DLESE Tools
v1.6.0

org.dlese.dpc.repository
Class RecordDataService

java.lang.Object
  extended by org.dlese.dpc.repository.RecordDataService

public class RecordDataService
extends Object

Provides data related to a given collection-level record such as its associated IDs and annotations. This class is used by class ItemFileIndexingWriter to insert data into the index for each record at index creation time.

Version:
$Id: RecordDataService.java,v 1.58 2010/07/14 00:18:49 jweather Exp $
Author:
John Weatherley
See Also:
RecordData, Query

Field Summary
static int QUERY_BOTH
          Use to query within both other and the same collection
static int QUERY_OTHER
          Use to query within a other collection
static int QUERY_SAME
          Use to query within a the same collection
 
Constructor Summary
RecordDataService(String dbUrl, MetadataVocab vocab, String collBaseDir, String annotationPathwaysSchemaUrl)
          Constructor for a RecordDataService that has access to an MmdRec Query service.
 
Method Summary
 void closeIdMapper()
          Closes the local Query Object, releasing it's resources.
 void closeIdMapperQueryObject(Query queryObject)
          Closes an IDMapper Query object, releasing its resources.
 String getAccessionStatus(MmdRec[] mmdRecs)
          Gets the accession status of the given records or, if multiple resources get all statuses separated by spaces.
 ArrayList getAnnoFormatsFromResultDocs(ResultDocList annoResultDocs)
          Gets the annotation formats from the anno result docs.
 ArrayList getAnnoPathwaysFromResultDocs(ResultDocList annoResultDocs)
          Gets all annotation pathways in the given set of DleseAnnoDocReaders, or null if none exist.
 ArrayList getAnnoStatusFromResultDocs(ResultDocList annoResultDocs)
          Gets the annoStatusFromReaders attribute of the RecordDataService object
 ArrayList getAnnoTypesFromResultDocs(ResultDocList annoResultDocs)
          Gets all annotation types in the given set of DleseAnnoDocReaders, or null if none exist.
 String[] getAssociatedIDs(String id, MmdRec[] associatedMmdRecs)
          Gets the IDs for records that catalog the same resource, not including the ID that is given.
 MmdRec[] getAssociatedMMDRecs(int queryType, String IDs, String collectionKeys)
          Gets the associated MMD records for the given IDs, records that catalog the same resource, or null if none exist, using the local Query Object.
 MmdRec[] getAssociatedMMDRecs(int queryType, String IDs, String collectionKeys, Query qo)
          Gets the associated MMD records for the given IDs, records that catalog the same resource, or null if none exist, using the given Query Object.
 String getCollectCollectionID()
          Returns the value of collectCollectionID.
 ArrayList getCollectionKeysFromResultDocs(ResultDocList collectionResults)
          Gets all collection keys encoded by Vocab Mgr, for example {06, 08}, for the given records.
 ArrayList getCompletedAnnoCollectionKeysFromResultDocs(ResultDocList annoResultDocs)
          Gets a list of keys, for example {06, 04}, for each of the annotation collections that have at least one status completed record.
protected static String getDateStamp()
          Return a string for the current time and date, sutiable for display in log files and output to standout:
 ResultDoc getDisplayableItemResultDoc(String itemId)
          Gets the ResultDoc for the given item level metata record id but only if it should be displayed in discovery.
 ResultDocList getDisplayableItemResultDocs(String[] itemIds)
          Gets the item result docs for each of the ids listed regardless, returning only those that should be displayed in discovery.
 ResultDocList getDleseAnnoResultDocs(String[] ids)
          Gets the DLESEAnno docs that annotate the given ids, or null if none.
 File getFileForId(MmdRec rec)
          Gets the fileForId attribute of the RecordDataService object
 String getFilePathForId(MmdRec rec)
          Gets the filePathForId attribute of the RecordDataService object
 String[] getIdentifiedErrors(MmdRec[] mmdRecs)
          Gets all errors identified by the ID mapper service for the given records, or null if none exist.
 Query getIdMapperQueryObject()
          Gets a IDMapper Query Object to use in getMmdRec(String, String, Query) or getAssociatedMMDRecs(int, String, String, Query).
 SimpleLuceneIndex getIndex()
          Gets the index used by this RecordData service to retrieve data.
 ResultDoc getItemResultDoc(String itemId)
          Gets the ResultDoc for the given item-level metata record id regardless of the records status, or null if none exists.
 ResultDocList getItemResultDocs(String[] itemIds)
          Gets the item result docs for each of the ids listed regardless of their status.
 MmdRec getMmdRec(String id, String collectionKey)
          Gets the ID mapper record for the given ID using the local Query Object.
 MmdRec getMmdRec(String id, String collectionKey, Query qo)
          Gets the ID mapper record for the given ID using the given Query Object.
 MetadataVocab getVocab()
          Gets the vocab attribute of the RecordDataService object
