Class DSpaceObjectServiceImpl<T extends DSpaceObject>

    • Constructor Detail

      • DSpaceObjectServiceImpl

        public DSpaceObjectServiceImpl()
    • Method Detail

      • getName

        public String getName​(T dso)
        Description copied from interface: DSpaceObjectService
        Get a proper name for the object. This may return null. Name should be suitable for display in a user interface.
        Specified by:
        getName in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        dso - DSpaceObject
        Returns:
        Name for the object, or null if it doesn't have one
      • getParentObject

        public DSpaceObject getParentObject​(Context context,
                                            T dso)
                                     throws SQLException
        Description copied from interface: DSpaceObjectService
        Return 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:
        getParentObject in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        context - DSpace context
        dso - 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: DSpaceObjectService
        Return 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:
        getAdminObject in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        context - DSpace context
        dso - DSpaceObject
        action - ID of action being attempted, from org.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
      • getMetadata

        public List<MetadataValue> getMetadata​(T dso,
                                               String schema,
                                               String element,
                                               String qualifier,
                                               String lang)
        Description copied from interface: DSpaceObjectService
        Get metadata for the DSpace Object in a chosen schema. See MetadataSchema for more information about schemas. Passing in a null value for qualifier or lang only matches metadata fields where that qualifier or languages is actually null. Passing in DSpaceObject.ANY retrieves all metadata fields with any value for the qualifier or language, including null

        Examples:

        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:
        getMetadata in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        dso - DSpaceObject
        schema - the schema for the metadata field. Must match the name of an existing metadata schema.
        element - the element name. DSpaceObject.ANY matches any element. null doesn't really make sense as all metadata must have an element.
        qualifier - the qualifier. null means unqualified, and DSpaceObject.ANY means any qualifier (including unqualified.)
        lang - the ISO639 language code, optionally followed by an underscore and the ISO3166 country code. null means only values with no language are returned, and DSpaceObject.ANY means 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: DSpaceObjectService
        Retrieve metadata field values from a given metadata string of the form <schema prefix>.<element>[.<qualifier>|.*]
        Specified by:
        getMetadataByMetadataString in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        dso - DSpaceObject
        mdString - 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: DSpaceObjectService
        Get the value of a metadata field
        Specified by:
        getMetadata in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        dso - DSpaceObject
        value - the name of the metadata field to get
        Returns:
        the value of the metadata field (or null if the column is an SQL NULL)
      • 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: DSpaceObjectService
        Add metadata fields. These are appended to existing values. Use clearMetadata to 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:
        addMetadata in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        context - DSpace context
        dso - DSpaceObject
        schema - the schema for the metadata field. Must match the name of an existing metadata schema.
        element - the metadata element name
        qualifier - the metadata qualifier name, or null for unqualified
        lang - the ISO639 language code, optionally followed by an underscore and the ISO3166 country code. null means 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: DSpaceObjectService
        Add metadata fields. These are appended to existing values. Use clearMetadata to remove values. The ordering of values passed in is maintained.
        Specified by:
        addMetadata in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        context - DSpace context
        dso - DSpaceObject
        schema - the schema for the metadata field. Must match the name of an existing metadata schema.
        element - the metadata element name
        qualifier - the metadata qualifier name, or null for unqualified
        lang - the ISO639 language code, optionally followed by an underscore and the ISO3166 country code. null means 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: DSpaceObjectService
        Add metadata fields. These are appended to existing values. Use clearMetadata to remove values. The ordering of values passed in is maintained.
        Specified by:
        addMetadata in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        context - DSpace context
        dso - DSpaceObject
        metadataField - the metadata field to which the value is to be set
        lang - the ISO639 language code, optionally followed by an underscore and the ISO3166 country code. null means 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,
                                String schema,
                                String element,
                                String qualifier,
                                String lang,
                                String value)
                         throws SQLException
        Description copied from interface: DSpaceObjectService
        Add a single metadata field. This is appended to existing values. Use clearMetadata to remove values.
        Specified by:
        addMetadata in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        context - DSpace context
        dso - DSpaceObject
        schema - the schema for the metadata field. Must match the name of an existing metadata schema.
        element - the metadata element name
        qualifier - the metadata qualifier, or null for unqualified
        lang - the ISO639 language code, optionally followed by an underscore and the ISO3166 country code. null means 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,
                                String schema,
                                String element,
                                String qualifier,
                                String lang,
                                String value,
                                String authority,
                                int confidence)
                         throws SQLException
        Description copied from interface: DSpaceObjectService
        Add a single metadata field. This is appended to existing values. Use clearMetadata to remove values.
        Specified by:
        addMetadata in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        context - DSpace context
        dso - DSpaceObject
        schema - the schema for the metadata field. Must match the name of an existing metadata schema.
        element - the metadata element name
        qualifier - the metadata qualifier, or null for unqualified
        lang - the ISO639 language code, optionally followed by an underscore and the ISO3166 country code. null means 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: DSpaceObjectService
        Clear metadata values. As with getDC above, passing in null only matches fields where the qualifier orr language is actually null.Item.ANY will match any element, qualifier or language, including null. Thus, dspaceobject.clearMetadata(Item.ANY, Item.ANY, Item.ANY) will remove all Dublin Core metadata associated with an DSpaceObject.
        Specified by:
        clearMetadata in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        context - DSpace context
        dso - DSpaceObject
        schema - the schema for the metadata field. Must match the name of an existing metadata schema.
        element - the Dublin Core element to remove, or Item.ANY
        qualifier - the qualifier. null means unqualified, and Item.ANY means any qualifier (including unqualified.)
        lang - the ISO639 language code, optionally followed by an underscore and the ISO3166 country code. null means only values with no language are removed, and Item.ANY means values with any country code or no country code are removed.
        Throws:
        SQLException - if database error
      • getMetadataFirstValue

        public String getMetadataFirstValue​(T dso,
                                            String schema,
                                            String element,
                                            String qualifier,
                                            String language)
        Retrieve first metadata field value
        Specified by:
        getMetadataFirstValue in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        dso - The DSpaceObject which we ask for metadata.
        schema - the schema for the metadata field. Must match the name of an existing metadata schema.
        element - the element to match, or Item.ANY
        qualifier - the qualifier to match, or Item.ANY
        language - the language to match, or Item.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:
        setMetadataSingleValue in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        context - DSpace context
        dso - DSpaceObject
        schema - the schema for the metadata field. Must match the name of an existing metadata schema.
        element - the Dublin Core element to remove, or Item.ANY
        qualifier - the qualifier. null means unqualified, and Item.ANY means any qualifier (including unqualified.)
        language - the ISO639 language code, optionally followed by an underscore and the ISO3166 country code. null means only values with no language are removed, and Item.ANY means 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 return true if the given schema, element, qualifier and language match the schema, element, qualifier and language of the DCValue object passed in. Any or all of the element, qualifier and language passed in can be the Item.ANY wildcard.
        Parameters:
        schema - the schema for the metadata field. Must match the name of an existing metadata schema.
        element - the element to match, or Item.ANY
        qualifier - the qualifier to match, or Item.ANY
        language - the language to match, or Item.ANY
        metadataValue - the Dublin Core value
        Returns:
        true if there is a match
      • 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
      • getMDValueByField

        protected String[] getMDValueByField​(String field)
      • 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 field
        metadataValue - the metadata value that needs to get a place
        Returns:
        The new place for the metadata value
      • getMDValueByLegacyField

        protected String[] getMDValueByLegacyField​(String field)
      • 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: DSpaceObjectService
        Add a single metadata field. Whether it's appended or prepended depends on index parameter. Use clearMetadata to remove values.
        Specified by:
        addAndShiftRightMetadata in interface DSpaceObjectService<T extends DSpaceObject>
        Parameters:
        context - DSpace context
        dso - DSpaceObject
        schema - the schema for the metadata field. Must match the name of an existing metadata schema.
        element - the metadata element name
        qualifier - the metadata qualifier, or null for unqualified
        lang - the ISO639 language code, optionally followed by an underscore and the ISO3166 country code. null means 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