diff --git a/dspace-api/src/main/java/org/dspace/content/enhancer/impl/RelatedEntityItemEnhancer.java b/dspace-api/src/main/java/org/dspace/content/enhancer/impl/RelatedEntityItemEnhancer.java index 284f9b8bff8..7a6f2927092 100644 --- a/dspace-api/src/main/java/org/dspace/content/enhancer/impl/RelatedEntityItemEnhancer.java +++ b/dspace-api/src/main/java/org/dspace/content/enhancer/impl/RelatedEntityItemEnhancer.java @@ -57,12 +57,12 @@ public class RelatedEntityItemEnhancer extends AbstractItemEnhancer { /** * the metadata used to navigate the relation, i.e. dc.contributor.author */ - private String sourceItemMetadataField; + private List sourceItemMetadataFields; /** * the metadata that is copied from the linked entity, i.e. person.identifier.orcid */ - private String relatedItemMetadataField; + private List relatedItemMetadataFields; @Override public boolean canEnhance(Context context, Item item) { @@ -166,16 +166,10 @@ private Map> getToBeVirtualMetadata(Context conte mvRelated.setValue(PLACEHOLDER_PARENT_METADATA_VALUE); tobeVirtualMetadata.add(mvRelated); } else { - List relatedItemMetadataValues = getMetadataValues(relatedItem, - relatedItemMetadataField); - if (relatedItemMetadataValues.isEmpty()) { - MetadataValueDTO mvRelated = new MetadataValueDTO(); - mvRelated.setSchema(VIRTUAL_METADATA_SCHEMA); - mvRelated.setElement(VIRTUAL_METADATA_ELEMENT); - mvRelated.setQualifier(getVirtualQualifier()); - mvRelated.setValue(PLACEHOLDER_PARENT_METADATA_VALUE); - tobeVirtualMetadata.add(mvRelated); - } else { + boolean foundAtLeastOneValue = false; + for (String relatedItemMetadataField : relatedItemMetadataFields) { + List relatedItemMetadataValues = getMetadataValues(relatedItem, + relatedItemMetadataField); for (MetadataValue relatedItemMetadataValue : relatedItemMetadataValues) { MetadataValueDTO mvRelated = new MetadataValueDTO(); mvRelated.setSchema(VIRTUAL_METADATA_SCHEMA); @@ -188,8 +182,17 @@ private Map> getToBeVirtualMetadata(Context conte mvRelated.setConfidence(Choices.CF_ACCEPTED); } tobeVirtualMetadata.add(mvRelated); + foundAtLeastOneValue = true; } } + if (!foundAtLeastOneValue) { + MetadataValueDTO mvRelated = new MetadataValueDTO(); + mvRelated.setSchema(VIRTUAL_METADATA_SCHEMA); + mvRelated.setElement(VIRTUAL_METADATA_ELEMENT); + mvRelated.setQualifier(getVirtualQualifier()); + mvRelated.setValue(PLACEHOLDER_PARENT_METADATA_VALUE); + tobeVirtualMetadata.add(mvRelated); + } } tobeVirtualMetadataMap.put(authority, tobeVirtualMetadata); } @@ -225,8 +228,10 @@ private List getObsoleteVirtualFields(Item item) { } private Set getVirtualSources(Item item) { - return itemService.getMetadataByMetadataString(item, sourceItemMetadataField).stream() - .filter(mv -> UUIDUtils.fromString(mv.getAuthority()) != null).map(mv -> mv.getAuthority()) + return sourceItemMetadataFields.stream() + .flatMap(field -> itemService.getMetadataByMetadataString(item, field).stream()) + .filter(mv -> UUIDUtils.fromString(mv.getAuthority()) != null) + .map(mv -> mv.getAuthority()) .collect(Collectors.toSet()); } @@ -276,7 +281,9 @@ private boolean performEnhancement(Context context, Item item) throws SQLExcepti Map> currentVirtualsMap = getCurrentVirtualsMap(item); Set virtualSources = getVirtualSources(item); for (String authority : virtualSources) { + boolean foundAtLeastOne = false; if (!currentVirtualsMap.containsKey(authority)) { + result = true; Item relatedItem = findRelatedEntityItem(context, authority); if (relatedItem == null) { addVirtualField(context, item, PLACEHOLDER_PARENT_METADATA_VALUE, null, null, Choices.CF_UNSET); @@ -284,20 +291,22 @@ private boolean performEnhancement(Context context, Item item) throws SQLExcepti continue; } - List relatedItemMetadataValues = getMetadataValues(relatedItem, - relatedItemMetadataField); - if (relatedItemMetadataValues.isEmpty()) { + for (String relatedItemMetadataField : relatedItemMetadataFields) { + List relatedItemMetadataValues = getMetadataValues(relatedItem, + relatedItemMetadataField); + for (MetadataValue relatedItemMetadataValue : relatedItemMetadataValues) { + foundAtLeastOne = true; + addVirtualField(context, item, relatedItemMetadataValue.getValue(), + relatedItemMetadataValue.getAuthority(), relatedItemMetadataValue.getLanguage(), + relatedItemMetadataValue.getConfidence()); + addVirtualSourceField(context, item, authority); + } + } + if (!foundAtLeastOne) { addVirtualField(context, item, PLACEHOLDER_PARENT_METADATA_VALUE, null, null, Choices.CF_UNSET); addVirtualSourceField(context, item, authority); continue; } - for (MetadataValue relatedItemMetadataValue : relatedItemMetadataValues) { - addVirtualField(context, item, relatedItemMetadataValue.getValue(), - relatedItemMetadataValue.getAuthority(), relatedItemMetadataValue.getLanguage(), - relatedItemMetadataValue.getConfidence()); - addVirtualSourceField(context, item, authority); - } - result = true; } } return result; @@ -340,12 +349,28 @@ public void setSourceEntityType(String sourceEntityType) { this.sourceEntityType = sourceEntityType; } + @Deprecated public void setSourceItemMetadataField(String sourceItemMetadataField) { - this.sourceItemMetadataField = sourceItemMetadataField; + LOGGER.warn( + "RelatedEntityItemEnhancer configured using the old single source item metadata field, " + + "please update the configuration to use the list"); + this.sourceItemMetadataFields = List.of(sourceItemMetadataField); } + @Deprecated public void setRelatedItemMetadataField(String relatedItemMetadataField) { - this.relatedItemMetadataField = relatedItemMetadataField; + LOGGER.warn( + "RelatedEntityItemEnhancer configured using the old single related item metadata field, " + + "please update the configuration to use the list"); + this.relatedItemMetadataFields = List.of(relatedItemMetadataField); + } + + public void setRelatedItemMetadataFields(List relatedItemMetadataFields) { + this.relatedItemMetadataFields = relatedItemMetadataFields; + } + + public void setSourceItemMetadataFields(List sourceItemMetadataFields) { + this.sourceItemMetadataFields = sourceItemMetadataFields; } } diff --git a/dspace-api/src/test/data/dspaceFolder/config/spring/api/extra-metadata-enhancers-for-test.xml b/dspace-api/src/test/data/dspaceFolder/config/spring/api/extra-metadata-enhancers-for-test.xml new file mode 100644 index 00000000000..0311d8a26aa --- /dev/null +++ b/dspace-api/src/test/data/dspaceFolder/config/spring/api/extra-metadata-enhancers-for-test.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + dc.contributor.author + dc.contributor.editor + + + + + person.affiliation.name + person.identifier.orcid + + + + + + diff --git a/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java b/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java index bef8ca45c09..4d4af87ddaa 100644 --- a/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java +++ b/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java @@ -221,7 +221,7 @@ public void testWorkbookBuildingFromItemDtos() throws Exception { with("dc.contributor.author", "White, Walter", authorId, 600), with("oairecerif.author.affiliation", PLACEHOLDER_PARENT_METADATA_VALUE), with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE), - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); + with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); assertThat(getItemBitstreamsByBundle(firstItem, "ORIGINAL"), contains( bitstreamWith("Bitstream 1", "First bitstream content"), @@ -242,8 +242,8 @@ public void testWorkbookBuildingFromItemDtos() throws Exception { with("oairecerif.author.affiliation", "Company", 1), with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE), with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE), - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE), - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE) + with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE), + with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE) )); assertThat(getItemBitstreamsByBundle(secondItem, "ORIGINAL"), contains( diff --git a/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java b/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java index aa440574c07..b2b34c1074f 100644 --- a/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java +++ b/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java @@ -19,15 +19,19 @@ import java.sql.SQLException; import java.util.List; +import java.util.stream.Collectors; +import org.apache.commons.codec.binary.StringUtils; import org.dspace.AbstractIntegrationTestWithDatabase; import org.dspace.authorize.AuthorizeException; import org.dspace.builder.CollectionBuilder; import org.dspace.builder.CommunityBuilder; import org.dspace.builder.ItemBuilder; +import org.dspace.builder.MetadataFieldBuilder; import org.dspace.builder.WorkspaceItemBuilder; import org.dspace.content.Collection; import org.dspace.content.Item; +import org.dspace.content.MetadataSchema; import org.dspace.content.MetadataValue; import org.dspace.content.WorkspaceItem; import org.dspace.content.factory.ContentServiceFactory; @@ -84,8 +88,8 @@ public void testSingleMetadataValueEnhancement() throws Exception { assertThat(metadataValues, hasSize(11)); assertThat(metadataValues, hasItem(with("cris.virtual.department", "4Science"))); assertThat(metadataValues, hasItem(with("cris.virtualsource.department", personId))); - assertThat(metadataValues, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); - assertThat(metadataValues, hasItem(with("cris.virtualsource.author-orcid", personId))); + assertThat(metadataValues, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); + assertThat(metadataValues, hasItem(with("cris.virtualsource.orcid", personId))); MetadataValue virtualField = getFirstMetadataValue(publication, "cris.virtual.department"); @@ -102,8 +106,8 @@ public void testSingleMetadataValueEnhancement() throws Exception { assertThat(metadataValues, hasItem(with("dc.contributor.author", "Walter White", personId, 600))); assertThat(metadataValues, hasItem(with("cris.virtual.department", "4Science"))); assertThat(metadataValues, hasItem(with("cris.virtualsource.department", personId))); - assertThat(metadataValues, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); - assertThat(metadataValues, hasItem(with("cris.virtualsource.author-orcid", personId))); + assertThat(metadataValues, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); + assertThat(metadataValues, hasItem(with("cris.virtualsource.orcid", personId))); assertThat(virtualField, equalTo(getFirstMetadataValue(publication, "cris.virtual.department"))); assertThat(virtualSourceField, equalTo(getFirstMetadataValue(publication, "cris.virtualsource.department"))); @@ -135,7 +139,7 @@ public void testManyMetadataValuesEnhancement() throws Exception { .withAuthor("Red Smith") .withAuthor("Walter White", person1.getID().toString()) .withAuthor("John Smith", person2.getID().toString()) - .withAuthor("Jesse Pinkman", person3.getID().toString()) + .withEditor("Jesse Pinkman", person3.getID().toString()) .build(); context.restoreAuthSystemState(); @@ -146,7 +150,7 @@ public void testManyMetadataValuesEnhancement() throws Exception { assertThat(values, hasItem(with("dc.contributor.author", "Red Smith"))); assertThat(values, hasItem(with("dc.contributor.author", "Walter White", person1.getID().toString(), 1, 600))); assertThat(values, hasItem(with("dc.contributor.author", "John Smith", person2.getID().toString(), 2, 600))); - assertThat(values, hasItem(with("dc.contributor.author", "Jesse Pinkman", person3.getID().toString(), 3, 600))); + assertThat(values, hasItem(with("dc.contributor.editor", "Jesse Pinkman", person3.getID().toString(), 0, 600))); // virtual source and virtual metadata are not required to respect the order of the source metadata assertThat(values, hasItem(withNoPlace("cris.virtualsource.department", person1.getID().toString()))); assertThat(values, hasItem(withNoPlace("cris.virtualsource.department", person2.getID().toString()))); @@ -154,17 +158,17 @@ public void testManyMetadataValuesEnhancement() throws Exception { assertThat(values, hasItem(withNoPlace("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE))); assertThat(values, hasItem(withNoPlace("cris.virtual.department", "4Science"))); assertThat(values, hasItem(withNoPlace("cris.virtual.department", "University of Rome"))); - assertThat(values, hasItem(withNoPlace("cris.virtualsource.author-orcid", person1.getID().toString()))); - assertThat(values, hasItem(withNoPlace("cris.virtualsource.author-orcid", person2.getID().toString()))); - assertThat(values, hasItem(withNoPlace("cris.virtualsource.author-orcid", person3.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person1.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person2.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person3.getID().toString()))); // we can check with the position as all the values are expected to be placeholder - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 2))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 2))); assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(3)); assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(3)); - assertThat(getMetadataValues(publication, "cris.virtual.author-orcid"), hasSize(3)); - assertThat(getMetadataValues(publication, "cris.virtualsource.author-orcid"), hasSize(3)); + assertThat(getMetadataValues(publication, "cris.virtual.orcid"), hasSize(3)); + assertThat(getMetadataValues(publication, "cris.virtualsource.orcid"), hasSize(3)); } @@ -256,15 +260,15 @@ public void testEnhancementWithMetadataRemoval() throws Exception { assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(3)); assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(3)); - assertThat(values, hasItem(withNoPlace("cris.virtualsource.author-orcid", person1.getID().toString()))); - assertThat(values, hasItem(withNoPlace("cris.virtualsource.author-orcid", person2.getID().toString()))); - assertThat(values, hasItem(withNoPlace("cris.virtualsource.author-orcid", person3.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person1.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person2.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person3.getID().toString()))); // we can check with the position as all the values are expected to be placeholder - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 2))); - assertThat(getMetadataValues(publication, "cris.virtual.author-orcid"), hasSize(3)); - assertThat(getMetadataValues(publication, "cris.virtualsource.author-orcid"), hasSize(3)); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 2))); + assertThat(getMetadataValues(publication, "cris.virtual.orcid"), hasSize(3)); + assertThat(getMetadataValues(publication, "cris.virtualsource.orcid"), hasSize(3)); MetadataValue authorToRemove = getMetadataValues(publication, "dc.contributor.author").get(1); @@ -284,15 +288,15 @@ public void testEnhancementWithMetadataRemoval() throws Exception { assertThat(values, hasItem(withNoPlace("cris.virtualsource.department", person3.getID().toString()))); assertThat(values, hasItem(withNoPlace("cris.virtual.department", "4Science"))); assertThat(values, hasItem(withNoPlace("cris.virtual.department", "University of Rome"))); - assertThat(values, hasItem(withNoPlace("cris.virtualsource.author-orcid", person1.getID().toString()))); - assertThat(values, hasItem(withNoPlace("cris.virtualsource.author-orcid", person3.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person1.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person3.getID().toString()))); // we can check with the position as all the values are expected to be placeholder - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1))); assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(2)); assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(2)); - assertThat(getMetadataValues(publication, "cris.virtual.author-orcid"), hasSize(2)); - assertThat(getMetadataValues(publication, "cris.virtualsource.author-orcid"), hasSize(2)); + assertThat(getMetadataValues(publication, "cris.virtual.orcid"), hasSize(2)); + assertThat(getMetadataValues(publication, "cris.virtualsource.orcid"), hasSize(2)); } @@ -354,11 +358,11 @@ public void testEnhancementAfterItemUpdate() throws Exception { with("dc.contributor.author", "Walter White", personId, 2, 600), with("dc.contributor.author", "Gus Fring", 3))); - assertThat(getMetadataValues(publication, "cris.virtual.author-orcid"), contains( - with("cris.virtual.author-orcid", "0000-0000-1111-2222"))); + assertThat(getMetadataValues(publication, "cris.virtual.orcid"), contains( + with("cris.virtual.orcid", "0000-0000-1111-2222"))); - assertThat(getMetadataValues(publication, "cris.virtualsource.author-orcid"), contains( - with("cris.virtualsource.author-orcid", personId))); + assertThat(getMetadataValues(publication, "cris.virtualsource.orcid"), contains( + with("cris.virtualsource.orcid", personId))); context.turnOffAuthorisationSystem(); itemService.addMetadata(context, publication, "dc", "title", "alternative", null, "Other name"); @@ -372,12 +376,89 @@ public void testEnhancementAfterItemUpdate() throws Exception { with("dc.contributor.author", "Walter White", personId, 2, 600), with("dc.contributor.author", "Gus Fring", 3))); - assertThat(getMetadataValues(publication, "cris.virtual.author-orcid"), contains( - with("cris.virtual.author-orcid", "0000-0000-1111-2222"))); + assertThat(getMetadataValues(publication, "cris.virtual.orcid"), contains( + with("cris.virtual.orcid", "0000-0000-1111-2222"))); + + assertThat(getMetadataValues(publication, "cris.virtualsource.orcid"), contains( + with("cris.virtualsource.orcid", personId))); + + } + + @Test + public void testMultipleRelatedItemValuesEnhancement() throws Exception { + + context.turnOffAuthorisationSystem(); + MetadataSchema schema = ContentServiceFactory.getInstance() + .getMetadataSchemaService().find(context, "cris"); + MetadataFieldBuilder.createMetadataField(context, schema, "virtual", "testmultival", null); + MetadataFieldBuilder.createMetadataField(context, schema, "virtualsource", "testmultival", null); + + Item person1 = ItemBuilder.createItem(context, collection) + .withTitle("Walter White") + .withPersonMainAffiliation("4Science") + .withPersonMainAffiliation("DSpace") + .withOrcidIdentifier("orcid1") + .build(); + + Item person2 = ItemBuilder.createItem(context, collection) + .withTitle("John Smith") + .build(); + + Item person3 = ItemBuilder.createItem(context, collection) + .withTitle("Jesse Pinkman") + .withPersonMainAffiliation("University of Rome") + .build(); + + Item testEntity = ItemBuilder.createItem(context, collection) + .withTitle("Test publication") + // let's use our custom entity for test purpose, see extra-metadata-enhancers-for-test.xml + .withEntityType("TestEntity") + .withAuthor("Red Smith") + .withAuthor("Walter White", person1.getID().toString()) + .withAuthor("John Smith", person2.getID().toString()) + .withEditor("Jesse Pinkman", person3.getID().toString()) + .build(); + + context.restoreAuthSystemState(); + testEntity = commitAndReload(testEntity); - assertThat(getMetadataValues(publication, "cris.virtualsource.author-orcid"), contains( - with("cris.virtualsource.author-orcid", personId))); + List values = testEntity.getMetadata(); + assertThat(values, hasItem(with("dc.contributor.author", "Red Smith"))); + assertThat(values, hasItem(with("dc.contributor.author", "Walter White", person1.getID().toString(), 1, 600))); + assertThat(values, hasItem(with("dc.contributor.author", "John Smith", person2.getID().toString(), 2, 600))); + assertThat(values, hasItem(with("dc.contributor.editor", "Jesse Pinkman", person3.getID().toString(), 0, 600))); + // virtual source and virtual metadata are not required to respect the order of the source metadata + List posPerson1 = getPlacesAsVirtualSource(person1, testEntity, "cris.virtualsource.testmultival"); + List posPerson2 = getPlacesAsVirtualSource(person2, testEntity, "cris.virtualsource.testmultival"); + List posPerson3 = getPlacesAsVirtualSource(person3, testEntity, "cris.virtualsource.testmultival"); + assertThat(values, + hasItem(with("cris.virtualsource.testmultival", person1.getID().toString(), posPerson1.get(0)))); + assertThat(values, hasItem(with("cris.virtual.testmultival", "4Science", posPerson1.get(0)))); + assertThat(values, + hasItem(with("cris.virtualsource.testmultival", person1.getID().toString(), posPerson1.get(1)))); + assertThat(values, hasItem(with("cris.virtual.testmultival", "DSpace", posPerson1.get(1)))); + assertThat(values, + hasItem(with("cris.virtualsource.testmultival", person1.getID().toString(), posPerson1.get(2)))); + assertThat(values, hasItem(with("cris.virtual.testmultival", "orcid1", posPerson1.get(2)))); + + assertThat(values, + hasItem(with("cris.virtualsource.testmultival", person2.getID().toString(), posPerson2.get(0)))); + assertThat(values, + hasItem(with("cris.virtual.testmultival", PLACEHOLDER_PARENT_METADATA_VALUE, posPerson2.get(0)))); + + assertThat(values, + hasItem(with("cris.virtualsource.testmultival", person3.getID().toString(), posPerson3.get(0)))); + assertThat(values, hasItem(with("cris.virtual.testmultival", "University of Rome", posPerson3.get(0)))); + + assertThat(getMetadataValues(testEntity, "cris.virtualsource.testmultival"), hasSize(5)); + assertThat(getMetadataValues(testEntity, "cris.virtual.testmultival"), hasSize(5)); + + } + private List getPlacesAsVirtualSource(Item person1, Item publication, String metadata) { + return getMetadataValues(publication, metadata).stream() + .filter(mv -> StringUtils.equals(mv.getValue(), person1.getID().toString())).map(mv -> mv.getPlace()) + .collect(Collectors.toList()); } private MetadataValue getFirstMetadataValue(Item item, String metadataField) { diff --git a/dspace-api/src/test/java/org/dspace/content/enhancer/script/ItemEnhancerScriptIT.java b/dspace-api/src/test/java/org/dspace/content/enhancer/script/ItemEnhancerScriptIT.java index f8b2b0d2d77..6d67c67a10b 100644 --- a/dspace-api/src/test/java/org/dspace/content/enhancer/script/ItemEnhancerScriptIT.java +++ b/dspace-api/src/test/java/org/dspace/content/enhancer/script/ItemEnhancerScriptIT.java @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.UUID; import org.dspace.AbstractIntegrationTestWithDatabase; import org.dspace.app.launcher.ScriptLauncher; @@ -39,6 +40,7 @@ import org.dspace.content.WorkspaceItem; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.ItemService; +import org.dspace.core.CrisConstants; import org.dspace.core.ReloadableEntity; import org.dspace.event.factory.EventServiceFactory; import org.dspace.event.service.EventService; @@ -138,24 +140,38 @@ public void testItemsEnhancement() throws Exception { .withAuthor("Jesse Pinkman", secondAuthorId) .build(); - WorkspaceItem thirdPublication = WorkspaceItemBuilder.createWorkspaceItem(context, collection) - .withTitle("Test publication 3") + final String randomUUID = UUID.randomUUID().toString(); + Item thirdPublication = ItemBuilder.createItem(context, collection) + .withTitle("Test publication 3") + .withEntityType("Publication") + .withAuthor("Walter White", firstAuthorId) + .withAuthor("Jesse Pinkman", secondAuthorId) + // same author multiple time + .withAuthor("Walter White", firstAuthorId) + // an author is also an editor + .withEditor("Jesse Pinkman", secondAuthorId) + .withEditor("Editor WithExternaAuthority", "external-authority") + .withEditor("Editor WithExternaUUIDAuthority", randomUUID) + .build(); + + WorkspaceItem wsPublication = WorkspaceItemBuilder.createWorkspaceItem(context, collection) + .withTitle("Test workspace publication") .withEntityType("Publication") - .withAuthor("Jesse Pinkman", secondAuthorId) + .withEditor("Jesse Pinkman", secondAuthorId) .build(); context.commit(); firstPublication = reload(firstPublication); secondPublication = reload(secondPublication); - thirdPublication = reload(thirdPublication); + wsPublication = reload(wsPublication); assertThat(getMetadataValues(firstPublication, "cris.virtual.department"), empty()); assertThat(getMetadataValues(firstPublication, "cris.virtualsource.department"), empty()); assertThat(getMetadataValues(secondPublication, "cris.virtual.department"), empty()); assertThat(getMetadataValues(secondPublication, "cris.virtualsource.department"), empty()); - assertThat(getMetadataValues(thirdPublication, "cris.virtual.department"), empty()); - assertThat(getMetadataValues(thirdPublication, "cris.virtualsource.department"), empty()); + assertThat(getMetadataValues(wsPublication, "cris.virtual.department"), empty()); + assertThat(getMetadataValues(wsPublication, "cris.virtualsource.department"), empty()); TestDSpaceRunnableHandler runnableHandler = runScript(false); @@ -164,15 +180,16 @@ public void testItemsEnhancement() throws Exception { firstPublication = reload(firstPublication); secondPublication = reload(secondPublication); + thirdPublication = reload(thirdPublication); + wsPublication = reload(wsPublication); assertThat(getMetadataValues(firstPublication, "cris.virtual.department"), hasSize(1)); assertThat(getMetadataValues(firstPublication, "cris.virtualsource.department"), hasSize(1)); + assertThat(firstPublication.getMetadata(), hasItem(with("cris.virtual.department", "4Science"))); + assertThat(firstPublication.getMetadata(), hasItem(with("cris.virtualsource.department", firstAuthorId))); assertThat(getMetadataValues(secondPublication, "cris.virtual.department"), hasSize(2)); assertThat(getMetadataValues(secondPublication, "cris.virtualsource.department"), hasSize(2)); - - assertThat(firstPublication.getMetadata(), hasItem(with("cris.virtual.department", "4Science"))); - assertThat(firstPublication.getMetadata(), hasItem(with("cris.virtualsource.department", firstAuthorId))); assertThat(getMetadataValues(secondPublication, "cris.virtual.department"), containsInAnyOrder( withNoPlace("cris.virtual.department", "4Science"), @@ -181,8 +198,22 @@ public void testItemsEnhancement() throws Exception { containsInAnyOrder( withNoPlace("cris.virtualsource.department", firstAuthorId), withNoPlace("cris.virtualsource.department", secondAuthorId))); - assertThat(getMetadataValues(thirdPublication, "cris.virtual.department"), empty()); - assertThat(getMetadataValues(thirdPublication, "cris.virtualsource.department"), empty()); + + assertThat(getMetadataValues(thirdPublication, "cris.virtual.department"), hasSize(3)); + assertThat(getMetadataValues(thirdPublication, "cris.virtualsource.department"), hasSize(3)); + assertThat(getMetadataValues(thirdPublication, "cris.virtual.department"), + containsInAnyOrder( + withNoPlace("cris.virtual.department", "4Science"), + withNoPlace("cris.virtual.department", CrisConstants.PLACEHOLDER_PARENT_METADATA_VALUE), + withNoPlace("cris.virtual.department", "Company"))); + assertThat(getMetadataValues(thirdPublication, "cris.virtualsource.department"), + containsInAnyOrder( + withNoPlace("cris.virtualsource.department", randomUUID), + withNoPlace("cris.virtualsource.department", firstAuthorId), + withNoPlace("cris.virtualsource.department", secondAuthorId))); + + assertThat(getMetadataValues(wsPublication, "cris.virtual.department"), empty()); + assertThat(getMetadataValues(wsPublication, "cris.virtualsource.department"), empty()); } @@ -281,7 +312,7 @@ public void testItemEnhancementWithForce() throws Exception { Item publication = ItemBuilder.createItem(context, collection) .withTitle("Test publication 2 ") .withEntityType("Publication") - .withAuthor("Walter White", firstAuthorId) + .withEditor("Walter White", firstAuthorId) .withAuthor("Jesse Pinkman", secondAuthorId) .build(); @@ -310,7 +341,7 @@ public void testItemEnhancementWithForce() throws Exception { context.turnOffAuthorisationSystem(); - MetadataValue authorToRemove = getMetadataValues(publication, "dc.contributor.author").get(1); + MetadataValue authorToRemove = getMetadataValues(publication, "dc.contributor.author").get(0); itemService.removeMetadataValues(context, publication, List.of(authorToRemove)); replaceMetadata(firstAuthor, "person", "affiliation", "name", "University"); @@ -413,7 +444,7 @@ public void testItemEnhancementSourceWithoutAuthority() throws Exception { .withTitle("Test publication 2 ") .withEntityType("Publication") .withAuthor("Jesse Pinkman") - .withAuthor("Jesse Smith", secondAuthorId) + .withEditor("Jesse Smith", secondAuthorId) .build(); context.commit(); diff --git a/dspace-api/src/test/java/org/dspace/harvest/OAIHarvesterIT.java b/dspace-api/src/test/java/org/dspace/harvest/OAIHarvesterIT.java index b305ccc1806..9c402b4e3a0 100644 --- a/dspace-api/src/test/java/org/dspace/harvest/OAIHarvesterIT.java +++ b/dspace-api/src/test/java/org/dspace/harvest/OAIHarvesterIT.java @@ -781,7 +781,7 @@ public void testRunHarvestWithPublicationAndThenPerson() throws Exception { assertThat(values, hasItems(with("dc.identifier.doi", "10.1007/978-3-642-35233-1_18"))); assertThat(values, hasItems(with("oairecerif.author.affiliation", PLACEHOLDER_PARENT_METADATA_VALUE))); assertThat(values, hasItems(with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE))); - assertThat(values, hasItems(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); + assertThat(values, hasItems(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); assertThat(values, hasItems(with("cris.sourceId", "test-harvest::3"))); assertThat(values, hasItems(with("dspace.entity.type", "Publication"))); @@ -889,8 +889,8 @@ public void testRunHarvestWithPersonAndThenPublication() throws Exception { assertThat(values, hasItems(with("dspace.entity.type", "Publication"))); assertThat(values, hasItems(with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE))); assertThat(values, hasItems(with("cris.virtualsource.department", UUIDUtils.toString(person.getID())))); - assertThat(values, hasItems(with("cris.virtual.author-orcid", "0000-0002-9079-5932"))); - assertThat(values, hasItems(with("cris.virtualsource.author-orcid", + assertThat(values, hasItems(with("cris.virtual.orcid", "0000-0002-9079-5932"))); + assertThat(values, hasItems(with("cris.virtualsource.orcid", UUIDUtils.toString(person.getID())))); MetadataValue author = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY).get(0); diff --git a/dspace/config/registries/cris-types.xml b/dspace/config/registries/cris-types.xml index 7f0f8d7ec63..90597ddffbc 100644 --- a/dspace/config/registries/cris-types.xml +++ b/dspace/config/registries/cris-types.xml @@ -152,14 +152,7 @@ cris virtual - author-orcid - - - - - cris - virtual - editor-orcid + orcid @@ -173,14 +166,7 @@ cris virtualsource - author-orcid - - - - - cris - virtualsource - editor-orcid + orcid diff --git a/dspace/config/spring/api/metadata-enhancers.xml b/dspace/config/spring/api/metadata-enhancers.xml index e36727959c2..eb87c320269 100644 --- a/dspace/config/spring/api/metadata-enhancers.xml +++ b/dspace/config/spring/api/metadata-enhancers.xml @@ -25,38 +25,50 @@ - + + + dc.contributor.author + dc.contributor.editor + + - - - - + + + + dc.contributor.author + dc.contributor.editor + + + + - + + + dc.contributor.author + dc.contributor.editor + + - + - + + + dc.contributor.author + dc.contributor.editor + + - + - - - - - - - -