Skip to content

Commit

Permalink
Merged in DSC-1561_itemenhancer_noplaceholder (pull request DSpace#1819)
Browse files Browse the repository at this point in the history
DSC-1561 itemenhancer noplaceholder
  • Loading branch information
abollini committed Mar 3, 2024
2 parents 4a71402 + f6b4127 commit 59589a7
Show file tree
Hide file tree
Showing 9 changed files with 499 additions and 381 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The contents of this file are subject to the license and copyright
detailed in the LICENSE and NOTICE files at the root of the source
tree and available online at
http://www.dspace.org/license/
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
>

<context:annotation-config />

<bean class="org.dspace.content.enhancer.impl.RelatedEntityItemEnhancer" >
<property name="sourceEntityType" value="TestEntity" />
<property name="sourceItemMetadataFields">
<list>
<value>dc.contributor.author</value>
<value>dc.contributor.editor</value>
</list>
</property>
<property name="relatedItemMetadataFields">
<list>
<value>person.affiliation.name</value>
<value>person.identifier.orcid</value>
</list>
</property>
<property name="virtualQualifier" value="testmultival" />
</bean>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ protected boolean matchesSafely(MetadataValue metadataValue) {
Objects.equals(metadataValue.getMetadataField().toString('.'), field) &&
Objects.equals(metadataValue.getLanguage(), language) &&
Objects.equals(metadataValue.getAuthority(), authority) &&
Objects.equals(metadataValue.getPlace(), place) &&
(Objects.isNull(place)
|| Objects.equals(metadataValue.getPlace(), place)) &&
Objects.equals(metadataValue.getConfidence(), confidence) &&
Objects.equals(metadataValue.getSecurityLevel(), securityLevel);
}
Expand All @@ -91,6 +92,10 @@ public static MetadataValueMatcher with(String field, String value) {
return with(field, value, null, null, 0, -1);
}

public static MetadataValueMatcher withNoPlace(String field, String value) {
return with(field, value, null, null, null, -1);
}

public static MetadataValueMatcher withSecurity(String field, String value, Integer securityLevel) {
return with(field, value, null, null, 0, -1, securityLevel);
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
package org.dspace.content.enhancer.script;

import static org.dspace.app.matcher.MetadataValueMatcher.with;
import static org.dspace.app.matcher.MetadataValueMatcher.withNoPlace;
import static org.dspace.content.Item.ANY;
import static org.dspace.content.enhancer.consumer.ItemEnhancerConsumer.ITEMENHANCER_ENABLED;
import static org.dspace.core.CrisConstants.PLACEHOLDER_PARENT_METADATA_VALUE;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
Expand All @@ -22,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;
Expand All @@ -37,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;
Expand Down Expand Up @@ -136,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);

Expand All @@ -162,22 +180,40 @@ 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(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(secondPublication.getMetadata(), hasItem(with("cris.virtual.department", "4Science")));
assertThat(secondPublication.getMetadata(), hasItem(with("cris.virtualsource.department", firstAuthorId)));
assertThat(secondPublication.getMetadata(), hasItem(with("cris.virtual.department", "Company", 1)));
assertThat(secondPublication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId, 1)));

assertThat(getMetadataValues(thirdPublication, "cris.virtual.department"), empty());
assertThat(getMetadataValues(thirdPublication, "cris.virtualsource.department"), empty());
assertThat(getMetadataValues(secondPublication, "cris.virtual.department"), hasSize(2));
assertThat(getMetadataValues(secondPublication, "cris.virtualsource.department"), hasSize(2));
assertThat(getMetadataValues(secondPublication, "cris.virtual.department"),
containsInAnyOrder(
withNoPlace("cris.virtual.department", "4Science"),
withNoPlace("cris.virtual.department", "Company")));
assertThat(getMetadataValues(secondPublication, "cris.virtualsource.department"),
containsInAnyOrder(
withNoPlace("cris.virtualsource.department", firstAuthorId),
withNoPlace("cris.virtualsource.department", secondAuthorId)));

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());

}

Expand Down Expand Up @@ -223,10 +259,13 @@ public void testItemEnhancementWithoutForce() throws Exception {
assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(2));
assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(2));

assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "4Science")));
assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", firstAuthorId)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "Company", 1)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId, 1)));
assertThat(getMetadataValues(publication, "cris.virtual.department"), containsInAnyOrder(
withNoPlace("cris.virtual.department", "4Science"),
withNoPlace("cris.virtual.department", "Company")));

assertThat(getMetadataValues(publication, "cris.virtualsource.department"), containsInAnyOrder(
withNoPlace("cris.virtualsource.department", firstAuthorId),
withNoPlace("cris.virtualsource.department", secondAuthorId)));

context.turnOffAuthorisationSystem();

Expand Down Expand Up @@ -273,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();

Expand All @@ -293,14 +332,16 @@ public void testItemEnhancementWithForce() throws Exception {
assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(2));
assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(2));

assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "4Science")));
assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", firstAuthorId)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "Company", 1)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId, 1)));
assertThat(getMetadataValues(publication, "cris.virtual.department"), containsInAnyOrder(
withNoPlace("cris.virtual.department", "4Science"),
withNoPlace("cris.virtual.department", "Company")));
assertThat(getMetadataValues(publication, "cris.virtualsource.department"), containsInAnyOrder(
withNoPlace("cris.virtualsource.department", firstAuthorId),
withNoPlace("cris.virtualsource.department", secondAuthorId)));

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");
Expand Down Expand Up @@ -375,17 +416,16 @@ public void testItemEnhancementMetadataPositions() throws Exception {
assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(4));
assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(4));

assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department",
PLACEHOLDER_PARENT_METADATA_VALUE, 0)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", firstAuthorId,0)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "4Science", 1)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId,1)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "Company", 2)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", thirdAuthorId, 2)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department",
PLACEHOLDER_PARENT_METADATA_VALUE, 3)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", fourthAuthorId,3)));

assertThat(getMetadataValues(publication, "cris.virtual.department"), containsInAnyOrder(
withNoPlace("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE),
withNoPlace("cris.virtual.department", "4Science"),
withNoPlace("cris.virtual.department", "Company"),
withNoPlace("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE)));
assertThat(getMetadataValues(publication, "cris.virtualsource.department"), containsInAnyOrder(
withNoPlace("cris.virtualsource.department", firstAuthorId),
withNoPlace("cris.virtualsource.department", secondAuthorId),
withNoPlace("cris.virtualsource.department", thirdAuthorId),
withNoPlace("cris.virtualsource.department", fourthAuthorId)));
}

@Test
Expand All @@ -404,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();
Expand All @@ -420,15 +460,11 @@ public void testItemEnhancementSourceWithoutAuthority() throws Exception {

publication = reload(publication);

assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(2));
assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(2));
assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(1));
assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(1));

assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department",
PLACEHOLDER_PARENT_METADATA_VALUE, 0)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department",
PLACEHOLDER_PARENT_METADATA_VALUE,0)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "4Science", 1)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId,1)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "4Science", 0)));
assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId,0)));

}

Expand Down
Loading

0 comments on commit 59589a7

Please sign in to comment.