org.filteredpush.mapper.datapolicymapper
Class SpecifyAdapter

java.lang.Object
  extended by org.filteredpush.mapper.datapolicymapper.SpecifyAdapter
All Implemented Interfaces:
DataPolicyAdapter, DataSourceAdapter

public class SpecifyAdapter
extends java.lang.Object
implements DataPolicyAdapter

A adapter for a specify database instance. It talks to the specify through a group of HTTP protocols and authenticate the user through OAuth. Author: Lei Dou $Id:$


Constructor Summary
SpecifyAdapter()
           
 
Method Summary
 java.lang.String add(java.lang.String objType, java.util.Map<java.lang.String,java.lang.Object> obj)
          Insert a record into the data source with the specified type and value.
 void delete(java.lang.String objType, java.lang.String identifier)
          Delete a record in the data source with the specified type and primary key.
 java.util.List<java.lang.String> find(java.lang.String objType, java.util.Map<java.lang.String,java.lang.Object> obj)
          Find the record that is in the specified type and has the specified value and return their primary keys.
 java.util.List<java.lang.String> findByIdentifiers(java.lang.String objType, java.util.Map<java.lang.String,java.lang.String> identifiers)
          Find the record in the local data source with the specified type and identified by the specific identifiers.
 java.util.Map<java.lang.String,java.lang.String> get(java.lang.String objType, java.lang.String identifier)
          Return the object with the specified type and the primary key.
 DataPolicy getDataPolicy()
          Return the data policy used by this adapter.
 void setContext(java.util.Map<java.lang.String,java.lang.String> context)
          Set the context, e.g.
 void update(java.lang.String objType, java.util.Map<java.lang.String,java.lang.Object> obj)
          Update a record in the data source with the specified type and value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpecifyAdapter

public SpecifyAdapter()
Method Detail

setContext

public void setContext(java.util.Map<java.lang.String,java.lang.String> context)
Set the context, e.g. the redirect page when the oAuth is used by the driver for authentication.

Specified by:
setContext in interface DataSourceAdapter
Parameters:
context -

getDataPolicy

public DataPolicy getDataPolicy()
Return the data policy used by this adapter.

Specified by:
getDataPolicy in interface DataPolicyAdapter
Returns:
The data policy used by this adapter.

findByIdentifiers

public java.util.List<java.lang.String> findByIdentifiers(java.lang.String objType,
                                                          java.util.Map<java.lang.String,java.lang.String> identifiers)
                                                   throws UnAuthenticated,
                                                          InvalidParameter,
                                                          InternalException,
                                                          OAuthRedirectException,
                                                          LocalDataSourceAccessException
Find the record in the local data source with the specified type and identified by the specific identifiers. The identifiers are not necessary the primary keys or any identifiers defined in the data policy for this type of record. For example, while mapping the "insert identification", to find all the identifications for the occurrence object, the identifiers used is actually the identifiers for the occurrence object, like collection code, catalog number etc. The reason why we design such method here is because only the local data source knows how to find the identifications for an occurrence object with the specified identifiers.

Specified by:
findByIdentifiers in interface DataPolicyAdapter
Parameters:
objType - The type of the target record.
identifiers - The list of identifiers identifying the target record.
Returns:
The list of primary key of the found record.
Throws:
UnAuthenticated - If the adapter can't be authenticated to access the local data source.
InvalidParameter - If the input value is not valid.
InternalException - Indicates internal error happening in the local data source to answer this query.
OAuthRedirectException - If redirection to the OAuth authentication page is needed.
LocalDataSourceAccessException - If the local data source can't be accessed for some reason.

find

public java.util.List<java.lang.String> find(java.lang.String objType,
                                             java.util.Map<java.lang.String,java.lang.Object> obj)
                                      throws UnAuthenticated,
                                             InvalidParameter,
                                             InternalException,
                                             OAuthRedirectException,
                                             LocalDataSourceAccessException
Find the record that is in the specified type and has the specified value and return their primary keys.

Specified by:
find in interface DataPolicyAdapter
Parameters:
objType - The type of record to be find.
obj - The value that the target record should have.
Returns:
List of primary keys of the found records.
Throws:
UnAuthenticated - If the adapter can't be authenticated to access the local data source.
InvalidParameter - If the input value is not valid.
InternalException - Indicates internal error happening in the local data source to answer this query.
OAuthRedirectException - If redirection to the OAuth authentication page is needed.
LocalDataSourceAccessException - If the local data source can't be accessed for some reason.

get

