mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Fix bug in MetadataImport where it could call addMetadata() with empty values. Minor refactors to MetadataImportIT to make findItemByName more efficient.
This commit is contained in:
@@ -825,8 +825,10 @@ public class MetadataImport extends DSpaceRunnable<MetadataImportScriptConfigura
|
||||
addRelationships(c, item, element, values);
|
||||
} else {
|
||||
itemService.clearMetadata(c, item, schema, element, qualifier, language);
|
||||
itemService.addMetadata(c, item, schema, element, qualifier,
|
||||
language, values, authorities, confidences);
|
||||
if (!values.isEmpty()) {
|
||||
itemService.addMetadata(c, item, schema, element, qualifier,
|
||||
language, values, authorities, confidences);
|
||||
}
|
||||
itemService.update(c, item);
|
||||
}
|
||||
}
|
||||
@@ -1121,8 +1123,8 @@ public class MetadataImport extends DSpaceRunnable<MetadataImportScriptConfigura
|
||||
.getAuthoritySeparator() + dcv.getConfidence();
|
||||
}
|
||||
|
||||
// Add it
|
||||
if ((value != null) && (!"".equals(value))) {
|
||||
// Add it, if value is not blank
|
||||
if (value != null && StringUtils.isNotBlank(value)) {
|
||||
changes.registerAdd(dcv);
|
||||
}
|
||||
}
|
||||
|
@@ -9,12 +9,12 @@ package org.dspace.app.bulkedit;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static junit.framework.TestCase.fail;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.cli.ParseException;
|
||||
@@ -218,9 +218,10 @@ public class MetadataImportIT extends AbstractIntegrationTestWithDatabase {
|
||||
|
||||
@Test
|
||||
public void metadataImportRemovingValueTest() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
Item item = ItemBuilder.createItem(context,personCollection).withAuthor("TestAuthorToRemove").withTitle("title")
|
||||
String itemTitle = "Testing removing author";
|
||||
Item item = ItemBuilder.createItem(context,personCollection).withAuthor("TestAuthorToRemove")
|
||||
.withTitle(itemTitle)
|
||||
.build();
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
@@ -232,19 +233,21 @@ public class MetadataImportIT extends AbstractIntegrationTestWithDatabase {
|
||||
String[] csv = {"id,collection,dc.title,dc.contributor.author[*]",
|
||||
item.getID().toString() + "," + personCollection.getHandle() + "," + item.getName() + ","};
|
||||
performImportScript(csv);
|
||||
item = findItemByName("title");
|
||||
item = findItemByName(itemTitle);
|
||||
assertEquals(0, itemService.getMetadata(item, "dc", "contributor", "author", Item.ANY).size());
|
||||
}
|
||||
|
||||
private Item findItemByName(String name) throws SQLException {
|
||||
Item importedItem = null;
|
||||
List<Item> allItems = IteratorUtils.toList(itemService.findAll(context));
|
||||
for (Item item : allItems) {
|
||||
if (item.getName().equals(name)) {
|
||||
importedItem = item;
|
||||
}
|
||||
private Item findItemByName(String name) throws Exception {
|
||||
List<Item> items =
|
||||
IteratorUtils.toList(itemService.findByMetadataField(context, "dc", "title", null, name));
|
||||
|
||||
if (items != null && !items.isEmpty()) {
|
||||
// Just return first matching Item. Tests should ensure name/title is unique.
|
||||
return items.get(0);
|
||||
} else {
|
||||
fail("Could not find expected Item with dc.title = '" + name + "'");
|
||||
return null;
|
||||
}
|
||||
return importedItem;
|
||||
}
|
||||
|
||||
public void performImportScript(String[] csv) throws Exception {
|
||||
|
Reference in New Issue
Block a user