(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
This commit is contained in:
Scott Phillips
2007-10-02 23:06:56 +00:00
parent bf971ddca1
commit dc7bee8347

View File

@@ -74,6 +74,7 @@ import org.dspace.content.Collection;
import org.dspace.content.FormatIdentifier; import org.dspace.content.FormatIdentifier;
import org.dspace.content.InstallItem; import org.dspace.content.InstallItem;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema; import org.dspace.content.MetadataSchema;
import org.dspace.content.WorkspaceItem; import org.dspace.content.WorkspaceItem;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
@@ -785,7 +786,7 @@ public class ItemImport
// Load all metadata schemas into the item. // Load all metadata schemas into the item.
private void loadMetadata(Context c, Item myitem, String path) private void loadMetadata(Context c, Item myitem, String path)
throws SQLException, IOException, ParserConfigurationException, throws SQLException, IOException, ParserConfigurationException,
SAXException, TransformerException SAXException, TransformerException, AuthorizeException
{ {
// Load the dublin core metadata // Load the dublin core metadata
loadDublinCore(c, myitem, path + "dublin_core.xml"); loadDublinCore(c, myitem, path + "dublin_core.xml");
@@ -801,7 +802,7 @@ public class ItemImport
private void loadDublinCore(Context c, Item myitem, String filename) private void loadDublinCore(Context c, Item myitem, String filename)
throws SQLException, IOException, ParserConfigurationException, throws SQLException, IOException, ParserConfigurationException,
SAXException, TransformerException //, AuthorizeException SAXException, TransformerException, AuthorizeException
{ {
Document document = loadXML(filename); Document document = loadXML(filename);
@@ -831,11 +832,11 @@ public class ItemImport
for (int i = 0; i < dcNodes.getLength(); i++) for (int i = 0; i < dcNodes.getLength(); i++)
{ {
Node n = dcNodes.item(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(); String value = getStringValue(n); //n.getNodeValue();
// compensate for empty value getting read as "null", which won't display // 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); 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;
}
}
} }
/** /**