org.springframework.social.connect
Interface ConnectionRepository


public interface ConnectionRepository

Data access interface for saving and restoring Connection objects from a persistent store. The view is relative to a specific local user--it's not possible using this interface to access or update connections for multiple local users. If you need that capability, see UsersConnectionRepository.

See Also:
UsersConnectionRepository

Method Summary
 void addConnection(Connection<?> connection)
          Add a new Connection for the current user to this repository.
 Connection<?> findConnection(ConnectionKey connectionKey)
          Find a single Connection for the current user by its key, which consists of the providerId + providerUserId.
 MultiValueMap<java.lang.String,Connection<?>> findConnections()
          Find a map of all Connections for the current user.
 MultiValueMap<java.lang.String,Connection<?>> findConnectionsForUsers(MultiValueMap<java.lang.String,java.lang.String> providerUserIds)
          Find the Connections the current user has to the given provider users.
<A> java.util.List<Connection<A>>
findConnectionsToApi(java.lang.Class<A> apiType)
          Find the Connections for the current user by the given apiType e.g.
 java.util.List<Connection<?>> findConnectionsToProvider(java.lang.String providerId)
          Find the Connections the current user has to the provider registered by the given id.
<A> Connection<A>
findConnectionToApiForUser(java.lang.Class<A> apiType, java.lang.String providerUserId)
          Find the Connection between the current user and the given provider user.
<A> Connection<A>
findPrimaryConnectionToApi(java.lang.Class<A> apiType)
          Find a single Connection for the current user by its apiType e.g.
 void removeConnection(ConnectionKey connectionKey)
          Remove a single Connection for the current user from this repository.
 void removeConnectionsToProvider(java.lang.String providerId)
          Remove all Connections between the current user and the provider from this repository.
 void updateConnection(Connection<?> connection)
          Update a Connection already added to this repository.
 

Method Detail

findConnections

MultiValueMap<java.lang.String,Connection<?>> findConnections()
Find a map of all Connections for the current user. The returned map contains an entry for each provider the user is connected to. The key for each entry is the providerId, and the value is the list of ServiceProviderConnections that exist between the user and that provider. For example, if the user is connected once to Facebook and twice to Twitter, the returned map would contain two entries with the following structure:
 { 
     "facebook" -> Connection("Keith Donald") ,
     "twitter"  -> Connection("kdonald"), Connection("springsource")
 }
 
The returned map is sorted by providerId and entry values are ordered by rank. Returns an empty map if the user has no connections.


findConnectionsToProvider

java.util.List<Connection<?>> findConnectionsToProvider(java.lang.String providerId)
Find the Connections the current user has to the provider registered by the given id. The returned list is ordered by connection rank. Returns an empty list if the user has no connections to the provider.

Parameters:
providerId - the provider id e.g. "facebook"

findConnectionsForUsers

MultiValueMap<java.lang.String,Connection<?>> findConnectionsForUsers(MultiValueMap<java.lang.String,java.lang.String> providerUserIds)
Find the Connections the current user has to the given provider users. The providerUsers parameter accepts a map containing an entry for each provider the caller is interested in. The key for each entry is the providerId e.g. "facebook", and the value is a list of provider user ids to fetch connections to e.g. ("126500", "34521", "127243"). The returned map has the same structure and order, except the provider userId values have been replaced by Connection instances. If no connection exists between the current user and a given provider user, a null value is returned for that position.

Parameters:
providerUserIds - the provider users map
Returns:
the provider user connection map

findConnection

Connection<?> findConnection(ConnectionKey connectionKey)
Find a single Connection for the current user by its key, which consists of the providerId + providerUserId.

Parameters:
connectionKey - the service provider connection key
Returns:
the service provider connection
Throws:
NoSuchConnectionException - if no such connection exists for the current user

findPrimaryConnectionToApi

<A> Connection<A> findPrimaryConnectionToApi(java.lang.Class<A> apiType)
Find a single Connection for the current user by its apiType e.g. FacebookApi.class. If the user has multiple connections to the provider associated with the given apiType, this method returns the one with the top rank (or priority). Useful for direct use by application code to obtain a parameterized Connection instance.

Type Parameters:
A - the service api parameterized type
Parameters:
apiType - the service api type e.g. FacebookApi.class or TwitterApi.class
Returns:
the connection

findConnectionToApiForUser

<A> Connection<A> findConnectionToApiForUser(java.lang.Class<A> apiType,
                                             java.lang.String providerUserId)
Find the Connection between the current user and the given provider user. Returns the equivalent of findConnection(ConnectionKey), but uses the apiType as the provider key instead of the providerId. Useful for direct use by application code to obtain a parameterized Connection instance.

Type Parameters:
A - the api parameterized type
Parameters:
apiType - the service api type e.g. FacebookApi.class or TwitterApi.class
providerUserId - the provider user e.g. "126500".
Returns:
the connection

findConnectionsToApi

<A> java.util.List<Connection<A>> findConnectionsToApi(java.lang.Class<A> apiType)
Find the Connections for the current user by the given apiType e.g. FacebookApi.class. Returns the equivalent of findConnectionsToProvider(String), but uses the apiType as the provider key instead of the providerId. Useful for direct use by application code to obtain parameterized Connection instances e.g. List<Connection<FacebookApi>>.

Type Parameters:
A - the api parameterized type
Parameters:
apiType - the service api type e.g. FacebookApi.class or TwitterApi.class
Returns:
the connections

addConnection

void addConnection(Connection<?> connection)
Add a new Connection for the current user to this repository. After the connection is added, it can be retrieved later using one of the finders defined by this interface.

Parameters:
connection - connection
Throws:
DuplicateConnectionException - if the user already has this connection

updateConnection

void updateConnection(Connection<?> connection)
Update a Connection already added to this repository. Merges the field values of the given connection object with the values stored in the repository.

Parameters:
connection - the connection

removeConnectionsToProvider

void removeConnectionsToProvider(java.lang.String providerId)
Remove all Connections between the current user and the provider from this repository. Does nothing if no provider connections exist.

Parameters:
providerId - the provider id e.g. "facebook"

removeConnection

void removeConnection(ConnectionKey connectionKey)
Remove a single Connection for the current user from this repository. Does nothing if no such connection exists.

Parameters:
connectionKey - the connection key