Merge remote-tracking branch 'dspace/main' into w2p-71780_support-csv-import-person-schema

Conflicts:
	dspace-api/src/test/java/org/dspace/app/bulkedit/MetadataImportIT.java
This commit is contained in:
Raf Ponsaerts
2020-11-19 09:44:19 +01:00
3 changed files with 49 additions and 6 deletions

View File

@@ -113,14 +113,14 @@ public class MetadataImport extends DSpaceRunnable<MetadataImportScriptConfigura
* *
* @see #populateRefAndRowMap(DSpaceCSVLine, UUID) * @see #populateRefAndRowMap(DSpaceCSVLine, UUID)
*/ */
protected static HashMap<UUID, String> entityTypeMap = new HashMap<>(); protected HashMap<UUID, String> entityTypeMap = new HashMap<>();
/** /**
* Map of UUIDs to their relations that are referenced within any import with their referers. * Map of UUIDs to their relations that are referenced within any import with their referers.
* *
* @see #populateEntityRelationMap(String, String, String) * @see #populateEntityRelationMap(String, String, String)
*/ */
protected static HashMap<String, HashMap<String, ArrayList<String>>> entityRelationMap = new HashMap<>(); protected HashMap<String, HashMap<String, ArrayList<String>>> entityRelationMap = new HashMap<>();
/** /**
@@ -1403,16 +1403,16 @@ public class MetadataImport extends DSpaceRunnable<MetadataImportScriptConfigura
//Populate the EntityRelationMap //Populate the EntityRelationMap
populateEntityRelationMap(uuid, key, originId.toString()); populateEntityRelationMap(uuid, key, originId.toString());
} }
} else {
newLine.add(key, null);
} }
} else { } else {
if (line.get(key).size() > 1) { if (line.get(key).size() > 0) {
for (String value : line.get(key)) { for (String value : line.get(key)) {
newLine.add(key, value); newLine.add(key, value);
} }
} else { } else {
if (line.get(key).size() > 0) { newLine.add(key, null);
newLine.add(key, line.get(key).get(0));
}
} }
} }
} }
@@ -1517,6 +1517,9 @@ public class MetadataImport extends DSpaceRunnable<MetadataImportScriptConfigura
throw new MetadataImportException("Error in CSV row " + rowCount + ":\n" + throw new MetadataImportException("Error in CSV row " + rowCount + ":\n" +
"Not a UUID or indirect entity reference: '" + reference + "'"); "Not a UUID or indirect entity reference: '" + reference + "'");
} }
}
if (reference.contains("::virtual::")) {
return UUID.fromString(StringUtils.substringBefore(reference, "::virtual::"));
} else if (!reference.startsWith("rowName:")) { // Not a rowName ref; so it's a metadata value reference } else if (!reference.startsWith("rowName:")) { // Not a rowName ref; so it's a metadata value reference
MetadataValueService metadataValueService = ContentServiceFactory.getInstance().getMetadataValueService(); MetadataValueService metadataValueService = ContentServiceFactory.getInstance().getMetadataValueService();
MetadataFieldService metadataFieldService = MetadataFieldService metadataFieldService =

View File

@@ -168,6 +168,26 @@ public class MetadataImportIT extends AbstractIntegrationTestWithDatabase {
context.restoreAuthSystemState(); context.restoreAuthSystemState();
} }
@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 { private Item findItemByName(String name) throws SQLException {
Item importedItem = null; Item importedItem = null;
List<Item> allItems = IteratorUtils.toList(itemService.findAll(context)); List<Item> allItems = IteratorUtils.toList(itemService.findAll(context));

View File

@@ -539,6 +539,26 @@ public class CSVMetadataImportReferenceIT extends AbstractIntegrationTestWithDat
assertRelationship(items[2], items[0], 1, "left", 0); assertRelationship(items[2], items[0], 1, "left", 0);
} }
@Test
public void testRelationToVirtualDataInReferences() throws Exception {
Item testItem = ItemBuilder.createItem(context, col1)
.withTitle("Person")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald")
.withPersonIdentifierLastName("Smith")
.withPersonIdentifierFirstName("Donald")
.withRelationshipType("Person")
.withIdentifierOther("testItemOne")
.build();
String[] csv = {"id,relationship.type,relation.isAuthorOfPublication,collection,dc.identifier.other,rowName",
"+,Publication," + testItem.getID() + "::virtual::4::600," + col1.getHandle() + ",0,1"};
Item[] items = runImport(csv);
assertRelationship(items[0], testItem, 1, "left", 0);
}
/** /**
* Test relationship validation with invalid relationship definition by incorrect typeName usage * Test relationship validation with invalid relationship definition by incorrect typeName usage
*/ */