gov.nih.nci.caarray.services.external.v1_0.impl
Class BaseV1_0ExternalService

java.lang.Object
  extended by gov.nih.nci.caarray.services.external.AbstractExternalService
      extended by gov.nih.nci.caarray.services.external.v1_0.impl.BaseV1_0ExternalService

public class BaseV1_0ExternalService
extends gov.nih.nci.caarray.services.external.AbstractExternalService

Base service for v1_0 external services.

Author:
dkokotov

Nested Class Summary
protected static interface BaseV1_0ExternalService.EntityHandler<T extends AbstractCaArrayEntity>
          An external entity handler encapsulates the logic to perform generic operations for an external entity type.
protected static class BaseV1_0ExternalService.EntityHandlerRegistry
          Class to hold a registry of entity handlers, which can be looked up by class of external entity.
 
Field Summary
protected static java.util.Map<BiomaterialType,java.lang.Class<? extends gov.nih.nci.caarray.domain.sample.AbstractBioMaterial>> BIOMATERIAL_TYPE_TO_CLASS_MAP
          Map of BiomaterialType to the corresponding AbstractBiomaterial subclass in the internal model.
 
Constructor Summary
BaseV1_0ExternalService()
          Constructor.
 
Method Summary
protected  java.lang.Object getByExternalId(java.lang.String externalId)
          Retrieve the entity in the internal domain model identified by the given external id.
protected
<T> T
getByReference(CaArrayEntityReference reference, java.lang.Class<T> type)
          Retrieve the entity for given reference expected to have given type.
protected  BaseV1_0ExternalService.EntityHandlerRegistry getEntityHandlerRegistry()
           
protected  java.lang.String getMapperVersionKey()
          
protected
<T> T
getRequiredByExternalId(java.lang.String externalId, java.lang.Class<T> type)
          Retrieve the entity with given external id expected to exist in the persistent store and have given type.
protected
<T> java.util.List<T>
mapRequiredReferencesToEntities(java.util.Collection<CaArrayEntityReference> refs, java.lang.Class<T> type)
          Convert the given list of references to the underlying internal entities pointed to by those references.
protected
<T> java.util.Collection<T>
mapRequiredReferencesToEntities(java.util.Collection<CaArrayEntityReference> refs, java.util.Collection<T> entities, java.lang.Class<T> type)
          Convert the given list of references to the underlying internal entities pointed to by those references.
 void setFileTypeRegistry(gov.nih.nci.caarray.domain.file.FileTypeRegistry fileTypeRegistry)
           
 void setMapperVersionKey(java.lang.String mapperVersionKey)
          Set a new mapper version key.
protected
<T> com.fiveamsolutions.nci.commons.data.search.PageSortParams<T>
toInternalParams(LimitOffset params, com.fiveamsolutions.nci.commons.data.search.SortCriterion<T> sortCriterion, boolean desc)
          convert given external paging params instance into internal paging params.
protected
<T> com.fiveamsolutions.nci.commons.data.search.PageSortParams<T>
toInternalParams(LimitOffset params, java.lang.String sortField, boolean desc)
          convert given external paging params instance into internal paging params.
protected
<T> com.fiveamsolutions.nci.commons.data.search.PageSortParams<T>
toInternalParams(LimitOffset params, java.lang.String sortField, boolean desc, java.lang.Class<T> targetClass)
          convert given external paging params instance into internal ones.
 
Methods inherited from class gov.nih.nci.caarray.services.external.AbstractExternalService
applySecurityPolicies, applySecurityPolicies, getClassFromExternalId, getDaoFactory, getHibernateMatchMode, getIdFromExternalId, getMapper, makeExternalId, makeExternalId, mapCollection, mapCollection, mapEntity, setDaoFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BIOMATERIAL_TYPE_TO_CLASS_MAP

protected static final java.util.Map<BiomaterialType,java.lang.Class<? extends gov.nih.nci.caarray.domain.sample.AbstractBioMaterial>> BIOMATERIAL_TYPE_TO_CLASS_MAP
Map of BiomaterialType to the corresponding AbstractBiomaterial subclass in the internal model.

Constructor Detail

BaseV1_0ExternalService

public BaseV1_0ExternalService()
Constructor.

Method Detail

setFileTypeRegistry

@Inject
public void setFileTypeRegistry(gov.nih.nci.caarray.domain.file.FileTypeRegistry fileTypeRegistry)
Parameters:
fileTypeRegistry - the file type registry to use

toInternalParams

