Package org.dspace.app.bulkedit
Class MetadataImport
- java.lang.Object
-
- org.dspace.app.bulkedit.MetadataImport
-
public class MetadataImport extends Object
Metadata importer to allow the batch import of metadata from a file- Author:
- Stuart Lewis
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringAC_PREFIXThe prefix of the authority controlled fieldprotected static Set<String>authorityControlledThe authority controlled fieldsprotected AuthorityValueServiceauthorityValueServiceprotected CollectionServicecollectionServiceprotected Map<String,Set<Integer>>csvRefMapMap of field:value to csv row number, used to resolve indirect entity target references.protected HashMap<Integer,UUID>csvRowMapMap of csv row number to UUID, used to resolve indirect entity target references.protected static HashMap<String,HashMap<String,ArrayList<String>>>entityRelationMapMap of UUIDs to their relations that are referenced within any import with their referers.protected EntityServiceentityServiceprotected static HashMap<UUID,String>entityTypeMapMap of UUIDs to their entity types.protected EntityTypeServiceentityTypeServiceprotected HandleServicehandleServiceprotected InstallItemServiceinstallItemServiceprotected ItemServiceitemServiceprotected static org.apache.logging.log4j.LoggerlogLoggerprotected RelationshipServicerelationshipServiceprotected RelationshipTypeServicerelationshipTypeServiceprotected ArrayList<String>relationValidationErrorsCollection of errors generated during relation validation process.protected IntegerrowCountCounter of rows proccssed in a CSV.protected WorkspaceItemServiceworkspaceItemService
-
Constructor Summary
Constructors Constructor Description MetadataImport(Context c, DSpaceCSV toImport)Create an instance of the metadata importer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidadd(String[] fromCSV, String md, BulkEditChange changes)Add an item metadata with a line from CSV, and optionally update the itemprotected Stringclean(String in)Clean elements before comparingprotected voidcompare(Item item, List<String> collections, List<Collection> actualCollections, BulkEditChange bechange, boolean change)Compare changes between an items owning collection and mapped collections and what is in the CSV fileprotected voidcompareAndUpdate(Item item, String[] fromCSV, boolean change, String md, BulkEditChange changes, DSpaceCSVLine line)Compare an item metadata with a line from CSV, and optionally update the item.protected booleancontains(String needle, String[] haystack)Method to find if a String occurs in an array of Stringsprotected BulkEditMetadataValuegetBulkEditValueFromCSV(String language, String schema, String element, String qualifier, String value, AuthorityValue fromAuthority)static voidmain(String[] argv)main method to run the metadata exporterDSpaceCSVLineresolveEntityRefs(DSpaceCSVLine line)Gets a copy of the given csv line with all entity target references resolved to UUID strings.List<BulkEditChange>runImport(boolean change, boolean useWorkflow, boolean workflowNotify, boolean useTemplate)Run an import.protected voidsimplyCopyValue(String value, BulkEditMetadataValue dcv)
-
-
-
Field Detail
-
authorityControlled
protected static Set<String> authorityControlled
The authority controlled fields
-
AC_PREFIX
protected static final String AC_PREFIX
The prefix of the authority controlled field- See Also:
- Constant Field Values
-
csvRefMap
protected Map<String,Set<Integer>> csvRefMap
Map of field:value to csv row number, used to resolve indirect entity target references.
-
csvRowMap
protected HashMap<Integer,UUID> csvRowMap
Map of csv row number to UUID, used to resolve indirect entity target references.
-
entityTypeMap
protected static HashMap<UUID,String> entityTypeMap
Map of UUIDs to their entity types.
-
entityRelationMap
protected static HashMap<String,HashMap<String,ArrayList<String>>> entityRelationMap
Map of UUIDs to their relations that are referenced within any import with their referers.
-
relationValidationErrors
protected ArrayList<String> relationValidationErrors
Collection of errors generated during relation validation process.
-
rowCount
protected Integer rowCount
Counter of rows proccssed in a CSV.
-
log
protected static final org.apache.logging.log4j.Logger log
Logger
-
authorityValueService
protected final AuthorityValueService authorityValueService
-
itemService
protected final ItemService itemService
-
installItemService
protected final InstallItemService installItemService
-
collectionService
protected final CollectionService collectionService
-
handleService
protected final HandleService handleService
-
workspaceItemService
protected final WorkspaceItemService workspaceItemService
-
relationshipTypeService
protected final RelationshipTypeService relationshipTypeService
-
relationshipService
protected final RelationshipService relationshipService
-
entityTypeService
protected final EntityTypeService entityTypeService
-
entityService
protected final EntityService entityService
-
-
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 databaseuseWorkflow- Whether the workflows should be used when creating new itemsworkflowNotify- If the workflows should be used, whether to send notifications or notuseTemplate- 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 metadatafromCSV- The metadata from the CSV filechange- Whether or not to make the updatemd- The element to comparechanges- The changes object to populateline- line in CSV file- Throws:
SQLException- if there is a problem accessing a Collection from the database, from its handleAuthorizeException- if there is an authorization problem with permissionsMetadataImportException- 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 questioncollections- The collection handles from the CSV fileactualCollections- The Collections from the actual itembechange- The bulkedit change object for this itemchange- Whether or not to actuate a change- Throws:
SQLException- if there is a problem accessing a Collection from the database, from its handleAuthorizeException- if there is an authorization problem with permissionsIOException- Can be thrown when moving items in communitiesMetadataImportException- 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 filemd- The element to comparechanges- The changes object to populate- Throws:
SQLException- when an SQL error has occurred (querying DSpace)AuthorizeException- If the user can't make the changes
-
getBulkEditValueFromCSV
protected BulkEditMetadataValue getBulkEditValueFromCSV(String language, String schema, String element, String qualifier, String value, AuthorityValue fromAuthority)
-
simplyCopyValue
protected void simplyCopyValue(String value, BulkEditMetadataValue dcv)
-
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 forhaystack- 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.
-
-