static boolean hasDRCAnnotation(ResultDocList annoResultDocs)
          Return true if there is an annotation present that is part of the DRC.
static boolean hasDRCItem(ResultDocList itemResultDocs)
          Return true if there is an item present that is part of the DRC as determined by the items collection.
 void init(RepositoryManager rm)
          Initialize the RecordDataService.
 void initIdMapper()
          Initializes the local Query Object.
 boolean isIdMapperDisabled()
          Gets the idMapperDisabled attribute of the RecordDataService object
protected static void prtln(String s)
          Output a line of text to standard out, with datestamp, if debug is set to true.
protected static void prtlnErr(String s)
          Output a line of text to error out, with datestamp.
 void setCollectCollectionID(String collectCollectionID)
          Sets the value of collectCollectionID.
static void setDebug(boolean db)
          Sets the debug attribute of the object
 void updateVocab(MetadataVocab newVocab)
          Updates the MetadataVocab being used by this service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QUERY_OTHER

public static int QUERY_OTHER
Use to query within a other collection


QUERY_SAME

public static int QUERY_SAME
Use to query within a the same collection


QUERY_BOTH

public static int QUERY_BOTH
Use to query within both other and the same collection

Constructor Detail

RecordDataService

public RecordDataService(String dbUrl,
                         MetadataVocab vocab,
                         String collBaseDir,
                         String annotationPathwaysSchemaUrl)
Constructor for a RecordDataService that has access to an MmdRec Query service.

Parameters:
dbUrl - URL of the database, or use the String "useRandomIds" to generate random associated IDs, or null if not using the Query API.
vocab - The MetadataVocab to use, or null if not needed.
collBaseDir - Description of the Parameter
annotationPathwaysSchemaUrl - URL to the annotation pathways schema
See Also:
Query
Method Detail

updateVocab

public void updateVocab(MetadataVocab newVocab)
Updates the MetadataVocab being used by this service.

Parameters:
newVocab - The new MetadataVocab that will be used.

init

public void init(RepositoryManager rm)
Initialize the RecordDataService.

Parameters:
rm - The RepositoryManager

getIndex

public SimpleLuceneIndex getIndex()
Gets the index used by this RecordData service to retrieve data.

Returns:
The index.

getCollectCollectionID

public String getCollectCollectionID()
Returns the value of collectCollectionID.

Returns:
The collectCollectionID value

setCollectCollectionID

public void setCollectCollectionID(String collectCollectionID)
Sets the value of collectCollectionID.

Parameters:
collectCollectionID - The value to assign collectCollectionID.

getIdMapperQueryObject

public Query getIdMapperQueryObject()
Gets a IDMapper Query Object to use in getMmdRec(String, String, Query) or getAssociatedMMDRecs(int, String, String, Query). The Query may be used multiple times. After use, the caller must be sure to close the Query using the closeIdMapperQueryObject(Query).

Returns:
The a Query Object, or null if unable to obtain

closeIdMapperQueryObject

public void closeIdMapperQueryObject(Query queryObject)
Closes an IDMapper Query object, releasing its resources.

Parameters:
queryObject - The Query Object to close

initIdMapper

public void initIdMapper()
Initializes the local Query Object. This must be called prior to use over a collection of files.


closeIdMapper