protected <T> com.fiveamsolutions.nci.commons.data.search.PageSortParams<T> toInternalParams(LimitOffset params,
                                                                                             com.fiveamsolutions.nci.commons.data.search.SortCriterion<T> sortCriterion,
                                                                                             boolean desc)
convert given external paging params instance into internal paging params.

Type Parameters:
T - type being iterated over.
Parameters:
params - the external params
sortCriterion - the sort criterion to use
desc - whether the sort should be in descending order
Returns:
the internal params

toInternalParams

protected <T> com.fiveamsolutions.nci.commons.data.search.PageSortParams<T> toInternalParams(LimitOffset params,
                                                                                             java.lang.String sortField,
                                                                                             boolean desc)
convert given external paging params instance into internal paging params.

Type Parameters:
T - type being iterated over.
Parameters:
params - the external params
sortField - the field to sort on
desc - whether the sort should be in descending order
Returns:
the internal params

toInternalParams

protected <T> com.fiveamsolutions.nci.commons.data.search.PageSortParams<T> toInternalParams(LimitOffset params,
                                                                                             java.lang.String sortField,
                                                                                             boolean desc,
                                                                                             java.lang.Class<T> targetClass)
convert given external paging params instance into internal ones. Use this version to explicitly specify the class of the target entity, when it cannot be deduced by the compiler.

Type Parameters:
T - type being iterated over.
Parameters:
params - the external params
sortField - the field to sort on
desc - whether the sort should be in descending order
targetClass - the class of the element entity of the list being sorted paged.
Returns:
the internal params

getMapperVersionKey

protected java.lang.String getMapperVersionKey()

Specified by:
getMapperVersionKey in class gov.nih.nci.caarray.services.external.AbstractExternalService

setMapperVersionKey

public void setMapperVersionKey(java.lang.String mapperVersionKey)
Set a new mapper version key. Used by test code.

Parameters:
mapperVersionKey - new key

getByExternalId

protected java.lang.Object getByExternalId(java.lang.String externalId)
Retrieve the entity in the internal domain model identified by the given external id. This is expected to be implemented by version-specific subclasses.

Parameters:
externalId - the external id
Returns:
the entity

getRequiredByExternalId

protected <T> T getRequiredByExternalId(java.lang.String externalId,
                                        java.lang.Class<T> type)
                             throws InvalidReferenceException
Retrieve the entity with given external id expected to exist in the persistent store and have given type.

Type Parameters:
T - the entity type
Parameters:
externalId - the the external id of entity to retrieve
type - the class for the entity type
Returns:
the entity
Throws:
InvalidReferenceException - if no entity exists with given external id or the entity is not of expected type.

getByReference

protected <T> T getByReference(CaArrayEntityReference reference,
                               java.lang.Class<T> type)
                    throws InvalidReferenceException
Retrieve the entity for given reference expected to have given type.

Type Parameters:
T - the entity type
Parameters:
reference - the reference to the entity to retrieve
type - the class for the entity type
Returns:
the entity, or null if the reference is null
Throws:
InvalidReferenceException - if no entity exists for given reference or the entity is not of the expected type.

mapRequiredReferencesToEntities

protected <T> java.util.Collection<T> mapRequiredReferencesToEntities(java.util.Collection<CaArrayEntityReference> refs,
                                                                      java.util.Collection<T> entities,
                                                                      java.lang.Class<T> type)
                                                           throws InvalidReferenceException
Convert the given list of references to the underlying internal entities pointed to by those references.

Type Parameters:
T - the expected entity type for each reference
Parameters:
refs - the list of references.
entities - the collection in which to store the referenced internal entities.
type - the class for the entity type
Returns:
the entities collection (same instance as passed in the entities parameter)
Throws:
InvalidReferenceException - if for any reference, no entity exists or is not of the expected type.

mapRequiredReferencesToEntities

protected <T> java.util.List<T> mapRequiredReferencesToEntities(java.util.Collection<CaArrayEntityReference> refs,
                                                                java.lang.Class<T> type)
                                                     throws InvalidReferenceException
Convert the given list of references to the underlying internal entities pointed to by those references.

Type Parameters:
T - the expected entity type for each reference
Parameters:
refs - the list of references.
type - the class for the entity type
Returns:
the list of referenced internal entities.
Throws:
InvalidReferenceException - if for any reference, no entity exists or is not of the expected type.

getEntityHandlerRegistry

protected BaseV1_0ExternalService.EntityHandlerRegistry getEntityHandlerRegistry()
Returns:
the entityHandlerRegistry