org.filteredpush.mapper.datapolicymapper
Class DataPolicyMapperImpl

java.lang.Object
  extended by org.filteredpush.mapper.datapolicymapper.DataPolicyMapperImpl
All Implemented Interfaces:
DataPolicyMapper, Mapper

public class DataPolicyMapperImpl
extends java.lang.Object
implements DataPolicyMapper

An implementation class of the mapper based on data policy. Author: Lei Dou $Id:$


Constructor Summary
DataPolicyMapperImpl()
           
 
Method Summary
 java.lang.String add(java.lang.String objType, java.util.Map<java.lang.String,java.lang.String> data)
          Add the record of specified type in the local data source.
 void delete(java.lang.String objType, java.lang.String identifier)
          Delete the record in specified type with the specified identifier from the local data source.
 java.util.List<java.util.Map<java.lang.String,java.lang.String>> get(java.lang.String objType, java.util.Map<java.lang.String,java.lang.String> data)
          Find the records of the specified type and with the specified value.
 java.util.List<java.util.Map<java.lang.String,java.lang.String>> getByIdentifiers(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.List<java.util.Map<java.lang.String,java.lang.String>> getFillin(java.lang.String objType, java.util.Map<java.lang.String,java.lang.String> data)
          Get the possible fill-in from the local data source for the input proposed change.
 java.util.List<org.filteredpush.data.definition.BasicFieldDefinition> getObjectDef(java.lang.String objType)
          Get the list of field definition for the specified record.
 void setAdapterWithClass(DataSourceAdapter adapter)
          Set the adapter class used by this mapper.
 void setAdapterWithName(java.lang.String adapterClassQN)
          Set the class name (including the package name) of the adapter used by this mapper.
 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.String> data)
          Update the record in specified type with the specified type and value in the local data source.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataPolicyMapperImpl

public DataPolicyMapperImpl()
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 Mapper
Parameters:
context -

setAdapterWithClass

public void setAdapterWithClass(DataSourceAdapter adapter)
                         throws UnsupportedAdapter
Set the adapter class used by this mapper.

Specified by:
setAdapterWithClass in interface Mapper
Parameters:
adapter - Adapter class.
Throws:
UnsupportedAdapter

setAdapterWithName

public void setAdapterWithName(java.lang.String adapterClassQN)
                        throws AdapterNotFound,
                               UnsupportedAdapter
Set the class name (including the package name) of the adapter used by this mapper.

Specified by:
setAdapterWithName in interface Mapper
Parameters:
adapterClassQN - Adapter class name.
Throws:
AdapterNotFound
UnsupportedAdapter

getByIdentifiers

public java.util.List<java.util.Map<java.lang.String,java.lang.String>> getByIdentifiers(java.lang.String objType,
                                                                                         java.util.Map<java.lang.String,java.lang.String> identifiers)
                                                                                  throws UnAuthenticated,
                                                                                         InvalidParameter,
                                                                                         InternalException,
                                                                                         OAuthRedirectException,
                                                                                         ConverterException,
                                                                                         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:
getByIdentifiers in interface DataPolicyMapper
Parameters:
objType - The type of the target record.
identifiers - The list of identifiers identifying the target record.
Returns:
The list 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.
ConverterException - If the data conversion fails.

get

public java.util.List<java.util.Map<java.lang.String,java.lang.String>> get(java.lang.String objType,
                                                                            java.util.Map<java.lang.String,java.lang.String> data)
                                                                     throws UnAuthenticated,
                                                                            InvalidParameter,
                                                                            InternalException,
                                                                            OAuthRedirectException,
                                                                            ConverterException,
                                                                            LocalDataSourceAccessException
Find the records of the specified type and with the specified value. In the current annotation processor implementation, we don't have any use case to invoke this method. We leave it here for future possible use.

Specified by:
get in interface DataPolicyMapper
Parameters:
objType - The type of the target record.
data - The value to be matched.
Returns:
The list of 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.
ConverterException - If the data conversion fails.

getFillin

public java.util.List<java.util.Map<java.lang.String,java.lang.String>> getFillin(java.lang.String objType,
                                                                                  java.util.Map<java.lang.String,java.lang.String> data)
                                                                           throws UnAuthenticated,
                                                                                  InvalidParameter,
                                                                                  InternalException,
                                                                                  OAuthRedirectException,
                                                                                  ConverterException,
                                                                                  LocalDataSourceAccessException
Get the possible fill-in from the local data source for the input proposed change. The method navigates the record tree of the specified record according to the data policy. If any record is found to match the input kvp (only need to match the value of the fields of this record), and the parent of this record doesn't match if there's no parent record, then the information of this record and all its nested records would be used for fill-in. Find all such records, make a composition and finally return the list of map while each map represents one fill-in choices for the absent fields in the proposed change.

Specified by:
getFillin in interface DataPolicyMapper
Parameters:
objType - The type of the target record.
data - The proposed change.
Returns:
The list of fill-in candidate.
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.
ConverterException - If the data conversion fails.

add

public java.lang.String add(java.lang.String objType,
                            java.util.Map<java.lang.String,java.lang.String> data)
                     throws UnAuthenticated,
                            InvalidParameter,
                            MissingInformationException,
                            UniqueIdentificationException,
                            InternalException,
                            OAuthRedirectException,
                            ConverterException,
                            LocalDataSourceAccessException,
                            ObjectExistException
Add the record of specified type in the local data source. The new object will be created if it doesn't exist.

Specified by:
add in interface DataPolicyMapper
Parameters:
objType - The type of the target record.
data - The value of the target record to be created.
Returns:
The primary key of the 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.
ConverterException - If the data conversion fails.
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.
ObjectExistException - If the record of the specified type with the specified value already exists in the local data source.

update

public void update(java.lang.String objType,
                   java.util.Map<java.lang.String,java.lang.String> data)
            throws UnAuthenticated,
                   InvalidParameter,
                   MissingInformationException,
                   UniqueIdentificationException,
                   InternalException,
                   OAuthRedirectException,
                   ConverterException,
                   LocalDataSourceAccessException,
                   ObjectExistException
Update the record in specified type with the specified type and value in the local data source.

Specified by:
update in interface DataPolicyMapper
Parameters:
objType - The type of the target record.
data - The value of the target record to be updated.
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.
ConverterException - If the data conversion fails.
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.
ObjectExistException - If the record of the specified type with the specified value already exists in the

delete

public void delete(java.lang.String objType,
                   java.lang.String identifier)
            throws UnAuthenticated,
                   InvalidParameter,
                   InternalException,
                   OAuthRedirectException,
                   ConverterException,
                   LocalDataSourceAccessException
Delete the record in specified type with the specified identifier from the local data source.

Specified by:
delete in interface DataPolicyMapper
Parameters:
objType - The type of the target record.
identifier - The primary key of the target 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.
ConverterException - If the data conversion fails.

getObjectDef

public java.util.List<org.filteredpush.data.definition.BasicFieldDefinition> getObjectDef(java.lang.String objType)
Get the list of field definition for the specified record.

When the object has cross reference to another object, the mapper will go to the referenced object definition and grab the field definition. This process could be recursive.

The major usage of this method is to generate the table in the webUI to present the existing local dataset and the "new" data. It would also be useful in other cases to help interpret and validate the data.

Specified by:
getObjectDef in interface DataPolicyMapper
Parameters:
objType - The type of the target record.
Returns:
The definition of the record.