taskid 77244 ItemMetadata caching bugfixes

This commit is contained in:
Samuel
2021-02-25 18:45:38 +01:00
parent f5043f15c3
commit 3fe194ae09
3 changed files with 483 additions and 23 deletions

View File

@@ -187,13 +187,38 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa
public void testDeleteAuthorRelationshipCopyToLeftItem() throws Exception { public void testDeleteAuthorRelationshipCopyToLeftItem() throws Exception {
initPublicationAuthor(); initPublicationAuthor();
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
//verify the dc.contributor.author virtual metadata
List<MetadataValue> authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY);
assertThat(authorList.size(), equalTo(1));
//verify the dc.contributor.author actual metadata
List<MetadataValue> plainMetadataAuthorList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null &&
metadataValue.getMetadataField().getQualifier().equals("author"))
.collect(Collectors.toList());
assertThat(plainMetadataAuthorList.size(), equalTo(0));
//verify there's no relation.isAuthorOfPublication actual metadata
List<MetadataValue> plainRelationshipMetadataList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication"))
.collect(Collectors.toList());
assertThat(plainRelationshipMetadataList.size(), equalTo(0));
//delete the relationship, copying the virtual metadata to actual metadata on the leftItem //delete the relationship, copying the virtual metadata to actual metadata on the leftItem
//leftItem is the publication //leftItem is the publication
relationshipService.delete(context, relationship, true, false); relationshipService.delete(context, relationship, true, false);
context.restoreAuthSystemState(); context.restoreAuthSystemState();
//verify the dc.contributor.author actual metadata //verify the dc.contributor.author actual metadata
List<MetadataValue> authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); plainMetadataAuthorList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null &&
metadataValue.getMetadataField().getQualifier().equals("author"))
.collect(Collectors.toList());
assertThat(plainMetadataAuthorList.size(), equalTo(1));
//verify the dc.contributor.author actual metadata
authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY);
assertThat(authorList.size(), equalTo(1)); assertThat(authorList.size(), equalTo(1));
assertThat(authorList.get(0).getValue(), equalTo("familyName, firstName")); assertThat(authorList.get(0).getValue(), equalTo("familyName, firstName"));
assertThat(authorList.get(0).getMetadataField().getMetadataSchema().getName(), equalTo("dc")); assertThat(authorList.get(0).getMetadataField().getMetadataSchema().getName(), equalTo("dc"));
@@ -201,10 +226,15 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa
assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author")); assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author"));
assertNull(authorList.get(0).getAuthority()); assertNull(authorList.get(0).getAuthority());
//verify there's no relation.isAuthorOfPublication actual metadata //verify there's relation.isAuthorOfPublication actual metadata
plainRelationshipMetadataList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication"))
.collect(Collectors.toList());
assertThat(plainRelationshipMetadataList.size(), equalTo(1));
//verify there's relation.isAuthorOfPublication actual metadata
List<MetadataValue> relationshipMetadataList = itemService List<MetadataValue> relationshipMetadataList = itemService
.getMetadata(leftItem, MetadataSchemaEnum.RELATION.getName(), "isAuthorOfPublication", null, Item.ANY); .getMetadata(leftItem, MetadataSchemaEnum.RELATION.getName(), "isAuthorOfPublication", null, Item.ANY);
assertThat(relationshipMetadataList.size(), equalTo(0)); assertThat(relationshipMetadataList.size(), equalTo(1));
//request the virtual metadata of the publication only //request the virtual metadata of the publication only
List<RelationshipMetadataValue> list = relationshipMetadataService.getRelationshipMetadata(leftItem, true); List<RelationshipMetadataValue> list = relationshipMetadataService.getRelationshipMetadata(leftItem, true);
@@ -399,13 +429,38 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa
public void testDeleteAuthorRelationshipCopyToLeftItemFromDefaultInDb() throws Exception { public void testDeleteAuthorRelationshipCopyToLeftItemFromDefaultInDb() throws Exception {
initPublicationAuthorWithCopyParams(true, false); initPublicationAuthorWithCopyParams(true, false);
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
//verify the dc.contributor.author virtual metadata
List<MetadataValue> authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY);
assertThat(authorList.size(), equalTo(1));
//verify the dc.contributor.author actual metadata
List<MetadataValue> plainMetadataAuthorList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null &&
metadataValue.getMetadataField().getQualifier().equals("author"))
.collect(Collectors.toList());
assertThat(plainMetadataAuthorList.size(), equalTo(0));
//verify there's no relation.isAuthorOfPublication actual metadata
List<MetadataValue> plainRelationshipMetadataList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication"))
.collect(Collectors.toList());
assertThat(plainRelationshipMetadataList.size(), equalTo(0));
//delete the relationship, copying the virtual metadata to actual metadata on the leftItem //delete the relationship, copying the virtual metadata to actual metadata on the leftItem
//leftItem is the publication //leftItem is the publication
relationshipService.delete(context, relationship); relationshipService.delete(context, relationship);
context.restoreAuthSystemState(); context.restoreAuthSystemState();
//verify the dc.contributor.author actual metadata //verify the dc.contributor.author actual metadata
List<MetadataValue> authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); plainMetadataAuthorList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null &&
metadataValue.getMetadataField().getQualifier().equals("author"))
.collect(Collectors.toList());
assertThat(plainMetadataAuthorList.size(), equalTo(1));
//verify the dc.contributor.author actual metadata
authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY);
assertThat(authorList.size(), equalTo(1)); assertThat(authorList.size(), equalTo(1));
assertThat(authorList.get(0).getValue(), equalTo("familyName, firstName")); assertThat(authorList.get(0).getValue(), equalTo("familyName, firstName"));
assertThat(authorList.get(0).getMetadataField().getMetadataSchema().getName(), equalTo("dc")); assertThat(authorList.get(0).getMetadataField().getMetadataSchema().getName(), equalTo("dc"));
@@ -413,10 +468,15 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa
assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author")); assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author"));
assertNull(authorList.get(0).getAuthority()); assertNull(authorList.get(0).getAuthority());
//verify there's no relation.isAuthorOfPublication actual metadata //verify there's relation.isAuthorOfPublication actual metadata
plainRelationshipMetadataList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication"))
.collect(Collectors.toList());
assertThat(plainRelationshipMetadataList.size(), equalTo(1));
//verify there's relation.isAuthorOfPublication actual metadata
List<MetadataValue> relationshipMetadataList = itemService List<MetadataValue> relationshipMetadataList = itemService
.getMetadata(leftItem, MetadataSchemaEnum.RELATION.getName(), "isAuthorOfPublication", null, Item.ANY); .getMetadata(leftItem, MetadataSchemaEnum.RELATION.getName(), "isAuthorOfPublication", null, Item.ANY);
assertThat(relationshipMetadataList.size(), equalTo(0)); assertThat(relationshipMetadataList.size(), equalTo(1));
//request the virtual metadata of the publication only //request the virtual metadata of the publication only
List<RelationshipMetadataValue> list = relationshipMetadataService.getRelationshipMetadata(leftItem, true); List<RelationshipMetadataValue> list = relationshipMetadataService.getRelationshipMetadata(leftItem, true);
@@ -446,12 +506,36 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa
public void testDeleteAuthorRelationshipCopyToBothItemsFromDefaultsInDb() throws Exception { public void testDeleteAuthorRelationshipCopyToBothItemsFromDefaultsInDb() throws Exception {
initPublicationAuthorWithCopyParams(true, true); initPublicationAuthorWithCopyParams(true, true);
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
//verify the dc.contributor.author virtual metadata
List<MetadataValue> authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY);
assertThat(authorList.size(), equalTo(1));
//verify the dc.contributor.author actual metadata
List<MetadataValue> plainMetadataAuthorList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null &&
metadataValue.getMetadataField().getQualifier().equals("author"))
.collect(Collectors.toList());
assertThat(plainMetadataAuthorList.size(), equalTo(0));
//verify there's no relation.isAuthorOfPublication actual metadata
List<MetadataValue> plainRelationshipMetadataList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication"))
.collect(Collectors.toList());
assertThat(plainRelationshipMetadataList.size(), equalTo(0));
//delete the relationship, copying the virtual metadata to actual metadata on the both items //delete the relationship, copying the virtual metadata to actual metadata on the both items
relationshipService.delete(context, relationship); relationshipService.delete(context, relationship);
context.restoreAuthSystemState(); context.restoreAuthSystemState();
//verify the dc.contributor.author actual metadata //verify the dc.contributor.author actual metadata
List<MetadataValue> authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); plainMetadataAuthorList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null &&
metadataValue.getMetadataField().getQualifier().equals("author"))
.collect(Collectors.toList());
assertThat(plainMetadataAuthorList.size(), equalTo(1));
//verify the dc.contributor.author actual metadata
authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY);
assertThat(authorList.size(), equalTo(1)); assertThat(authorList.size(), equalTo(1));
assertThat(authorList.get(0).getValue(), equalTo("familyName, firstName")); assertThat(authorList.get(0).getValue(), equalTo("familyName, firstName"));
assertThat(authorList.get(0).getMetadataField().getMetadataSchema().getName(), equalTo("dc")); assertThat(authorList.get(0).getMetadataField().getMetadataSchema().getName(), equalTo("dc"));
@@ -459,10 +543,15 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa
assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author")); assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author"));
assertNull(authorList.get(0).getAuthority()); assertNull(authorList.get(0).getAuthority());
//verify there's no relation.isAuthorOfPublication actual metadata //verify there's relation.isAuthorOfPublication actual metadata
plainRelationshipMetadataList = leftItem.getMetadata().stream()
.filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication"))
.collect(Collectors.toList());
assertThat(plainRelationshipMetadataList.size(), equalTo(1));
//verify there's relation.isAuthorOfPublication actual metadata
List<MetadataValue> relationshipMetadataList = itemService List<MetadataValue> relationshipMetadataList = itemService
.getMetadata(leftItem, MetadataSchemaEnum.RELATION.getName(), "isAuthorOfPublication", null, Item.ANY); .getMetadata(leftItem, MetadataSchemaEnum.RELATION.getName(), "isAuthorOfPublication", null, Item.ANY);
assertThat(relationshipMetadataList.size(), equalTo(0)); assertThat(relationshipMetadataList.size(), equalTo(1));
} }
@Test @Test

