Class ItemImportServiceImpl

  • All Implemented Interfaces:
    ItemImportService, org.springframework.beans.factory.InitializingBean

    public class ItemImportServiceImpl
    extends Object
    implements ItemImportService, org.springframework.beans.factory.InitializingBean
    Import items into DSpace. The conventional use is upload files by copying them. DSpace writes the item's bitstreams into its assetstore. Metadata is also loaded to the DSpace database.

    A second use assumes the bitstream files already exist in a storage resource accessible to DSpace. In this case the bitstreams are 'registered'. That is, the metadata is loaded to the DSpace database and DSpace is given the location of the file which is subsumed into DSpace.

    The distinction is controlled by the format of lines in the 'contents' file. See comments in processContentsFile() below.

    Modified by David Little, UCSD Libraries 12/21/04 to allow the registration of files (bitstreams) into DSpace.

    • Field Detail

      • authorizeService

        @Autowired(required=true)
        protected AuthorizeService authorizeService
      • bitstreamService

        @Autowired(required=true)
        protected BitstreamService bitstreamService
      • bundleService

        @Autowired(required=true)
        protected BundleService bundleService
      • collectionService

        @Autowired(required=true)
        protected CollectionService collectionService
      • ePersonService

        @Autowired(required=true)
        protected EPersonService ePersonService
      • handleService

        @Autowired(required=true)
        protected HandleService handleService
      • itemService

        @Autowired(required=true)
        protected ItemService itemService
      • installItemService

        @Autowired(required=true)
        protected InstallItemService installItemService
      • groupService

        @Autowired(required=true)
        protected GroupService groupService
      • metadataFieldService

        @Autowired(required=true)
        protected MetadataFieldService metadataFieldService
      • workspaceItemService

        @Autowired(required=true)
        protected WorkspaceItemService workspaceItemService
      • workflowService

        @Autowired(required=true)
        protected WorkflowService workflowService
      • configurationService

        @Autowired(required=true)
        protected ConfigurationService configurationService
      • relationshipService

        @Autowired(required=true)
        protected RelationshipService relationshipService
      • metadataValueService

        @Autowired(required=true)
        protected MetadataValueService metadataValueService
      • tempWorkDir

        protected String tempWorkDir
      • isTest

        protected boolean isTest
      • isResume

        protected boolean isResume
      • useWorkflow

        protected boolean useWorkflow
      • useWorkflowSendEmail

        protected boolean useWorkflowSendEmail
      • isQuiet

        protected boolean isQuiet
    • Constructor Detail

      • ItemImportServiceImpl

        protected ItemImportServiceImpl()
    • Method Detail

      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws Exception
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        Exception
      • addItemsAtomic

        public void addItemsAtomic​(Context c,
                                   List<Collection> mycollections,
                                   String sourceDir,
                                   String mapFile,
                                   boolean template)
                            throws Exception
        Specified by:
        addItemsAtomic in interface ItemImportService
        Parameters:
        c - DSpace Context
        mycollections - List of Collections
        sourceDir - source location
        mapFile - map file
        template - whether to use template item
        Throws:
        Exception - if error
      • addRelationships

        protected void addRelationships​(Context c,
                                        String sourceDir)
                                 throws Exception
        Add relationships from a 'relationships' manifest file.
        Parameters:
        c - Context
        sourceDir - The parent import source directory
        Throws:
        Exception
      • getEntityType

        protected String getEntityType​(Item item)
                                throws Exception
        Get the item's entity type from meta.
        Parameters:
        item -
        Returns:
        Throws:
        Exception
      • processRelationshipFile

        protected Map<String,​List<String>> processRelationshipFile​(String path,
                                                                         String filename)
                                                                  throws Exception
        Read the relationship manifest file. Each line in the file contains a relationship type id and an item identifier in the following format: relation. The input_item_folder should refer the folder name of another item in this import batch.
        Parameters:
        path - The main import folder path.
        filename - The name of the manifest file to check ('relationships')
        Returns:
        Map of found relationships
        Throws:
        Exception
      • resolveRelatedItem

        protected Item resolveRelatedItem​(Context c,
                                          String itemIdentifier)
                                   throws Exception
        Resolve an item identifier referred to in the relationships manifest file. The import item map will be checked first to see if the identifier refers to an item folder that was just imported. Next it will try to find the item by handle or UUID, or by a unique meta value.
        Parameters:
        c - Context
        itemIdentifier - The identifier string found in the import manifest (handle, uuid, or import subfolder)
        Returns:
        Item if found, or null.
        Throws:
        Exception
      • findItemByMetaValue

        protected Item findItemByMetaValue​(Context c,
                                           String metaKey,
                                           String metaValue)
                                    throws Exception
        Lookup an item by a (unique) meta value.
        Parameters:
        metaKey -
        metaValue -
        Returns:
        Item
        Throws:
        Exception - if single item not found.
      • addItem

        protected Item addItem​(Context c,
                               List<Collection> mycollections,
                               String path,
                               String itemname,
                               PrintWriter mapOut,
                               boolean template)
                        throws Exception
        item? try and add it to the archive.
        Parameters:
        c - current Context
        mycollections - - add item to these Collections.
        path - - directory containing the item directories.
        itemname - handle - non-null means we have a pre-defined handle already
        mapOut - - mapfile we're writing
        template - whether to use collection template item as starting point
        Returns:
        Item
        Throws:
        Exception - if error occurs
      • processCollectionFile

        protected List<Collection> processCollectionFile​(Context c,
                                                         String path,
                                                         String filename)
                                                  throws IOException,
                                                         SQLException
        Read the collections file inside the item directory. If there is one and it is not empty return a list of collections in which the item should be inserted. If it does not exist or it is empty return null.
        Parameters:
        c - The context
        path - The path to the data directory for this item
        filename - The collections file filename. Should be "collections"
        Returns:
        A list of collections in which to insert the item or null
        Throws:
        IOException - if IO error
        SQLException - if database error
      • processHandleFile

        protected String processHandleFile​(Context c,
                                           Item i,
                                           String path,
                                           String filename)
        Read in the handle file contents or return null if empty or doesn't exist
        Parameters:
        c - DSpace context
        i - DSpace item
        path - path to handle file
        filename - name of file
        Returns:
        handle file contents or null if doesn't exist
      • processContentsFile

        protected List<String> processContentsFile​(Context c,
                                                   Item i,
                                                   String path,
                                                   String filename)
                                            throws SQLException,
                                                   IOException,
                                                   AuthorizeException
        Given a contents file and an item, stuffing it with bitstreams from the contents file Returns a List of Strings with lines from the contents file that request non-default bitstream permission
        Parameters:
        c - DSpace Context
        i - DSpace item
        path - path as string
        filename - file name
        Returns:
        List of Strings
        Throws:
        SQLException - if database error
        IOException - if IO error
        AuthorizeException - if authorization error
      • registerBitstream

        protected void registerBitstream​(Context c,
                                         Item i,
                                         int assetstore,
                                         String bitstreamPath,
                                         String bundleName,
                                         String description)
                                  throws SQLException,
                                         IOException,
                                         AuthorizeException
        Register the bitstream file into DSpace
        Parameters:
        c - DSpace Context
        i - DSpace Item
        assetstore - assetstore number
        bitstreamPath - the full filepath expressed in the contents file
        bundleName - bundle name
        description - bitstream description
        Throws:
        SQLException - if database error
        IOException - if IO error
        AuthorizeException - if authorization error
      • processOptions

        protected void processOptions​(Context c,
                                      Item myItem,
                                      List<String> options)
                               throws SQLException,
                                      AuthorizeException
        Process the Options to apply to the Item. The options are tab delimited Options: 48217870-MIT.pdf permissions: -r 'MIT Users' description: Full printable version (MIT only) permissions:[r|w]-['group name'] description: 'the description of the file' where: [r|w] (meaning: read|write) ['MIT Users'] (the group name)
        Parameters:
        c - DSpace Context
        myItem - DSpace Item
        options - List of option strings
        Throws:
        SQLException - if database error
        AuthorizeException - if authorization error
      • getStringValue

        protected String getStringValue​(Node node)
        Return the String value of a Node.
        Parameters:
        node - node
        Returns:
        string value
      • deleteDirectory

        protected boolean deleteDirectory​(File path)
        Delete a directory and its child files and directories
        Parameters:
        path - The directory to delete
        Returns:
        Whether the deletion was successful or not
      • generateRandomFilename

        protected String generateRandomFilename​(boolean hidden)
        Generate a random filename based on current time
        Parameters:
        hidden - set to add . as a prefix to make the file hidden
        Returns:
        the filename
      • processUIImport

        public void processUIImport​(String filepath,
                                    Collection owningCollection,
                                    String[] otherCollections,
                                    String resumeDir,
                                    String inputType,
                                    Context context,
                                    boolean template)
                             throws Exception
        Given a local file or public URL to a zip file that has the Simple Archive Format, this method imports the contents to DSpace
        Specified by:
        processUIImport in interface ItemImportService
        Parameters:
        filepath - The filepath to local file or the public URL of the zip file
        owningCollection - The owning collection the items will belong to
        otherCollections - The collections the created items will be inserted to, apart from the owning one
        resumeDir - In case of a resume request, the directory that containsthe old mapfile and data
        inputType - The input type of the data (bibtex, csv, etc.), in case of local file
        context - The context
        template - whether to use template item
        Throws:
        Exception - if error
      • emailSuccessMessage

        public void emailSuccessMessage​(Context context,
                                        EPerson eperson,
                                        String fileName)
                                 throws javax.mail.MessagingException
        Description copied from interface: ItemImportService
        If a batch import is done in a new thread we are unable to communicate with calling method about success or failure. We accomplish this communication with email instead. Send a success email once the batch import is complete
        Specified by:
        emailSuccessMessage in interface ItemImportService
        Parameters:
        context - - the current Context
        eperson - - eperson to send the email to
        fileName - - the filepath to the mapfile created by the batch import
        Throws:
        javax.mail.MessagingException - if error
      • emailErrorMessage

        public void emailErrorMessage​(EPerson eperson,
                                      String error)
                               throws javax.mail.MessagingException
        Description copied from interface: ItemImportService
        If a batch import is done in a new thread we are unable to communicate with calling method about success or failure. We accomplis this communication with email instead. Send an error email if the batch import fails
        Specified by:
        emailErrorMessage in interface ItemImportService
        Parameters:
        eperson - - EPerson to send the error message to
        error - - the error message
        Throws:
        javax.mail.MessagingException - if error
      • setTest

        public void setTest​(boolean isTest)
        Description copied from interface: ItemImportService
        Set test flag
        Specified by:
        setTest in interface ItemImportService
        Parameters:
        isTest - true or false
      • setResume

        public void setResume​(boolean isResume)
        Description copied from interface: ItemImportService
        Set resume flag
        Specified by:
        setResume in interface ItemImportService
        Parameters:
        isResume - true or false
      • setUseWorkflow

        public void setUseWorkflow​(boolean useWorkflow)
        Description copied from interface: ItemImportService
        Set use workflow
        Specified by:
        setUseWorkflow in interface ItemImportService
        Parameters:
        useWorkflow - whether to enable workflow
      • setUseWorkflowSendEmail

        public void setUseWorkflowSendEmail​(boolean useWorkflowSendEmail)
        Specified by:
        setUseWorkflowSendEmail in interface ItemImportService
        Parameters:
        useWorkflowSendEmail - whether to send mail
      • setQuiet

        public void setQuiet​(boolean isQuiet)
        Description copied from interface: ItemImportService
        Set quiet flag
        Specified by:
        setQuiet in interface ItemImportService
        Parameters:
        isQuiet - true or false