public void closeIdMapper()
Closes the local Query Object, releasing it's resources. This should be called after finished using the idmapper for a collection of files.


isIdMapperDisabled

public boolean isIdMapperDisabled()
Gets the idMapperDisabled attribute of the RecordDataService object

Returns:
The idMapperDisabled [true | false]

getFilePathForId

public String getFilePathForId(MmdRec rec)
Gets the filePathForId attribute of the RecordDataService object

Parameters:
rec - Description of the Parameter
Returns:
The filePathForId value

getFileForId

public File getFileForId(MmdRec rec)
Gets the fileForId attribute of the RecordDataService object

Parameters:
rec - Description of the Parameter
Returns:
The fileForId value

getAssociatedIDs

public String[] getAssociatedIDs(String id,
                                 MmdRec[] associatedMmdRecs)
Gets the IDs for records that catalog the same resource, not including the ID that is given.

Parameters:
id - The id to the item-level record - will be ommitted from the list of associatedIDs
associatedMmdRecs - An array of MmdRecs
Returns:
The associatedIDs value

getIdentifiedErrors

public String[] getIdentifiedErrors(MmdRec[] mmdRecs)
Gets all errors identified by the ID mapper service for the given records, or null if none exist.

Parameters:
mmdRecs - An array of MmdRecords
Returns:
A String array of IDMapper error codes

getAssociatedMMDRecs

public MmdRec[] getAssociatedMMDRecs(int queryType,
                                     String IDs,
                                     String collectionKeys,
                                     Query qo)
Gets the associated MMD records for the given IDs, records that catalog the same resource, or null if none exist, using the given Query Object. Splits the IDs and collectionKeys by spaces and uses the first one.

Parameters:
IDs - An ID(s) to an item-level resource, separated by spaces - the first is used
collectionKeys - The collection keys for the collection of files, for example "dcc" or "comet", separated by spaces - the first is used
queryType - Specify to look in other or the same collection
qo - The IDMapper Query Object to use
Returns:
The associated MmdRecs

getAssociatedMMDRecs

public MmdRec[] getAssociatedMMDRecs(int queryType,
                                     String IDs,
                                     String collectionKeys)
Gets the associated MMD records for the given IDs, records that catalog the same resource, or null if none exist, using the local Query Object. Splits the IDs and collectionKeys by spaces and uses the first one.

Parameters:
IDs - An ID(s) to an item-level resource, separated by spaces.
collectionKeys - The collection keys for the collection of files, for example "dcc" or "comet", separated by spaces.
queryType - Specify to look in other or the same collection
Returns:
The associated MmdRecs

getMmdRec

public MmdRec getMmdRec(String id,
                        String collectionKey,
                        Query qo)
Gets the ID mapper record for the given ID using the given Query Object.

Parameters:
id - The ID of a given record, for example DLESE-000-000-000-001.
collectionKey - The collection in which the given record resides, for example dcc.
qo - The Query Object to use
Returns:
The ID mapper mmdRecord.

getMmdRec

public MmdRec getMmdRec(String id,
                        String collectionKey)
Gets the ID mapper record for the given ID using the local Query Object.

Parameters:
id - The ID of a given record, for example DLESE-000-000-000-001.
collectionKey - The collection in which the given record resides, for example dcc.
Returns:
The ID mapper mmdRecord.

getAccessionStatus

public String getAccessionStatus(MmdRec[] mmdRecs)
Gets the accession status of the given records or, if multiple resources get all statuses separated by spaces.

Parameters:
mmdRecs - The MmdRecords
Returns:
The status value

getDisplayableItemResultDoc

public ResultDoc getDisplayableItemResultDoc(String itemId)
Gets the ResultDoc for the given item level metata record id but only if it should be displayed in discovery. Returns null if none exists.

Parameters:
itemId - The ID to a given item-level record.
Returns:
The ResultDoc for that item or null.

getDisplayableItemResultDocs

public ResultDocList getDisplayableItemResultDocs(String[] itemIds)
Gets the item result docs for each of the ids listed regardless, returning only those that should be displayed in discovery.

Parameters:
itemIds - An array of IDs.
Returns:
The items that matched or null if none.

