Class DSpaceObjectServiceImpl<T extends DSpaceObject>
- java.lang.Object
-
- org.dspace.content.DSpaceObjectServiceImpl<T>
-
- Type Parameters:
T- class type
- All Implemented Interfaces:
DSpaceObjectService<T>
- Direct Known Subclasses:
BitstreamServiceImpl,BundleServiceImpl,CollectionServiceImpl,CommunityServiceImpl,EPersonServiceImpl,GroupServiceImpl,ItemServiceImpl,SiteServiceImpl
public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> extends Object implements DSpaceObjectService<T>
Service implementation class for the DSpaceObject. All DSpaceObject service classes should extend this class since it implements some basic methods which all DSpaceObjects are required to have.- Author:
- kevinvandevelde at atmire.com
-
-
Field Summary
Fields Modifier and Type Field Description protected ChoiceAuthorityServicechoiceAuthorityServiceprotected HandleServicehandleServiceprotected MetadataAuthorityServicemetadataAuthorityServiceprotected MetadataFieldServicemetadataFieldServiceprotected MetadataValueServicemetadataValueServiceprotected RelationshipServicerelationshipService
-
Constructor Summary
Constructors Constructor Description DSpaceObjectServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAndShiftRightMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value, String authority, int confidence, int index)Add a single metadata field.voidaddMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value)Add a single metadata field.voidaddMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value, String authority, int confidence)Add a single metadata field.voidaddMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, List<String> values)Add metadata fields.voidaddMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, List<String> values, List<String> authorities, List<Integer> confidences)Add metadata fields.voidaddMetadata(Context context, T dso, MetadataField metadataField, String language, String value)voidaddMetadata(Context context, T dso, MetadataField metadataField, String language, String value, String authority, int confidence)Shortcut forDSpaceObjectService.addMetadata(Context, DSpaceObject, MetadataField, String, List, List, List)when a single value need to be addedvoidaddMetadata(Context context, T dso, MetadataField metadataField, String language, List<String> values)voidaddMetadata(Context context, T dso, MetadataField metadataField, String lang, List<String> values, List<String> authorities, List<Integer> confidences)Add metadata fields.voidclearMetadata(Context context, T dso, String schema, String element, String qualifier, String lang)Clear metadata values.DSpaceObjectgetAdminObject(Context context, T dso, int action)Return the dspace object where an ADMIN action right is sufficient to grant the initial authorize check.protected voidgetAuthoritiesAndConfidences(String fieldKey, Collection collection, List<String> values, List<String> authorities, List<Integer> confidences, int i)protected String[]getElements(String fieldName)Splits "schema.element.qualifier.language" into an array.protected String[]getElementsFilled(String fieldName)Splits "schema.element.qualifier.language" into an array.ArrayList<String>getIdentifiers(Context context, T dso)Tries to lookup all Identifiers of this DSpaceObject.protected String[]getMDValueByField(String field)protected String[]getMDValueByLegacyField(String field)StringgetMetadata(T dso, String value)Get the value of a metadata fieldList<MetadataValue>getMetadata(T dso, String mdString, String authority)List<MetadataValue>getMetadata(T dso, String schema, String element, String qualifier, String lang)Get metadata for the DSpace Object in a chosen schema.List<MetadataValue>getMetadata(T dso, String schema, String element, String qualifier, String lang, String authority)List<MetadataValue>getMetadataByMetadataString(T dso, String mdString)Retrieve metadata field values from a given metadata string of the form<schema prefix>.<element>[.<qualifier>|.*]StringgetMetadataFirstValue(T dso, String schema, String element, String qualifier, String language)Retrieve first metadata field valueprotected intgetMetadataValuePlace(Map<MetadataField,Integer> fieldToLastPlace, MetadataValue metadataValue)Retrieve the place of the metadata valueStringgetName(T dso)Get a proper name for the object.DSpaceObjectgetParentObject(Context context, T dso)Return the dspace object that "own" the current object in the hierarchy.StringgetTypeText(T dso)Provide the text name of the type of this DSpaceObject.protected booleanmatch(String schema, String element, String qualifier, String language, MetadataValue metadataValue)Utility method for pattern-matching metadata elements.voidmoveMetadata(Context context, T dso, String schema, String element, String qualifier, int from, int to)voidremoveMetadataValues(Context context, T dso, List<MetadataValue> values)voidreplaceMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value, String authority, int confidence, int index)voidsetMetadataModified(T dso)Trigger the modifiedMetadata variable in DSpaceObjectvoidsetMetadataSingleValue(Context context, T dso, String schema, String element, String qualifier, String language, String value)Set first metadata field valuevoidupdate(Context context, T dso)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.dspace.content.service.DSpaceObjectService
delete, find, getSupportsTypeConstant, updateLastModified
-
-
-
-
Field Detail
-
choiceAuthorityService
@Autowired(required=true) protected ChoiceAuthorityService choiceAuthorityService
-
handleService
@Autowired(required=true) protected HandleService handleService
-
metadataValueService
@Autowired(required=true) protected MetadataValueService metadataValueService
-
metadataFieldService
@Autowired(required=true) protected MetadataFieldService metadataFieldService
-
metadataAuthorityService
@Autowired(required=true) protected MetadataAuthorityService metadataAuthorityService
-
relationshipService
@Autowired(required=true) protected RelationshipService relationshipService
-
-
Method Detail
-
getName
public String getName(T dso)
Description copied from interface:DSpaceObjectServiceGet a proper name for the object. This may returnnull. Name should be suitable for display in a user interface.- Specified by:
getNamein interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
dso- DSpaceObject- Returns:
- Name for the object, or
nullif it doesn't have one
-
getIdentifiers
public ArrayList<String> getIdentifiers(Context context, T dso)
Description copied from interface:DSpaceObjectServiceTries to lookup all Identifiers of this DSpaceObject.- Specified by:
getIdentifiersin interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
context- DSpace contextdso- DSpaceObject- Returns:
- An array containing all found identifiers or an array with a length of 0.
-
getParentObject
public DSpaceObject getParentObject(Context context, T dso) throws SQLException
Description copied from interface:DSpaceObjectServiceReturn the dspace object that "own" the current object in the hierarchy. Note that this method has a meaning slightly different from the getAdminObject because it is independent of the action but it is in a way related to it. It defines the "first" dspace object OTHER then the current one, where allowed ADMIN actions imply allowed ADMIN actions on the object self.- Specified by:
getParentObjectin interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
context- DSpace contextdso- DSpaceObject- Returns:
- the dspace object that "own" the current object in the hierarchy
- Throws:
SQLException- if database error
-
getAdminObject
public DSpaceObject getAdminObject(Context context, T dso, int action) throws SQLException
Description copied from interface:DSpaceObjectServiceReturn the dspace object where an ADMIN action right is sufficient to grant the initial authorize check.Default behaviour is ADMIN right on the object grant right on all other action on the object itself. Subclass should override this method as needed.
- Specified by:
getAdminObjectin interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
context- DSpace contextdso- DSpaceObjectaction- ID of action being attempted, fromorg.dspace.core.Constants. The ADMIN action is not a valid parameter for this method, an IllegalArgumentException should be thrown- Returns:
- the dspace object, if any, where an ADMIN action is sufficient to grant the original action
- Throws:
SQLException- if database error
-
getTypeText
public String getTypeText(T dso)
Description copied from interface:DSpaceObjectServiceProvide the text name of the type of this DSpaceObject. It is most likely all uppercase.- Specified by:
getTypeTextin interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
dso- DSpaceObject- Returns:
- Object type as text
-
getMetadata
public List<MetadataValue> getMetadata(T dso, String schema, String element, String qualifier, String lang)
Description copied from interface:DSpaceObjectServiceGet metadata for the DSpace Object in a chosen schema. SeeMetadataSchemafor more information about schemas. Passing in anullvalue forqualifierorlangonly matches metadata fields where that qualifier or languages is actuallynull. Passing inDSpaceObject.ANYretrieves all metadata fields with any value for the qualifier or language, includingnullExamples:
Return values of the unqualified "title" field, in any language. Qualified title fields (e.g. "title.uniform") are NOT returned:
dspaceobject.getMetadataByMetadataString("dc", "title", null, DSpaceObject.ANY );Return all US English values of the "title" element, with any qualifier (including unqualified):
dspaceobject.getMetadataByMetadataString("dc, "title", DSpaceObject.ANY, "en_US" );The ordering of values of a particular element/qualifier/language combination is significant. When retrieving with wildcards, values of a particular element/qualifier/language combinations will be adjacent, but the overall ordering of the combinations is indeterminate.
- Specified by:
getMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
dso- DSpaceObjectschema- the schema for the metadata field. Must match thenameof an existing metadata schema.element- the element name.DSpaceObject.ANYmatches any element.nulldoesn't really make sense as all metadata must have an element.qualifier- the qualifier.nullmeans unqualified, andDSpaceObject.ANYmeans any qualifier (including unqualified.)lang- the ISO639 language code, optionally followed by an underscore and the ISO3166 country code.nullmeans only values with no language are returned, andDSpaceObject.ANYmeans values with any country code or no country code are returned.- Returns:
- metadata fields that match the parameters
-
getMetadataByMetadataString
public List<MetadataValue> getMetadataByMetadataString(T dso, String mdString)
Description copied from interface:DSpaceObjectServiceRetrieve metadata field values from a given metadata string of the form<schema prefix>.<element>[.<qualifier>|.*]- Specified by:
getMetadataByMetadataStringin interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
dso- DSpaceObjectmdString- The metadata string of the form<schema prefix>.<element>[.<qualifier>|.*]- Returns:
- metadata fields that match the parameters
-
getMetadata
public String getMetadata(T dso, String value)
Description copied from interface:DSpaceObjectServiceGet the value of a metadata field- Specified by:
getMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
dso- DSpaceObjectvalue- the name of the metadata field to get- Returns:
- the value of the metadata field (or null if the column is an SQL NULL)
-
getMetadata
public List<MetadataValue> getMetadata(T dso, String mdString, String authority)
- Specified by:
getMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>
-
getMetadata
public List<MetadataValue> getMetadata(T dso, String schema, String element, String qualifier, String lang, String authority)
- Specified by:
getMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>
-
addMetadata
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, List<String> values) throws SQLException
Description copied from interface:DSpaceObjectServiceAdd metadata fields. These are appended to existing values. UseclearMetadatato remove values. The ordering of values passed in is maintained.If metadata authority control is available, try to get authority values. The authority confidence depends on whether authority is required or not.
- Specified by:
addMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
context- DSpace contextdso- DSpaceObjectschema- the schema for the metadata field. Must match thenameof an existing metadata schema.element- the metadata element namequalifier- the metadata qualifier name, ornullfor unqualifiedlang- the ISO639 language code, optionally followed by an underscore and the ISO3166 country code.nullmeans the value has no language (for example, a date).values- the values to add.- Throws:
SQLException- if database error
-
addMetadata
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, List<String> values, List<String> authorities, List<Integer> confidences) throws SQLException
Description copied from interface:DSpaceObjectServiceAdd metadata fields. These are appended to existing values. UseclearMetadatato remove values. The ordering of values passed in is maintained.- Specified by:
addMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
context- DSpace contextdso- DSpaceObjectschema- the schema for the metadata field. Must match thenameof an existing metadata schema.element- the metadata element namequalifier- the metadata qualifier name, ornullfor unqualifiedlang- the ISO639 language code, optionally followed by an underscore and the ISO3166 country code.nullmeans the value has no language (for example, a date).values- the values to add.authorities- the external authority key for this value (or null)confidences- the authority confidence (default 0)- Throws:
SQLException- if database error
-
addMetadata
public void addMetadata(Context context, T dso, MetadataField metadataField, String lang, List<String> values, List<String> authorities, List<Integer> confidences) throws SQLException
Description copied from interface:DSpaceObjectServiceAdd metadata fields. These are appended to existing values. UseclearMetadatato remove values. The ordering of values passed in is maintained.- Specified by:
addMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
context- DSpace contextdso- DSpaceObjectmetadataField- the metadata field to which the value is to be setlang- the ISO639 language code, optionally followed by an underscore and the ISO3166 country code.nullmeans the value has no language (for example, a date).values- the values to add.authorities- the external authority key for this value (or null)confidences- the authority confidence (default 0)- Throws:
SQLException- if database error
-
addMetadata
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value, String authority, int confidence) throws SQLException
Description copied from interface:DSpaceObjectServiceShortcut forDSpaceObjectService.addMetadata(Context, DSpaceObject, MetadataField, String, List, List, List)when a single value need to be added- Specified by:
addMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Throws:
SQLException
-
addMetadata
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value) throws SQLException
Description copied from interface:DSpaceObjectServiceAdd a single metadata field. This is appended to existing values. UseclearMetadatato remove values.- Specified by:
addMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
context- DSpace contextdso- DSpaceObjectschema- the schema for the metadata field. Must match thenameof an existing metadata schema.element- the metadata element namequalifier- the metadata qualifier, ornullfor unqualifiedlang- the ISO639 language code, optionally followed by an underscore and the ISO3166 country code.nullmeans the value has no language (for example, a date).value- the value to add.- Throws:
SQLException- if database error
-
addMetadata
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value) throws SQLException
- Specified by:
addMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Throws:
SQLException
-
addMetadata
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, List<String> values) throws SQLException
- Specified by:
addMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Throws:
SQLException
-
addMetadata
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value, String authority, int confidence) throws SQLException
Description copied from interface:DSpaceObjectServiceAdd a single metadata field. This is appended to existing values. UseclearMetadatato remove values.- Specified by:
addMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
context- DSpace contextdso- DSpaceObjectschema- the schema for the metadata field. Must match thenameof an existing metadata schema.element- the metadata element namequalifier- the metadata qualifier, ornullfor unqualifiedlang- the ISO639 language code, optionally followed by an underscore and the ISO3166 country code.nullmeans the value has no language (for example, a date).value- the value to add.authority- the external authority key for this value (or null)confidence- the authority confidence (default 0)- Throws:
SQLException- if database error
-
clearMetadata
public void clearMetadata(Context context, T dso, String schema, String element, String qualifier, String lang) throws SQLException
Description copied from interface:DSpaceObjectServiceClear metadata values. As withgetDCabove, passing innullonly matches fields where the qualifier orr language is actuallynull.Item.ANYwill match any element, qualifier or language, includingnull. Thus,dspaceobject.clearMetadata(Item.ANY, Item.ANY, Item.ANY)will remove all Dublin Core metadata associated with an DSpaceObject.- Specified by:
clearMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
context- DSpace contextdso- DSpaceObjectschema- the schema for the metadata field. Must match thenameof an existing metadata schema.element- the Dublin Core element to remove, orItem.ANYqualifier- the qualifier.nullmeans unqualified, andItem.ANYmeans any qualifier (including unqualified.)lang- the ISO639 language code, optionally followed by an underscore and the ISO3166 country code.nullmeans only values with no language are removed, andItem.ANYmeans values with any country code or no country code are removed.- Throws:
SQLException- if database error
-
removeMetadataValues
public void removeMetadataValues(Context context, T dso, List<MetadataValue> values) throws SQLException
- Specified by:
removeMetadataValuesin interfaceDSpaceObjectService<T extends DSpaceObject>- Throws:
SQLException
-
getMetadataFirstValue
public String getMetadataFirstValue(T dso, String schema, String element, String qualifier, String language)
Retrieve first metadata field value- Specified by:
getMetadataFirstValuein interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
dso- The DSpaceObject which we ask for metadata.schema- the schema for the metadata field. Must match thenameof an existing metadata schema.element- the element to match, orItem.ANYqualifier- the qualifier to match, orItem.ANYlanguage- the language to match, orItem.ANY- Returns:
- the first metadata field value
-
setMetadataSingleValue
public void setMetadataSingleValue(Context context, T dso, String schema, String element, String qualifier, String language, String value) throws SQLException
Set first metadata field value- Specified by:
setMetadataSingleValuein interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
context- DSpace contextdso- DSpaceObjectschema- the schema for the metadata field. Must match thenameof an existing metadata schema.element- the Dublin Core element to remove, orItem.ANYqualifier- the qualifier.nullmeans unqualified, andItem.ANYmeans any qualifier (including unqualified.)language- the ISO639 language code, optionally followed by an underscore and the ISO3166 country code.nullmeans only values with no language are removed, andItem.ANYmeans values with any country code or no country code are removed.value- metadata value- Throws:
SQLException- if database error
-
match
protected boolean match(String schema, String element, String qualifier, String language, MetadataValue metadataValue)
Utility method for pattern-matching metadata elements. This method will returntrueif the given schema, element, qualifier and language match the schema, element, qualifier and language of theDCValueobject passed in. Any or all of the element, qualifier and language passed in can be theItem.ANYwildcard.- Parameters:
schema- the schema for the metadata field. Must match thenameof an existing metadata schema.element- the element to match, orItem.ANYqualifier- the qualifier to match, orItem.ANYlanguage- the language to match, orItem.ANYmetadataValue- the Dublin Core value- Returns:
trueif there is a match
-
getAuthoritiesAndConfidences
protected void getAuthoritiesAndConfidences(String fieldKey, Collection collection, List<String> values, List<String> authorities, List<Integer> confidences, int i)
-
getElements
protected String[] getElements(String fieldName)
Splits "schema.element.qualifier.language" into an array.The returned array will always have length greater than or equal to 4
Values in the returned array can be empty or null.
- Parameters:
fieldName- field name- Returns:
- array
-
getElementsFilled
protected String[] getElementsFilled(String fieldName)
Splits "schema.element.qualifier.language" into an array.The returned array will always have length greater than or equal to 4
When @param fill is true, elements that would be empty or null are replaced by Item.ANY
- Parameters:
fieldName- field name- Returns:
- array
-
update
public void update(Context context, T dso) throws SQLException, AuthorizeException
- Specified by:
updatein interfaceDSpaceObjectService<T extends DSpaceObject>- Throws:
SQLExceptionAuthorizeException
-
getMetadataValuePlace
protected int getMetadataValuePlace(Map<MetadataField,Integer> fieldToLastPlace, MetadataValue metadataValue)
Retrieve the place of the metadata value- Parameters:
fieldToLastPlace- the map containing the latest place of each metadata fieldmetadataValue- the metadata value that needs to get a place- Returns:
- The new place for the metadata value
-
addAndShiftRightMetadata
public void addAndShiftRightMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value, String authority, int confidence, int index) throws SQLException
Description copied from interface:DSpaceObjectServiceAdd a single metadata field. Whether it's appended or prepended depends on index parameter. UseclearMetadatato remove values.- Specified by:
addAndShiftRightMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
context- DSpace contextdso- DSpaceObjectschema- the schema for the metadata field. Must match thenameof an existing metadata schema.element- the metadata element namequalifier- the metadata qualifier, ornullfor unqualifiedlang- the ISO639 language code, optionally followed by an underscore and the ISO3166 country code.nullmeans the value has no language (for example, a date).value- the value to add.authority- the external authority key for this value (or null)confidence- the authority confidence (default 0)index- the index at which this metadata is added (0: first place, -1 for last)- Throws:
SQLException- if database error
-
moveMetadata
public void moveMetadata(Context context, T dso, String schema, String element, String qualifier, int from, int to) throws SQLException, IllegalArgumentException
- Specified by:
moveMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Throws:
SQLExceptionIllegalArgumentException
-
replaceMetadata
public void replaceMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value, String authority, int confidence, int index) throws SQLException
- Specified by:
replaceMetadatain interfaceDSpaceObjectService<T extends DSpaceObject>- Throws:
SQLException
-
setMetadataModified
public void setMetadataModified(T dso)
Description copied from interface:DSpaceObjectServiceTrigger the modifiedMetadata variable in DSpaceObject- Specified by:
setMetadataModifiedin interfaceDSpaceObjectService<T extends DSpaceObject>- Parameters:
dso- DSpaceObject whose metadata has been modified
-
-