View File

@@ -7,8 +7,12 @@
*/ */
package org.dspace.app.rest; package org.dspace.app.rest;
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import static org.dspace.content.Item.ANY;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
@@ -221,6 +225,35 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
public void testDeleteAuthorRelationshipCopyToLeftItem() throws Exception { public void testDeleteAuthorRelationshipCopyToLeftItem() throws Exception {
initPublicationAuthor(); initPublicationAuthor();
// Verify the dc.contributor.author virtual metadata of the left item
assertEquals(
1,
itemService
.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY)
.size()
);
// Verify there's no dc.contributor.author actual metadata on the left item
assertEquals(
0,
leftItem.getMetadata()
.stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList())
.size()
);
// Verify there's no relation.isAuthorOfPublication actual metadata on the left item
assertEquals(
0,
leftItem.getMetadata()
.stream()
.filter(metadataValue -> "isAuthorOfPublication"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
getClient(adminAuthToken).perform( getClient(adminAuthToken).perform(
delete("/api/core/relationships/" + relationship.getID() + "?copyVirtualMetadata=left")) delete("/api/core/relationships/" + relationship.getID() + "?copyVirtualMetadata=left"))
.andExpect(status().isNoContent()); .andExpect(status().isNoContent());
@@ -235,12 +268,35 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author")); assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author"));
assertNull(authorList.get(0).getAuthority()); assertNull(authorList.get(0).getAuthority());
// Check that the relation metadata values are gone because the relationship is gone
List<MetadataValue> relationshipMetadataList = itemService List<MetadataValue> relationshipMetadataList = itemService
.getMetadata(leftItem, "relation", "isAuthorOfPublication", null, Item.ANY); .getMetadata(leftItem, "relation", "isAuthorOfPublication", null, Item.ANY);
assertThat(relationshipMetadataList.size(), equalTo(0)); assertThat(relationshipMetadataList.size(), equalTo(1));
// Verify there's dc.contributor.author actual metadata on the left item
assertEquals(
1,
leftItem.getMetadata()
.stream()
.filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null &&
metadataValue.getMetadataField().getQualifier().equals("author"))
.collect(toList())
.size()
);
// Verify there's relation.isAuthorOfPublication actual metadata on the left item
assertEquals(
1,
leftItem.getMetadata()
.stream()
.filter(metadataValue -> "isAuthorOfPublication"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
// Check right item to ensure that no metadata is copied
rightItem = context.reloadEntity(rightItem);
relationshipMetadataList = itemService relationshipMetadataList = itemService
.getMetadata(rightItem, "relation", "isPublicationOfAuthor", null, Item.ANY); .getMetadata(rightItem, "relation", "isPublicationOfAuthor", null, Item.ANY);
assertThat(relationshipMetadataList.size(), equalTo(0)); assertThat(relationshipMetadataList.size(), equalTo(0));
@@ -250,6 +306,27 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
public void testAuthorDeleteRelationshipCopyToRightItem() throws Exception { public void testAuthorDeleteRelationshipCopyToRightItem() throws Exception {
initPublicationAuthor(); initPublicationAuthor();
// Verify there's no dc.contributor.author actual metadata on the right item
assertEquals(
0,
rightItem.getMetadata()
.stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList())
.size()
);
// Verify there's no relation.isPublicationOfAuthor actual metadata on the right item
assertEquals(
0,
rightItem.getMetadata()
.stream()
.filter(metadataValue -> "isPublicationOfAuthor"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
getClient(adminAuthToken).perform( getClient(adminAuthToken).perform(
delete("/api/core/relationships/" + relationship.getID() + "?copyVirtualMetadata=right")) delete("/api/core/relationships/" + relationship.getID() + "?copyVirtualMetadata=right"))
.andExpect(status().isNoContent()); .andExpect(status().isNoContent());
@@ -259,14 +336,27 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
List<MetadataValue> authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); List<MetadataValue> authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY);
assertThat(authorList.size(), equalTo(0)); assertThat(authorList.size(), equalTo(0));
// Check that the relation metadata values are gone because the relationship is gone
List<MetadataValue> relationshipMetadataList = itemService List<MetadataValue> relationshipMetadataList = itemService
.getMetadata(leftItem, "relation", "isAuthorOfPublication", null, Item.ANY); .getMetadata(leftItem, "relation", "isAuthorOfPublication", null, Item.ANY);
assertThat(relationshipMetadataList.size(), equalTo(0)); assertThat(relationshipMetadataList.size(), equalTo(0));
// Check right item to ensure that the metadata is copied
rightItem = itemService.find(context, rightItem.getID());
relationshipMetadataList = itemService relationshipMetadataList = itemService
.getMetadata(rightItem, "relation", "isPublicationOfAuthor", null, Item.ANY); .getMetadata(rightItem, "relation", "isPublicationOfAuthor", null, Item.ANY);
assertThat(relationshipMetadataList.size(), equalTo(0)); assertThat(relationshipMetadataList.size(), equalTo(1));
// Verify there's relation.isPublicationOfAuthor actual metadata on the right item
assertEquals(
1,
rightItem.getMetadata()
.stream()
.filter(metadataValue -> "isPublicationOfAuthor"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
// There is no additional Metadata to check on the rightItem because the configuration of the virtual // There is no additional Metadata to check on the rightItem because the configuration of the virtual
// metadata holds no config to display virtual metadata on the author of the publication // metadata holds no config to display virtual metadata on the author of the publication
@@ -291,11 +381,44 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
List<MetadataValue> relationshipMetadataList = itemService List<MetadataValue> relationshipMetadataList = itemService
.getMetadata(leftItem, "relation", "isAuthorOfPublication", null, Item.ANY); .getMetadata(leftItem, "relation", "isAuthorOfPublication", null, Item.ANY);
assertThat(relationshipMetadataList.size(), equalTo(0)); assertThat(relationshipMetadataList.size(), equalTo(1));
// Verify there's dc.contributor.author actual metadata on the left item
assertEquals(
1,
leftItem.getMetadata()
.stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList())
.size()
);
// Verify there's relation.isAuthorOfPublication actual metadata on the left item
assertEquals(
1,
leftItem.getMetadata()
.stream()
.filter(metadataValue -> "isAuthorOfPublication"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
rightItem = itemService.find(context, rightItem.getID());
relationshipMetadataList = itemService relationshipMetadataList = itemService
.getMetadata(rightItem, "relation", "isPublicationOfAuthor", null, Item.ANY); .getMetadata(rightItem, "relation", "isPublicationOfAuthor", null, Item.ANY);
assertThat(relationshipMetadataList.size(), equalTo(0)); assertThat(relationshipMetadataList.size(), equalTo(1));
// Verify there's relation.isPublicationOfAuthor actual metadata on the right item
assertEquals(
1,
rightItem.getMetadata()
.stream()
.filter(metadataValue -> "isPublicationOfAuthor"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
// There is no additional Metadata to check on the rightItem because the configuration of the virtual // There is no additional Metadata to check on the rightItem because the configuration of the virtual
// metadata holds no config to display virtual metadata on the author of the publication // metadata holds no config to display virtual metadata on the author of the publication
@@ -375,6 +498,32 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
public void deleteItemCopyVirtualMetadataAll() throws Exception { public void deleteItemCopyVirtualMetadataAll() throws Exception {
initPersonProjectPublication(); initPersonProjectPublication();
for (Item item : asList(publicationItem, projectItem)) {
// Verify the dc.contributor.author virtual metadata
assertEquals(
1,
itemService.getMetadata(item, "dc", "contributor", "author", ANY).size()
);
// Verify there's no dc.contributor.author actual metadata on the item
assertEquals(
0,
item.getMetadata().stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList()).size()
);
// Verify there's no relation.isAuthorOfPublication actual metadata on the item
assertEquals(
0,
item.getMetadata().stream()
.filter(metadataValue -> "isAuthorOfPublication"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList()).size()
);
}
getClient(adminAuthToken).perform( getClient(adminAuthToken).perform(
delete("/api/core/items/" + personItem.getID() + "?copyVirtualMetadata=all")) delete("/api/core/items/" + personItem.getID() + "?copyVirtualMetadata=all"))
.andExpect(status().isNoContent()); .andExpect(status().isNoContent());
@@ -387,7 +536,26 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
assertNull(publicationAuthorList.get(0).getAuthority()); assertNull(publicationAuthorList.get(0).getAuthority());
List<MetadataValue> publicationRelationships = itemService.getMetadata(publicationItem, List<MetadataValue> publicationRelationships = itemService.getMetadata(publicationItem,
"relation", "isAuthorOfPublication", Item.ANY, Item.ANY); "relation", "isAuthorOfPublication", Item.ANY, Item.ANY);
assertThat(publicationRelationships.size(), equalTo(0)); assertThat(publicationRelationships.size(), equalTo(1));
// Verify there's dc.contributor.author actual metadata on the publication item
assertEquals(
1,
publicationItem.getMetadata().stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList())
.size()
);
// Verify there's relation.isAuthorOfPublication actual metadata on the publication item
assertEquals(
1,
publicationItem.getMetadata().stream()
.filter(metadataValue -> "isAuthorOfPublication"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
projectItem = itemService.find(context, projectItem.getID()); projectItem = itemService.find(context, projectItem.getID());
List<MetadataValue> projectAuthorList = itemService.getMetadata(projectItem, List<MetadataValue> projectAuthorList = itemService.getMetadata(projectItem,
@@ -397,13 +565,58 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
assertNull(projectAuthorList.get(0).getAuthority()); assertNull(projectAuthorList.get(0).getAuthority());
List<MetadataValue> projectRelationships = itemService.getMetadata(projectItem, List<MetadataValue> projectRelationships = itemService.getMetadata(projectItem,
"relation", "isPersonOfProject", Item.ANY, Item.ANY); "relation", "isPersonOfProject", Item.ANY, Item.ANY);
assertThat(projectRelationships.size(), equalTo(0)); assertThat(projectRelationships.size(), equalTo(1));
// Verify there's dc.contributor.author actual metadata on the project item
assertEquals(
1,
projectItem.getMetadata().stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList())
.size()
);
// Verify there's relation.isPersonOfProject actual metadata on the project item
assertEquals(
1,
projectItem.getMetadata().stream()
.filter(metadataValue -> "isPersonOfProject"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
} }
@Test @Test
public void deleteItemCopyVirtualMetadataOneType() throws Exception { public void deleteItemCopyVirtualMetadataOneType() throws Exception {
initPersonProjectPublication(); initPersonProjectPublication();
for (Item item : asList(publicationItem, projectItem)) {
// Verify the dc.contributor.author virtual metadata
assertEquals(
1,
itemService.getMetadata(item, "dc", "contributor", "author", ANY).size()
);
// Verify there's no dc.contributor.author actual metadata on the item
assertEquals(
0,
item.getMetadata().stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList()).size()
);
// Verify there's no relation.isAuthorOfPublication actual metadata on the item
assertEquals(
0,
item.getMetadata().stream()
.filter(metadataValue -> "isAuthorOfPublication"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList()).size()
);
}
getClient(adminAuthToken).perform( getClient(adminAuthToken).perform(
delete("/api/core/items/" + personItem.getID() + "?copyVirtualMetadata=" delete("/api/core/items/" + personItem.getID() + "?copyVirtualMetadata="
+ publicationPersonRelationshipType.getID())) + publicationPersonRelationshipType.getID()))
@@ -417,7 +630,26 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
assertNull(publicationAuthorList.get(0).getAuthority()); assertNull(publicationAuthorList.get(0).getAuthority());
List<MetadataValue> publicationRelationships = itemService.getMetadata(publicationItem, List<MetadataValue> publicationRelationships = itemService.getMetadata(publicationItem,
"relation", "isAuthorOfPublication", Item.ANY, Item.ANY); "relation", "isAuthorOfPublication", Item.ANY, Item.ANY);
assertThat(publicationRelationships.size(), equalTo(0)); assertThat(publicationRelationships.size(), equalTo(1));
// Verify there's dc.contributor.author actual metadata on the publication item
assertEquals(
1,
publicationItem.getMetadata().stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList())
.size()
);
// Verify there's relation.isAuthorOfPublication actual metadata on the publication item
assertEquals(
1,
publicationItem.getMetadata().stream()
.filter(metadataValue -> "isAuthorOfPublication"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
projectItem = itemService.find(context, projectItem.getID()); projectItem = itemService.find(context, projectItem.getID());
List<MetadataValue> projectAuthorList = itemService.getMetadata(projectItem, List<MetadataValue> projectAuthorList = itemService.getMetadata(projectItem,
@@ -432,6 +664,32 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
public void deleteItemCopyVirtualMetadataTwoTypes() throws Exception { public void deleteItemCopyVirtualMetadataTwoTypes() throws Exception {
initPersonProjectPublication(); initPersonProjectPublication();
for (Item item : asList(publicationItem, projectItem)) {
// Verify the dc.contributor.author virtual metadata
assertEquals(
1,
itemService.getMetadata(item, "dc", "contributor", "author", ANY).size()
);
// Verify there's no dc.contributor.author actual metadata on the item
assertEquals(
0,
item.getMetadata().stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList()).size()
);
// Verify there's no relation.isAuthorOfPublication actual metadata on the item
assertEquals(
0,
item.getMetadata().stream()
.filter(metadataValue -> "isAuthorOfPublication"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList()).size()
);
}
getClient(adminAuthToken).perform( getClient(adminAuthToken).perform(
delete("/api/core/items/" + personItem.getID() delete("/api/core/items/" + personItem.getID()
+ "?copyVirtualMetadata=" + publicationPersonRelationshipType.getID() + "?copyVirtualMetadata=" + publicationPersonRelationshipType.getID()
@@ -446,7 +704,26 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
assertNull(publicationAuthorList.get(0).getAuthority()); assertNull(publicationAuthorList.get(0).getAuthority());
List<MetadataValue> publicationRelationships = itemService.getMetadata(publicationItem, List<MetadataValue> publicationRelationships = itemService.getMetadata(publicationItem,
"relation", "isAuthorOfPublication", Item.ANY, Item.ANY); "relation", "isAuthorOfPublication", Item.ANY, Item.ANY);
assertThat(publicationRelationships.size(), equalTo(0)); assertThat(publicationRelationships.size(), equalTo(1));
// Verify there's dc.contributor.author actual metadata on the publication item
assertEquals(
1,
publicationItem.getMetadata().stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList())
.size()
);
// Verify there's relation.isAuthorOfPublication actual metadata on the publication item
assertEquals(
1,
publicationItem.getMetadata().stream()
.filter(metadataValue -> "isAuthorOfPublication"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
projectItem = itemService.find(context, projectItem.getID()); projectItem = itemService.find(context, projectItem.getID());
List<MetadataValue> projectAuthorList = itemService.getMetadata(projectItem, List<MetadataValue> projectAuthorList = itemService.getMetadata(projectItem,
@@ -456,7 +733,26 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
assertNull(projectAuthorList.get(0).getAuthority()); assertNull(projectAuthorList.get(0).getAuthority());
List<MetadataValue> projectRelationships = itemService.getMetadata(projectItem, List<MetadataValue> projectRelationships = itemService.getMetadata(projectItem,
"relation", "isPersonOfProject", Item.ANY, Item.ANY); "relation", "isPersonOfProject", Item.ANY, Item.ANY);
assertThat(projectRelationships.size(), equalTo(0)); assertThat(projectRelationships.size(), equalTo(1));
// Verify there's dc.contributor.author actual metadata on the project item
assertEquals(
1,
projectItem.getMetadata().stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList())
.size()
);
// Verify there's relation.isPersonOfProject actual metadata on the project item
assertEquals(
1,
projectItem.getMetadata().stream()
.filter(metadataValue -> "isPersonOfProject"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
} }
@Test @Test
@@ -520,6 +816,32 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
public void deleteItemCopyVirtualMetadataAllNoPermissions() throws Exception { public void deleteItemCopyVirtualMetadataAllNoPermissions() throws Exception {
initPersonProjectPublication(); initPersonProjectPublication();
for (Item item : asList(publicationItem, projectItem)) {
// Verify the dc.contributor.author virtual metadata
assertEquals(
1,
itemService.getMetadata(item, "dc", "contributor", "author", ANY).size()
);
// Verify there's no dc.contributor.author actual metadata on the item
assertEquals(
0,
item.getMetadata().stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList()).size()
);
// Verify there's no relation.isAuthorOfPublication actual metadata on the item
assertEquals(
0,
item.getMetadata().stream()
.filter(metadataValue -> "isAuthorOfPublication"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList()).size()
);
}
getClient(getAuthToken(eperson.getEmail(), password)).perform( getClient(getAuthToken(eperson.getEmail(), password)).perform(
delete("/api/core/items/" + personItem.getID())) delete("/api/core/items/" + personItem.getID()))
.andExpect(status().isForbidden()); .andExpect(status().isForbidden());
@@ -608,6 +930,32 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
public void deleteItemCopyVirtualMetadataConfigured() throws Exception { public void deleteItemCopyVirtualMetadataConfigured() throws Exception {
initPersonProjectPublication(); initPersonProjectPublication();
for (Item item : asList(publicationItem, projectItem)) {
// Verify the dc.contributor.author virtual metadata
assertEquals(
1,
itemService.getMetadata(item, "dc", "contributor", "author", ANY).size()
);
// Verify there's no dc.contributor.author actual metadata on the item
assertEquals(
0,
item.getMetadata().stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList()).size()
);
// Verify there's no relation.isAuthorOfPublication actual metadata on the item
assertEquals(
0,
item.getMetadata().stream()
.filter(metadataValue -> "isAuthorOfPublication"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList()).size()
);
}
getClient(adminAuthToken).perform( getClient(adminAuthToken).perform(
delete("/api/core/items/" + personItem.getID() + "?copyVirtualMetadata=configured")) delete("/api/core/items/" + personItem.getID() + "?copyVirtualMetadata=configured"))
.andExpect(status().isNoContent()); .andExpect(status().isNoContent());
@@ -629,7 +977,26 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
assertNull(projectAuthorList.get(0).getAuthority()); assertNull(projectAuthorList.get(0).getAuthority());
List<MetadataValue> projectRelationships = itemService.getMetadata(projectItem, List<MetadataValue> projectRelationships = itemService.getMetadata(projectItem,
"relation", "isPersonOfProject", Item.ANY, Item.ANY); "relation", "isPersonOfProject", Item.ANY, Item.ANY);
assertThat(projectRelationships.size(), equalTo(0)); assertThat(projectRelationships.size(), equalTo(1));
// Verify there's dc.contributor.author actual metadata on the project item
assertEquals(
1,
projectItem.getMetadata().stream()
.filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier()))
.collect(toList())
.size()
);
// Verify there's relation.isPersonOfProject actual metadata on the project item
assertEquals(
1,
projectItem.getMetadata().stream()
.filter(metadataValue -> "isPersonOfProject"
.equals(metadataValue.getMetadataField().getElement()))
.collect(toList())
.size()
);
} }
@Test @Test
@@ -653,7 +1020,7 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio
assertNull(publicationAuthorList.get(0).getAuthority()); assertNull(publicationAuthorList.get(0).getAuthority());
List<MetadataValue> publicationRelationships = itemService.getMetadata(publicationItem, List<MetadataValue> publicationRelationships = itemService.getMetadata(publicationItem,
"relation", "isAuthorOfPublication", Item.ANY, Item.ANY); "relation", "isAuthorOfPublication", Item.ANY, Item.ANY);
assertThat(publicationRelationships.size(), equalTo(0)); assertThat(publicationRelationships.size(), equalTo(1));
projectItem = itemService.find(context, projectItem.getID()); projectItem = itemService.find(context, projectItem.getID());
List<MetadataValue> projectAuthorList = itemService.getMetadata(projectItem, List<MetadataValue> projectAuthorList = itemService.getMetadata(projectItem,

View File

@@ -775,6 +775,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
.andExpect(status().isCreated()) .andExpect(status().isCreated())
.andDo(result -> idRef2.set(read(result.getResponse().getContentAsString(), "$.id"))); .andDo(result -> idRef2.set(read(result.getResponse().getContentAsString(), "$.id")));
publication1 = itemService.find(context, publication1.getID());
list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY); list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY);
// Ensure that we now have three dc.contributor.author mdv ("Smith, Donald", "plain text", "Smith, Maria" // Ensure that we now have three dc.contributor.author mdv ("Smith, Donald", "plain text", "Smith, Maria"
// In that order which will be checked below the rest call // In that order which will be checked below the rest call
@@ -801,6 +802,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
itemService.update(context, publication1); itemService.update(context, publication1);
context.restoreAuthSystemState(); context.restoreAuthSystemState();
publication1 = itemService.find(context, publication1.getID());
list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY); list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY);
// Assert that the list of dc.contributor.author mdv is now of size 4 in the following order: // Assert that the list of dc.contributor.author mdv is now of size 4 in the following order:
@@ -838,6 +840,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
.andExpect(status().isCreated()) .andExpect(status().isCreated())
.andDo(result -> idRef3.set(read(result.getResponse().getContentAsString(), "$.id"))); .andDo(result -> idRef3.set(read(result.getResponse().getContentAsString(), "$.id")));
publication1 = itemService.find(context, publication1.getID());
list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY); list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY);
// Assert that our dc.contributor.author mdv list is now of size 5 // Assert that our dc.contributor.author mdv list is now of size 5
assertEquals(5, list.size()); assertEquals(5, list.size());
@@ -901,6 +904,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
itemService.update(context, publication1); itemService.update(context, publication1);
context.restoreAuthSystemState(); context.restoreAuthSystemState();
publication1 = itemService.find(context, publication1.getID());
list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY); list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY);
assertEquals(10, list.size()); assertEquals(10, list.size());