Class MetadataImport


  • public class MetadataImport
    extends Object
    Metadata importer to allow the batch import of metadata from a file
    Author:
    Stuart Lewis
    • Constructor Detail

      • MetadataImport

        public MetadataImport​(Context c,
                              DSpaceCSV toImport)
        Create an instance of the metadata importer. Requires a context and an array of CSV lines to examine.
        Parameters:
        c - The context
        toImport - An array of CSV lines to examine
    • Method Detail

      • runImport

        public List<BulkEditChange> runImport​(boolean change,
                                              boolean useWorkflow,
                                              boolean workflowNotify,
                                              boolean useTemplate)
                                       throws MetadataImportException
        Run an import. The import can either be read-only to detect changes, or can write changes as it goes.
        Parameters:
        change - Whether or not to write the changes to the database
        useWorkflow - Whether the workflows should be used when creating new items
        workflowNotify - If the workflows should be used, whether to send notifications or not
        useTemplate - Use collection template if create new item
        Returns:
        An array of BulkEditChange elements representing the items that have changed
        Throws:
        MetadataImportException - if something goes wrong
      • compareAndUpdate

        protected void compareAndUpdate​(Item item,
                                        String[] fromCSV,
                                        boolean change,
                                        String md,
                                        BulkEditChange changes,
                                        DSpaceCSVLine line)
                                 throws SQLException,
                                        AuthorizeException,
                                        MetadataImportException
        Compare an item metadata with a line from CSV, and optionally update the item.
        Parameters:
        item - The current item metadata
        fromCSV - The metadata from the CSV file
        change - Whether or not to make the update
        md - The element to compare
        changes - The changes object to populate
        line - line in CSV file
        Throws:
        SQLException - if there is a problem accessing a Collection from the database, from its handle
        AuthorizeException - if there is an authorization problem with permissions
        MetadataImportException - custom exception for error handling within metadataimport
      • compare

        protected void compare​(Item item,
                               List<String> collections,
                               List<Collection> actualCollections,
                               BulkEditChange bechange,
                               boolean change)
                        throws SQLException,
                               AuthorizeException,
                               IOException,
                               MetadataImportException
        Compare changes between an items owning collection and mapped collections and what is in the CSV file
        Parameters:
        item - The item in question
        collections - The collection handles from the CSV file
        actualCollections - The Collections from the actual item
        bechange - The bulkedit change object for this item
        change - Whether or not to actuate a change
        Throws:
        SQLException - if there is a problem accessing a Collection from the database, from its handle
        AuthorizeException - if there is an authorization problem with permissions
        IOException - Can be thrown when moving items in communities
        MetadataImportException - If something goes wrong to be reported back to the user
      • add

        protected void add​(String[] fromCSV,
                           String md,
                           BulkEditChange changes)
                    throws SQLException,
                           AuthorizeException
        Add an item metadata with a line from CSV, and optionally update the item
        Parameters:
        fromCSV - The metadata from the CSV file
        md - The element to compare
        changes - The changes object to populate
        Throws:
        SQLException - when an SQL error has occurred (querying DSpace)
        AuthorizeException - If the user can't make the changes
      • contains

        protected boolean contains​(String needle,
                                   String[] haystack)
        Method to find if a String occurs in an array of Strings
        Parameters:
        needle - The String to look for
        haystack - The array of Strings to search through
        Returns:
        Whether or not it is contained
      • clean

        protected String clean​(String in)
        Clean elements before comparing
        Parameters:
        in - The element to clean
        Returns:
        The cleaned up element
      • main

        public static void main​(String[] argv)
        main method to run the metadata exporter
        Parameters:
        argv - the command line arguments given
      • resolveEntityRefs

        public DSpaceCSVLine resolveEntityRefs​(DSpaceCSVLine line)
                                        throws MetadataImportException
        Gets a copy of the given csv line with all entity target references resolved to UUID strings. Keys being iterated over represent metadatafields or special columns to be processed.
        Parameters:
        line - the csv line to process.
        Returns:
        a copy, with all references resolved.
        Throws:
        MetadataImportException - if there is an error resolving any entity target reference.