public java.util.Map<java.lang.String,java.lang.String> get(java.lang.String objType,
                                                            java.lang.String identifier)
                                                     throws UnAuthenticated,
                                                            InvalidParameter,
                                                            InternalException,
                                                            OAuthRedirectException,
                                                            LocalDataSourceAccessException
Return the object with the specified type and the primary key.

Specified by:
get in interface DataPolicyAdapter
Parameters:
objType - The type of record to be find.
identifier - The primary key.
Returns:
The value in key-value pairs of the matched record.
Throws:
UnAuthenticated - If the adapter can't be authenticated to access the local data source.
InvalidParameter - If the input value is not valid.
InternalException - Indicates internal error happening in the local data source to answer this query.
OAuthRedirectException - If redirection to the OAuth authentication page is needed.
LocalDataSourceAccessException - If the local data source can't be accessed for some reason.

add

public java.lang.String add(java.lang.String objType,
                            java.util.Map<java.lang.String,java.lang.Object> obj)
                     throws UnAuthenticated,
                            InvalidParameter,
                            MissingInformationException,
                            UniqueIdentificationException,
                            InternalException,
                            OAuthRedirectException,
                            LocalDataSourceAccessException
Insert a record into the data source with the specified type and value.

Specified by:
add in interface DataPolicyAdapter
Parameters:
objType - The type of record to be inserted.
obj - The value of the object to be inserted.
Returns:
The primary key of the inserted object.
Throws:
UnAuthenticated - If the adapter can't be authenticated to access the local data source.
InvalidParameter - If the input value is not valid.
MissingInformationException - If the information provided to create the record is not enough. E.g. the information to create higher taxon is needed when a taxon is inserted and its higher taxon doesn't exist.
UniqueIdentificationException - If more than one records (could be the referenced record) are matched according to the input value while only one is expected. E.g. when insert an identification record, a gci_botanist (representing the identifier) record will be found and its id will be used to create the identification record. But if only the identifier's name is provided and more than one gci_botanist records are matched, then the system won't be able to know which record should be used. In this case, this exception will be thrown out.
InternalException - Indicates internal error happening in the local data source to answer this query.
OAuthRedirectException - If redirection to the OAuth authentication page is needed.
LocalDataSourceAccessException - If the local data source can't be accessed for some reason.

update

public void update(java.lang.String objType,
                   java.util.Map<java.lang.String,java.lang.Object> obj)
            throws UnAuthenticated,
                   InvalidParameter,
                   MissingInformationException,
                   UniqueIdentificationException,
                   InternalException,
                   OAuthRedirectException,
                   LocalDataSourceAccessException
Update a record in the data source with the specified type and value. It's required to provide the primary key in the input value.

Specified by:
update in interface DataPolicyAdapter
Parameters:
objType - The type of record to be updated.
obj - The value that the object to be updated to. The primary key of the object must be contained so that the to be updated object could be identified.
Throws:
UnAuthenticated - If the adapter can't be authenticated to access the local data source.
InvalidParameter - If the input value is not valid.
MissingInformationException - If the information provided to create the record is not enough. E.g. the information to create higher taxon is needed when a taxon is updated and its higher taxon doesn't exist.
UniqueIdentificationException - If more than one records (could be the referenced record) are matched according to the input value while only one is expected. E.g. when insert an identification record, a gci_botanist (representing the identifier) record will be found and its id will be used to create the identification record. But if only the identifier's name is provided and more than one gci_botanist records are matched, then the system won't be able to know which record should be used. In this case, this exception will be thrown out.
InternalException - Indicates internal error happening in the local data source to answer this query.
OAuthRedirectException - If redirection to the OAuth authentication page is needed.
LocalDataSourceAccessException - If the local data source can't be accessed for some reason.

delete

public void delete(java.lang.String objType,
                   java.lang.String identifier)
            throws UnAuthenticated,
                   InvalidParameter,
                   InternalException,
                   OAuthRedirectException,
                   LocalDataSourceAccessException
Delete a record in the data source with the specified type and primary key.

Specified by:
delete in interface DataPolicyAdapter
Parameters:
objType - The type of record to be deleted.
identifier - The primary key of the object to be deleted.
Throws:
UnAuthenticated - If the adapter can't be authenticated to access the local data source.
InvalidParameter - If the input value is not valid.
InternalException - Indicates internal error happening in the local data source to answer this query.
OAuthRedirectException - If redirection to the OAuth authentication page is needed.
LocalDataSourceAccessException - If the local data source can't be accessed for some reason.