Class DSpaceObjectMetadataPatchUtils


  • @Component
    public final class DSpaceObjectMetadataPatchUtils
    extends Object
    Util class for shared methods between the Metadata Operations
    Author:
    Maria Verdonck (Atmire) on 18/11/2019
    • Field Detail

      • OPERATION_METADATA_PATH

        public static final String OPERATION_METADATA_PATH
        Path in json body of patch that uses these metadata operations
        See Also:
        Constant Field Values
    • Method Detail

      • extractMetadataValueFromOperation

        protected MetadataValueRest extractMetadataValueFromOperation​(Operation operation)
        Extract metadataValue from Operation by parsing the json and mapping it to a MetadataValueRest
        Parameters:
        operation - Operation whose value is begin parsed
        Returns:
        MetadataValueRest extracted from json in operation value
      • extractMdFieldStringFromOperation

        protected String extractMdFieldStringFromOperation​(Operation operation)
        Extracts the mdField String (schema.element.qualifier) from the operation and returns it
        Parameters:
        operation - The patch operation
        Returns:
        The mdField (schema.element.qualifier) patch is being performed on
      • convertMdValueToRest

        protected MetadataValueRest convertMdValueToRest​(org.dspace.content.MetadataValue md)
        Converts a metadataValue (database entity) to a REST equivalent of it
        Parameters:
        md - Original metadataValue
        Returns:
        The REST equivalent
      • extractPropertyOfMdFromPath

        protected String extractPropertyOfMdFromPath​(String[] partsOfPath)
        Extracts which property of the metadata is being changed in the replace patch operation
        Parameters:
        partsOfPath - Parts of the path of the operation, separated with /
        Returns:
        The property that is begin replaced of the metadata
      • extractNewValueOfMd

        protected String extractNewValueOfMd​(Operation operation)
        Extracts the new value of the metadata from the operation for the replace patch operation
        Parameters:
        operation - The patch operation
        Returns:
        The new value of the metadata being replaced in the patch operation
      • getMetadataField

        protected org.dspace.content.MetadataField getMetadataField​(org.dspace.core.Context context,
                                                                    Operation operation)
                                                             throws SQLException
        Retrieves metadataField based on the metadata element found in the operation
        Parameters:
        context - Context the retrieve metadataField from service with string
        operation - Operation of the patch
        Returns:
        The metadataField corresponding to the md element string of the operation
        Throws:
        SQLException
      • getIndexFromPath

        protected String getIndexFromPath​(String path)
        Retrieved the index from the path of the patch operation, if one can be found
        Parameters:
        path - The string from the operation
        Returns:
        The index in the path if there is one (path ex: /metadata/dc.title/1 (1 being the index))
      • checkMetadataFieldNotNull

        protected void checkMetadataFieldNotNull​(org.dspace.content.MetadataField metadataField)