From dc7bee8347db1538bae09dbaad0d665fb59bf9ae Mon Sep 17 00:00:00 2001 From: Scott Phillips Date: Tue, 2 Oct 2007 23:06:56 +0000 Subject: [PATCH] (Scott Phillips) Modified ItemImport so that when testing, i.e. the -t flag, each metadata field that is being added is check to see if it exists. If the field does not exist then an error message is printed, and the test continues. git-svn-id: http://scm.dspace.org/svn/repo/trunk@2230 9c30dcfa-912a-0410-8fc2-9e0234be79fd --- .../org/dspace/app/itemimport/ItemImport.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java b/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java index a811652181..12a79c32f0 100755 --- a/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java +++ b/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java @@ -74,6 +74,7 @@ import org.dspace.content.Collection; import org.dspace.content.FormatIdentifier; import org.dspace.content.InstallItem; import org.dspace.content.Item; +import org.dspace.content.MetadataField; import org.dspace.content.MetadataSchema; import org.dspace.content.WorkspaceItem; import org.dspace.core.ConfigurationManager; @@ -785,7 +786,7 @@ public class ItemImport // Load all metadata schemas into the item. private void loadMetadata(Context c, Item myitem, String path) throws SQLException, IOException, ParserConfigurationException, - SAXException, TransformerException + SAXException, TransformerException, AuthorizeException { // Load the dublin core metadata loadDublinCore(c, myitem, path + "dublin_core.xml"); @@ -801,7 +802,7 @@ public class ItemImport private void loadDublinCore(Context c, Item myitem, String filename) throws SQLException, IOException, ParserConfigurationException, - SAXException, TransformerException //, AuthorizeException + SAXException, TransformerException, AuthorizeException { Document document = loadXML(filename); @@ -831,11 +832,11 @@ public class ItemImport for (int i = 0; i < dcNodes.getLength(); i++) { Node n = dcNodes.item(i); - addDCValue(myitem, schema, n); + addDCValue(c, myitem, schema, n); } } - private void addDCValue(Item i, String schema, Node n) throws TransformerException + private void addDCValue(Context c, Item i, String schema, Node n) throws TransformerException, SQLException, AuthorizeException { String value = getStringValue(n); //n.getNodeValue(); // compensate for empty value getting read as "null", which won't display @@ -872,6 +873,26 @@ public class ItemImport { i.addMetadata(schema, element, qualifier, language, value); } + else + { + // If we're just test the import, let's check that the actual metadata field exists. + MetadataSchema foundSchema = MetadataSchema.find(c,schema); + + if (foundSchema == null) + { + System.out.println("ERROR: schema '"+schema+"' was not found in the registry."); + return; + } + + int schemaID = foundSchema.getSchemaID(); + MetadataField foundField = MetadataField.findByElement(c, schemaID, element, qualifier); + + if (foundField == null) + { + System.out.println("ERROR: Metadata field: '"+schema+"."+element+"."+qualifier+"' was not found in the registry."); + return; + } + } } /**