FP-SpecifyDriver

From Filtered Push Wiki
Jump to: navigation, search

Class Diagrams

Specifyweb-specify-diagram.jpg

AddServlet

 

AddServlet

1. User login information from OAuth process is validated.

2. If there is a non-empty value for both parameters "object" and "type," call save(type, object, userId), where type is a String name of a DwC type, and object is a json representation of a key-value pair Map<String, String> containing DwC terms and corresponding values.

3. Driver.login(userId, collId)

4. Driver.save(type, object)

5. Return the String value of the integer id of the object added.

Driver

login: set "context." A Specify user is associated with an institution/division/discipline/collection, and some user preferences. Retrieve this data from the database.

save:

1. Translate type parameter to Specify table name

2. Translate a map of key-value pairs to a tree structure of Maps that mimics the object graph for a persisted item of the given type, by iterating over the key-value pairs:

a) Given the type and field name, retrieve an hql path to find the related column. The hql join path is augmented with some special non-pojo properties for finding ancestors of taxon/geography records (e.g. taxon.family). No n-to-many relationships are allowed. (The hql paths are currently hard-coded in SpecifyDataPolicy)

b) traverse the hql path to obtain the value as a String (if it exists).

c) query Hibernate's metadata to find the type for the field value (may be an entity or a primitive)

d) if the field value is an entity, create a sub-Map for it; otherwise, parse the String value into a Java object of the proper type (currently the formatter is created in the constuctor for SpecifyDriver)

3. Create an intermediary object for communication with Hibernate. The ValidatingObjectLoader implements SessionAssociate, which means it will be called by Hibernate when Hibernate is asked to merge an object. Hibernate will pass the ValidatingObjectLoader a QueryClient object, which provides limited access to the Hibernate session object. Some access is needed so that persisted objects can be used as business rules are being applied.

4. SpecifyHibernate.merge(ValidatingObjectLoader)


SpecifyHibernate

1. Create a QueryClient to pass to the SessionAssociate client.

2. Call SessionAssociate.toMerge(QueryClient) to obtain the entity to merge.

3. Merge the object

4. Call SessionAssociate.postMerge(object)


ValidatingObjectLoader

1. Convert the Map tree into a Java-Hibernate entity object by loading objects by class and id, or in a few special cases, by name (definition items and parents of taxon/geography objects).

2. Call the BusinessRules object to set defaults on the entity.

3. Call the BusinessRules object to validate the entity.

4. Pass the entity to Hibernate to merge.


FindServlet

 

FindServlet

1. User login information from OAuth process is validated.

2. If there is a non-empty value for both parameters "object" and "type," call find(type, object, userId, start, max), where type is a String name of a DwC type, and object is a json representation of a key-value pair Map<String, String> containing DwC terms and corresponding values. Start and max are integers for paging.

3. Driver.login(userId, collId)

4. Driver.find(type, object, start, max)

5. Return a json representation of a list of integer ids of matching persisted objects.

Driver

login: set "context." A Specify user is associated with an institution/division/discipline/collection, and some user preferences. Retrieve this data from the database.

find:

1. Translate type parameter to Specify entity class

2. Translate a map of key-value pairs to a tree structure of Maps that mimics the object graph for a persisted item of the given type, by iterating over the key-value pairs:

a) Given the type and field name, retrieve an hql path to find the related column. The hql join path is augmented with some special non-pojo properties for finding ancestors of taxon/geography records (e.g. taxon.family). No n-to-many relationships are allowed. (The hql paths are currently hard-coded in SpecifyDataPolicy)

b) traverse the hql path to obtain the value as a String (if it exists).

c) query Hibernate's metadata to find the type for the field value (may be an entity or a primitive)

d) if the field value is an entity, create a sub-Map for it; otherwise, parse the String value into a Java object of the proper type (currently the formatter is created in the constuctor for SpecifyDriver)

3. Create an intermediary object for communication with Hibernate. The IdReader implements ObjectAssociate, which means it will be called by Hibernate when Hibernate is asked to retrieve an object. Hibernate will pass the ObjectAssociate a Specify DataModelObjBase object, which provides limited access to the attached object. Access to attached objects is limited to exceptions caused by access to lazy-loaded properties outside the scope of the session. The IdReader's only job is to record the identifiers for the matched objects.

4. Hibernate.match(IdReader)


Hibernate

1. Translate the tree of Map<String, String>s into restrictions on a criteria query for a given class.

2. Perform the query.

3. For each result, call ObjectAssociate.postFetch(object)


IdReader

1. When postFetch is called by SpecifyHibernate, record the id of the object

2. When getIds is called by SpecifyDriver, return the list of integer ids.


GetServlet

 

GetServlet

1. User login information from OAuth process is validated.

2. If there is a non-empty value for both parameters "id" and "type," call get(id, type), where type is a String name of a DwC type, and object is a json representation of a key-value pair Map<String, String> containing DwC terms and corresponding values. Start and max are integers for paging.

3. Driver.login(userId, collId)

4. Driver.find(type, object, start, max)

5. Return a json representation of a Map<String, String>s, where the map represents the persisted object flattened into DwC terms and their corresponding values.


Driver

login: set "context." A Specify user is associated with an institution/division/discipline/collection, and some user preferences. Retrieve this data from the database.

get: 1. Translate type parameter to Specify entity class

2. Read in the mappings for exporting Specify objects as DwC from the xml format that Specify uses.

3. Create an intermediary object for communication with Hibernate. The MapperWrapper implements ObjectAssociate, which means it will be called by Hibernate when Hibernate is asked to retrieve an object. Hibernate will pass the ObjectAssociate a Specify DataModelObjBase object, which provides limited access to the attached object. Access to attached objects is limited to exceptions caused by access to lazy-loaded properties outside the scope of the session. The MapperWrapper's only job is to flatten the object into a DwC key-value-pair representation, using the mappings read in in step 2.

4. Hibernate.fetch(entity class, id, MapperWrapper)


Hibernate

1. Translate the tree of Map<String, String>s into restrictions on a criteria query for a given class.

2. Perform the query.

3. For each result, call ObjectAssociate.postFetch(object)


MapperWrapper

1. When postFetch is called by SpecifyHibernate, go through each of the mappings and traverse the mapping's hql path to obtain the value, and format it as a String.

2. When getMap is called by SpecifyDriver, return a map of DwC terms to their corresponding values.