getItemResultDoc

public ResultDoc getItemResultDoc(String itemId)
Gets the ResultDoc for the given item-level metata record id regardless of the records status, or null if none exists.

Parameters:
itemId - The ID to a given item-level record.
Returns:
The ResultDoc for that item.

getItemResultDocs

public ResultDocList getItemResultDocs(String[] itemIds)
Gets the item result docs for each of the ids listed regardless of their status.

Parameters:
itemIds - An array of IDs.
Returns:
The items that matched or null if none.

getDleseAnnoResultDocs

public ResultDocList getDleseAnnoResultDocs(String[] ids)
Gets the DLESEAnno docs that annotate the given ids, or null if none.

Parameters:
ids - Ids for records in the repository.
Returns:
The matching DLESE anno records, or null if none.

getAnnoTypesFromResultDocs

public ArrayList getAnnoTypesFromResultDocs(ResultDocList annoResultDocs)
Gets all annotation types in the given set of DleseAnnoDocReaders, or null if none exist.

Parameters:
annoResultDocs - An array of ResultDocs
Returns:
The annoTypes value or null.

getAnnoStatusFromResultDocs

public ArrayList getAnnoStatusFromResultDocs(ResultDocList annoResultDocs)
Gets the annoStatusFromReaders attribute of the RecordDataService object

Parameters:
annoResultDocs - An array of ResultDocs
Returns:
The annoStatusFromReaders value

getAnnoFormatsFromResultDocs

public ArrayList getAnnoFormatsFromResultDocs(ResultDocList annoResultDocs)
Gets the annotation formats from the anno result docs.

Parameters:
annoResultDocs - An array of ResultDocs
Returns:
The anno formats

getCompletedAnnoCollectionKeysFromResultDocs

public ArrayList getCompletedAnnoCollectionKeysFromResultDocs(ResultDocList annoResultDocs)
Gets a list of keys, for example {06, 04}, for each of the annotation collections that have at least one status completed record.

Parameters:
annoResultDocs - An array of ResultDocs of annotation records
Returns:
A list of annotation collection keys, or null

getAnnoPathwaysFromResultDocs

public ArrayList getAnnoPathwaysFromResultDocs(ResultDocList annoResultDocs)
Gets all annotation pathways in the given set of DleseAnnoDocReaders, or null if none exist. Currently, this is not used!

Parameters:
annoResultDocs - An array of ResultDocs
Returns:
The annoPathways value or null.

hasDRCAnnotation

public static boolean hasDRCAnnotation(ResultDocList annoResultDocs)
Return true if there is an annotation present that is part of the DRC. The definition of DRC is obtains from the current pathways.xsd schema at the DPC.

Parameters:
annoResultDocs - Annotation records.
Returns:
True if one or more of the annotations is part of the DRC.

hasDRCItem

public static boolean hasDRCItem(ResultDocList itemResultDocs)
Return true if there is an item present that is part of the DRC as determined by the items collection.

Parameters:
itemResultDocs - Array of Item result docs.
Returns:
True if one or more of the items is part of the DRC.

getCollectionKeysFromResultDocs

public ArrayList getCollectionKeysFromResultDocs(ResultDocList collectionResults)
Gets all collection keys encoded by Vocab Mgr, for example {06, 08}, for the given records.

Parameters:
collectionResults - ResultDocs of records
Returns:
The collection keys or null.

getVocab

public MetadataVocab getVocab()
Gets the vocab attribute of the RecordDataService object

Returns:
The vocab value

getDateStamp

protected static final String getDateStamp()
Return a string for the current time and date, sutiable for display in log files and output to standout:

Returns:
The dateStamp value

prtlnErr

protected static final void prtlnErr(String s)
Output a line of text to error out, with datestamp.

Parameters:
s - The text that will be output to error out.

prtln

protected static final void prtln(String s)
Output a line of text to standard out, with datestamp, if debug is set to true.

Parameters:
s - The String that will be output.

setDebug

public static void setDebug(boolean db)
Sets the debug attribute of the object

Parameters:
db - The new debug value

DLESE Tools
v1.6.0