Merge pull request #3037 from atmire/csv-import-empty-value-support

Supporting CSV import removing values
This commit is contained in:
Tim Donohue
2020-11-18 14:32:08 -06:00
committed by GitHub
2 changed files with 24 additions and 4 deletions

View File

@@ -1403,16 +1403,16 @@ public class MetadataImport extends DSpaceRunnable<MetadataImportScriptConfigura
//Populate the EntityRelationMap
populateEntityRelationMap(uuid, key, originId.toString());
}
} else {
newLine.add(key, null);
}
} else {
if (line.get(key).size() > 1) {
if (line.get(key).size() > 0) {
for (String value : line.get(key)) {
newLine.add(key, value);
}
} else {
if (line.get(key).size() > 0) {
newLine.add(key, line.get(key).get(0));
}
newLine.add(key, null);
}
}
}

View File

@@ -152,6 +152,26 @@ public class MetadataImportIT extends AbstractIntegrationTestWithDatabase {
}
@Test
public void metadataImportRemovingValueTest() throws Exception {
context.turnOffAuthorisationSystem();
Item item = ItemBuilder.createItem(context, collection).withAuthor("TestAuthorToRemove").withTitle("title")
.build();
context.restoreAuthSystemState();
assertTrue(
StringUtils.equals(
itemService.getMetadata(item, "dc", "contributor", "author", Item.ANY).get(0).getValue(),
"TestAuthorToRemove"));
String[] csv = {"id,collection,dc.title,dc.contributor.author[*]",
item.getID().toString() + "," + collection.getHandle() + "," + item.getName() + ","};
performImportScript(csv);
item = findItemByName("title");
assertEquals(itemService.getMetadata(item, "dc", "contributor", "author", Item.ANY).size(), 0);
}
private Item findItemByName(String name) throws SQLException {
Item importedItem = null;
List<Item> allItems = IteratorUtils.toList(itemService.findAll(context));