Merge remote-tracking branch 'origin/feature-relationship-versioning_discover-7.2' into feature-relationship-versioning-contribution

This commit is contained in:
Ben Bosman
2022-05-25 17:53:09 +02:00
19 changed files with 861 additions and 553 deletions

View File

@@ -40,6 +40,7 @@ import org.dspace.content.service.BitstreamService;
import org.dspace.content.service.BundleService; import org.dspace.content.service.BundleService;
import org.dspace.content.service.CollectionService; import org.dspace.content.service.CollectionService;
import org.dspace.content.service.CommunityService; import org.dspace.content.service.CommunityService;
import org.dspace.content.service.EntityTypeService;
import org.dspace.content.service.InstallItemService; import org.dspace.content.service.InstallItemService;
import org.dspace.content.service.ItemService; import org.dspace.content.service.ItemService;
import org.dspace.content.service.MetadataSchemaService; import org.dspace.content.service.MetadataSchemaService;
@@ -120,6 +121,9 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
@Autowired(required = true) @Autowired(required = true)
private RelationshipMetadataService relationshipMetadataService; private RelationshipMetadataService relationshipMetadataService;
@Autowired(required = true)
private EntityTypeService entityTypeService;
protected ItemServiceImpl() { protected ItemServiceImpl() {
super(); super();
} }
@@ -1535,5 +1539,37 @@ prevent the generation of resource policy entry values with null dspace_object a
.stream().findFirst().orElse(null); .stream().findFirst().orElse(null);
} }
@Override
public String getEntityTypeLabel(Item item) {
List<MetadataValue> mdvs = getMetadata(item, "dspace", "entity", "type", Item.ANY, false);
if (mdvs.isEmpty()) {
return null;
}
if (mdvs.size() > 1) {
log.warn(
"Item with uuid {}, handle {} has {} entity types ({}), expected 1 entity type",
item.getID(), item.getHandle(), mdvs.size(),
mdvs.stream().map(MetadataValue::getValue).collect(Collectors.toList())
);
}
String entityType = mdvs.get(0).getValue();
if (StringUtils.isBlank(entityType)) {
return null;
}
return entityType;
}
@Override
public EntityType getEntityType(Context context, Item item) throws SQLException {
String entityTypeString = getEntityTypeLabel(item);
if (StringUtils.isBlank(entityTypeString)) {
return null;
}
return entityTypeService.findByEntityType(context, entityTypeString);
}
} }

View File

@@ -56,14 +56,9 @@ public interface RelationshipMetadataService {
* This method will retrieve the EntityType String from an item * This method will retrieve the EntityType String from an item
* @param item The Item for which the entityType String will be returned * @param item The Item for which the entityType String will be returned
* @return A String value indicating the entityType * @return A String value indicating the entityType
* @deprecated use {@link org.dspace.content.service.ItemService#getEntityTypeLabel(Item)} instead.
*/ */
@Deprecated
public String getEntityTypeStringFromMetadata(Item item); public String getEntityTypeStringFromMetadata(Item item);
/**
* This method will retrieve the EntityType from an item
* @param item The Item for which the entityType will be returned
* @return The entity type
*/
public EntityType getEntityTypeFromMetadata(Context context, Item item) throws SQLException;
} }

View File

@@ -21,7 +21,7 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dspace.content.dao.pojo.ItemUuidAndRelationshipId; import org.dspace.content.dao.pojo.ItemUuidAndRelationshipId;
import org.dspace.content.service.EntityTypeService; import org.dspace.content.service.ItemService;
import org.dspace.content.service.MetadataFieldService; import org.dspace.content.service.MetadataFieldService;
import org.dspace.content.service.RelationshipService; import org.dspace.content.service.RelationshipService;
import org.dspace.content.service.RelationshipTypeService; import org.dspace.content.service.RelationshipTypeService;
@@ -45,7 +45,7 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
protected RelationshipTypeService relationshipTypeService; protected RelationshipTypeService relationshipTypeService;
@Autowired(required = true) @Autowired(required = true)
protected EntityTypeService entityTypeService; protected ItemService itemService;
@Autowired(required = true) @Autowired(required = true)
protected VirtualMetadataPopulator virtualMetadataPopulator; protected VirtualMetadataPopulator virtualMetadataPopulator;
@@ -58,7 +58,7 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
Context context = new Context(); Context context = new Context();
List<RelationshipMetadataValue> fullMetadataValueList = new LinkedList<>(); List<RelationshipMetadataValue> fullMetadataValueList = new LinkedList<>();
try { try {
EntityType entityType = getEntityTypeFromMetadata(context, item); EntityType entityType = itemService.getEntityType(context, item);
if (entityType != null) { if (entityType != null) {
// NOTE: The following code will add metadata fields of type relation.*.latestForDiscovery // NOTE: The following code will add metadata fields of type relation.*.latestForDiscovery
// (e.g. relation.isAuthorOfPublication.latestForDiscovery). // (e.g. relation.isAuthorOfPublication.latestForDiscovery).
@@ -167,25 +167,10 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
.collect(Collectors.toUnmodifiableList()); .collect(Collectors.toUnmodifiableList());
} }
@Override
@Deprecated
public String getEntityTypeStringFromMetadata(Item item) { public String getEntityTypeStringFromMetadata(Item item) {
List<MetadataValue> list = item.getMetadata(); return itemService.getEntityTypeLabel(item);
for (MetadataValue mdv : list) {
if (StringUtils.equals(mdv.getMetadataField().getMetadataSchema().getName(), "dspace")
&& StringUtils.equals(mdv.getMetadataField().getElement(), "entity")
&& StringUtils.equals(mdv.getMetadataField().getQualifier(), "type")) {
return mdv.getValue();
}
}
return null;
}
public EntityType getEntityTypeFromMetadata(Context context, Item item) throws SQLException {
String entityTypeString = getEntityTypeStringFromMetadata(item);
if (StringUtils.isBlank(entityTypeString)) {
return null;
}
return entityTypeService.findByEntityType(context, entityTypeString);
} }
@Override @Override

View File

@@ -792,7 +792,7 @@ public class RelationshipServiceImpl implements RelationshipService {
+ item.getID() + " due to " + currentDepth + " depth"); + item.getID() + " due to " + currentDepth + " depth");
return; return;
} }
String entityTypeStringFromMetadata = relationshipMetadataService.getEntityTypeStringFromMetadata(item); String entityTypeStringFromMetadata = itemService.getEntityTypeLabel(item);
EntityType actualEntityType = entityTypeService.findByEntityType(context, entityTypeStringFromMetadata); EntityType actualEntityType = entityTypeService.findByEntityType(context, entityTypeStringFromMetadata);
// Get all types of relations for the current item // Get all types of relations for the current item
List<RelationshipType> relationshipTypes = relationshipTypeService.findByEntityType(context, actualEntityType); List<RelationshipType> relationshipTypes = relationshipTypeService.findByEntityType(context, actualEntityType);
@@ -865,8 +865,7 @@ public class RelationshipServiceImpl implements RelationshipService {
boolean copyToRightItem) boolean copyToRightItem)
throws SQLException, AuthorizeException { throws SQLException, AuthorizeException {
if (copyToLeftItem) { if (copyToLeftItem) {
String entityTypeString = relationshipMetadataService String entityTypeString = itemService.getEntityTypeLabel(relationship.getLeftItem());
.getEntityTypeStringFromMetadata(relationship.getLeftItem());
List<RelationshipMetadataValue> relationshipMetadataValues = List<RelationshipMetadataValue> relationshipMetadataValues =
relationshipMetadataService.findRelationshipMetadataValueForItemRelationship(context, relationshipMetadataService.findRelationshipMetadataValueForItemRelationship(context,
relationship.getLeftItem(), entityTypeString, relationship, true); relationship.getLeftItem(), entityTypeString, relationship, true);
@@ -892,8 +891,7 @@ public class RelationshipServiceImpl implements RelationshipService {
itemService.update(context, relationship.getLeftItem()); itemService.update(context, relationship.getLeftItem());
} }
if (copyToRightItem) { if (copyToRightItem) {
String entityTypeString = relationshipMetadataService String entityTypeString = itemService.getEntityTypeLabel(relationship.getRightItem());
.getEntityTypeStringFromMetadata(relationship.getRightItem());
List<RelationshipMetadataValue> relationshipMetadataValues = List<RelationshipMetadataValue> relationshipMetadataValues =
relationshipMetadataService.findRelationshipMetadataValueForItemRelationship(context, relationshipMetadataService.findRelationshipMetadataValueForItemRelationship(context,
relationship.getRightItem(), entityTypeString, relationship, true); relationship.getRightItem(), entityTypeString, relationship, true);

View File

@@ -21,6 +21,7 @@ import org.dspace.content.Bitstream;
import org.dspace.content.Bundle; import org.dspace.content.Bundle;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.content.Community; import org.dspace.content.Community;
import org.dspace.content.EntityType;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.content.MetadataField; import org.dspace.content.MetadataField;
import org.dspace.content.MetadataValue; import org.dspace.content.MetadataValue;
@@ -783,4 +784,19 @@ public interface ItemService
public List<MetadataValue> getMetadata(Item item, String schema, String element, String qualifier, public List<MetadataValue> getMetadata(Item item, String schema, String element, String qualifier,
String lang, boolean enableVirtualMetadata); String lang, boolean enableVirtualMetadata);
/**
* Retrieve the label of the entity type of the given item.
* @param item the item.
* @return the label of the entity type, taken from the item metadata, or null if not found.
*/
public String getEntityTypeLabel(Item item);
/**
* Retrieve the entity type of the given item.
* @param context the DSpace context.
* @param item the item.
* @return the entity type of the given item, or null if not found.
*/
public EntityType getEntityType(Context context, Item item) throws SQLException;
} }

View File

@@ -21,7 +21,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dspace.content.EntityType; import org.dspace.content.EntityType;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.content.MetadataValue;
import org.dspace.content.Relationship; import org.dspace.content.Relationship;
import org.dspace.content.RelationshipType; import org.dspace.content.RelationshipType;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
@@ -299,8 +298,8 @@ public class VersioningConsumer implements Consumer {
* @return true if the entity types of both items are non-null and equal, false otherwise. * @return true if the entity types of both items are non-null and equal, false otherwise.
*/ */
protected boolean doEntityTypesMatch(Item latestItem, Item previousItem) { protected boolean doEntityTypesMatch(Item latestItem, Item previousItem) {
String latestItemEntityType = getEntityType(latestItem); String latestItemEntityType = itemService.getEntityTypeLabel(latestItem);
String previousItemEntityType = getEntityType(previousItem); String previousItemEntityType = itemService.getEntityTypeLabel(previousItem);
// check if both items have an entity type // check if both items have an entity type
if (latestItemEntityType == null || previousItemEntityType == null) { if (latestItemEntityType == null || previousItemEntityType == null) {
@@ -338,49 +337,18 @@ public class VersioningConsumer implements Consumer {
return true; return true;
} }
/**
* Get the entity type (stored in metadata field dspace.entity.type) of any item.
* @param item the item.
* @return the label of the entity type.
*/
protected String getEntityType(Item item) {
List<MetadataValue> mdvs = itemService.getMetadata(item, "dspace", "entity", "type", Item.ANY, false);
if (mdvs.isEmpty()) {
return null;
}
if (mdvs.size() > 1) {
log.warn(
"Item with uuid {}, handle {} has {} entity types ({}), expected 1 entity type",
item.getID(), item.getHandle(), mdvs.size(),
mdvs.stream().map(MetadataValue::getValue).collect(Collectors.toUnmodifiableList())
);
}
String entityType = mdvs.get(0).getValue();
if (StringUtils.isBlank(entityType)) {
return null;
}
return entityType;
}
/** /**
* Get the entity type (stored in metadata field dspace.entity.type) of any item. * Get the entity type (stored in metadata field dspace.entity.type) of any item.
* @param item the item. * @param item the item.
* @return the entity type. * @return the entity type.
*/ */
protected EntityType getEntityType(Context ctx, Item item) { protected EntityType getEntityType(Context ctx, Item item) {
String entityTypeStr = getEntityType(item);
if (entityTypeStr == null) {
return null;
}
try { try {
return entityTypeService.findByEntityType(ctx, entityTypeStr); return itemService.getEntityType(ctx, item);
} catch (SQLException e) { } catch (SQLException e) {
log.error( log.error(
"Exception occurred when trying to obtain entity type with label {} of item with uuid {}, handle {}", "Exception occurred when trying to obtain entity type with label {} of item with uuid {}, handle {}",
entityTypeStr, item.getID(), item.getHandle(), e itemService.getEntityTypeLabel(item), item.getID(), item.getHandle(), e
); );
return null; return null;
} }

View File

@@ -80,6 +80,7 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
Item project6; Item project6;
RelationshipType isAuthorOfPublication; RelationshipType isAuthorOfPublication;
RelationshipType isProjectOfPublication;
RelationshipType isProjectOfPerson; RelationshipType isProjectOfPerson;
EntityType publicationEntityType; EntityType publicationEntityType;
@@ -220,6 +221,10 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
.create(context, publicationEntityType, personEntityType, .create(context, publicationEntityType, personEntityType,
"isAuthorOfPublication", "isPublicationOfAuthor", "isAuthorOfPublication", "isPublicationOfAuthor",
null, null, null, null); null, null, null, null);
isProjectOfPublication = relationshipTypeService
.create(context, publicationEntityType, projectEntityType,
"isProjectOfPublication", "isPublicationOfProject",
null, null, null, null);
isProjectOfPerson = relationshipTypeService isProjectOfPerson = relationshipTypeService
.create(context, personEntityType, projectEntityType, .create(context, personEntityType, projectEntityType,
"isProjectOfPerson", "isPersonOfProject", "isProjectOfPerson", "isPersonOfProject",
@@ -741,6 +746,52 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
)); ));
} }
@Test
public void createUseForPlaceRelationshipWithLeftPlaceInTheMiddleWithMetadataTest_ignoreOtherRels(
) throws Exception {
context.turnOffAuthorisationSystem();
// Add a dc.contributor.author MDV
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 1");
// Add two Authors to the same Publication, appending to the end
Relationship r1 = relationshipService.create(context, publication1, author1, isAuthorOfPublication, -1, -1);
Relationship r2 = relationshipService.create(context, publication1, author2, isAuthorOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, project1, isProjectOfPublication, -1, -1);
// Add another dc.contributor.author MDV
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 2");
// NOTE: unrelated relationship => should not be affected
Relationship ur2 = relationshipService.create(context, author2, project2, isProjectOfPerson, -1, -1);
// Add another Author @ leftPlace 2. All MDVs & relationships after it should get pushed by one place
Relationship r3 = relationshipService.create(context, publication1, author3, isAuthorOfPublication, 2, -1);
context.restoreAuthSystemState();
// Check relationship order
assertLeftPlace(r1, 1);
assertLeftPlace(r3, 2);
assertLeftPlace(r2, 3);
assertRelationMetadataOrder(publication1, isAuthorOfPublication, List.of(r1, r3, r2));
assertMetadataOrder(publication1, "dc.contributor.author", List.of(
"MDV 1",
"Author, First",
"Author, Third",
"Author, Second",
"MDV 2"
));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
assertLeftPlace(ur2, 0);
assertRightPlace(ur2, 0);
}
@Test @Test
public void createUseForPlaceRelationshipWithLeftPlaceAtTheEndWithMetadataTest() throws Exception { public void createUseForPlaceRelationshipWithLeftPlaceAtTheEndWithMetadataTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -832,6 +883,39 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
assertRelationMetadataOrder(author1, isAuthorOfPublication, List.of(r1, r3, r2)); assertRelationMetadataOrder(author1, isAuthorOfPublication, List.of(r1, r3, r2));
} }
@Test
public void createUseForPlaceRelationshipWithRightPlaceInTheMiddleNoMetadataTest_ignoreOtherRels(
) throws Exception {
context.turnOffAuthorisationSystem();
// Add two Publications to the same Author, appending to the end
Relationship r1 = relationshipService.create(context, publication1, author1, isAuthorOfPublication, -1, -1);
Relationship r2 = relationshipService.create(context, publication2, author1, isAuthorOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, author1, project1, isProjectOfPerson, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur2 = relationshipService.create(context, author1, project2, isProjectOfPerson, -1, -1);
// Add another Publication @ rightPlace 1. The second relationship should get pushed by one place
Relationship r3 = relationshipService.create(context, publication3, author1, isAuthorOfPublication, -1, 1);
context.restoreAuthSystemState();
// Check relationship order
assertRightPlace(r1, 0);
assertRightPlace(r3, 1);
assertRightPlace(r2, 2);
assertRelationMetadataOrder(author1, isAuthorOfPublication, List.of(r1, r3, r2));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
assertLeftPlace(ur2, 1);
assertRightPlace(ur2, 0);
}
@Test @Test
public void createUseForPlaceRelationshipWithRightPlaceAtTheEndNoMetadataTest() throws Exception { public void createUseForPlaceRelationshipWithRightPlaceAtTheEndNoMetadataTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -910,6 +994,33 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
assertRelationMetadataOrder(author1, isProjectOfPerson, List.of(r1, r3, r2)); assertRelationMetadataOrder(author1, isProjectOfPerson, List.of(r1, r3, r2));
} }
@Test
public void createNonUseForPlaceRelationshipWithLeftPlaceInTheMiddleTest_ignoreOtherRels() throws Exception {
context.turnOffAuthorisationSystem();
// Add two Projects to the same Author, appending to the end
Relationship r1 = relationshipService.create(context, author1, project1, isProjectOfPerson, -1, -1);
Relationship r2 = relationshipService.create(context, author1, project2, isProjectOfPerson, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, author1, isAuthorOfPublication, -1, -1);
// Add another Project @ leftPlace 1. The second relationship should get pushed by one place
Relationship r3 = relationshipService.create(context, author1, project3, isProjectOfPerson, 1, -1);
context.restoreAuthSystemState();
// Check relationship order
assertLeftPlace(r1, 0);
assertLeftPlace(r3, 1);
assertLeftPlace(r2, 2);
assertRelationMetadataOrder(author1, isProjectOfPerson, List.of(r1, r3, r2));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
}
@Test @Test
public void createNonUseForPlaceRelationshipWithLeftPlaceAtTheEndTest() throws Exception { public void createNonUseForPlaceRelationshipWithLeftPlaceAtTheEndTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -988,6 +1099,33 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r1, r3, r2)); assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r1, r3, r2));
} }
@Test
public void createNonUseForPlaceRelationshipWithRightPlaceInTheMiddleTest_ignoreOtherRels() throws Exception {
context.turnOffAuthorisationSystem();
// Add two Authors to the same Project, appending to the end
Relationship r1 = relationshipService.create(context, author1, project1, isProjectOfPerson, -1, -1);
Relationship r2 = relationshipService.create(context, author2, project1, isProjectOfPerson, -1, -1);
// Add another Author @ rightPlace 1. The second relationship should get pushed by one place
Relationship r3 = relationshipService.create(context, author3, project1, isProjectOfPerson, -1, 1);
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, project1, isProjectOfPublication, -1, -1);
context.restoreAuthSystemState();
// Check relationship order
assertRightPlace(r1, 0);
assertRightPlace(r3, 1);
assertRightPlace(r2, 2);
assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r1, r3, r2));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
}
@Test @Test
public void createNonUseForPlaceRelationshipWithRightPlaceAtTheEndTest() throws Exception { public void createNonUseForPlaceRelationshipWithRightPlaceAtTheEndTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -1219,6 +1357,42 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
assertRelationMetadataOrder(publication1, isAuthorOfPublication, List.of(r2, r1, r3)); assertRelationMetadataOrder(publication1, isAuthorOfPublication, List.of(r2, r1, r3));
} }
@Test
public void moveUseForPlaceRelationshipUpToLeftPlaceInTheMiddleWithTest_ignoreOtherRels() throws Exception {
context.turnOffAuthorisationSystem();
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, project1, isProjectOfPublication, -1, -1);
// Initialize MDVs and Relationships
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 1");
Relationship r1 = relationshipService.create(context, publication1, author1, isAuthorOfPublication, -1, -1);
Relationship r2 = relationshipService.create(context, publication1, author2, isAuthorOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur2 = relationshipService.create(context, publication1, project2, isProjectOfPublication, -1, -1);
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 2");
Relationship r3 = relationshipService.create(context, publication1, author3, isAuthorOfPublication, -1, -1);
// Move the first Author to leftPlace=3
relationshipService.move(context, r1, 3, null);
context.restoreAuthSystemState();
// Check relationship order
assertLeftPlace(r2, 1);
assertLeftPlace(r1, 3);
assertLeftPlace(r3, 4);
assertRelationMetadataOrder(publication1, isAuthorOfPublication, List.of(r2, r1, r3));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
assertLeftPlace(ur2, 1);
assertRightPlace(ur2, 0);
}
@Test @Test
public void moveUseForPlaceRelationshipDownToLeftPlaceInTheMiddleWithMetadataTest() throws Exception { public void moveUseForPlaceRelationshipDownToLeftPlaceInTheMiddleWithMetadataTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -1242,6 +1416,43 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
assertRelationMetadataOrder(publication1, isAuthorOfPublication, List.of(r1, r3, r2)); assertRelationMetadataOrder(publication1, isAuthorOfPublication, List.of(r1, r3, r2));
} }
@Test
public void moveUseForPlaceRelationshipDownToLeftPlaceInTheMiddleWithMetadataTest_ignoreOtherRels(
) throws Exception {
context.turnOffAuthorisationSystem();
// Initialize MDVs and Relationships
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 1");
Relationship r1 = relationshipService.create(context, publication1, author1, isAuthorOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, project1, isProjectOfPublication, -1, -1);
Relationship r2 = relationshipService.create(context, publication1, author2, isAuthorOfPublication, -1, -1);
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 2");
Relationship r3 = relationshipService.create(context, publication1, author3, isAuthorOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur2 = relationshipService.create(context, author2, project2, isProjectOfPerson, -1, -1);
// Move the last Author to leftPlace=2
relationshipService.move(context, r3, 2, null);
context.restoreAuthSystemState();
// Check relationship order
assertLeftPlace(r1, 1);
assertLeftPlace(r3, 2);
assertLeftPlace(r2, 3);
assertRelationMetadataOrder(publication1, isAuthorOfPublication, List.of(r1, r3, r2));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
assertLeftPlace(ur2, 0);
assertRightPlace(ur2, 0);
}
@Test @Test
public void moveUseForPlaceRelationshipToLeftPlaceAtTheEndWithMetadataTest() throws Exception { public void moveUseForPlaceRelationshipToLeftPlaceAtTheEndWithMetadataTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -1609,6 +1820,47 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r2, r1, r3)); assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r2, r1, r3));
} }
@Test
public void moveNonUseForPlaceRelationshipUpToRightPlaceInTheMiddleNoMetadataTest_ignoreOtherRels(
) throws Exception {
context.turnOffAuthorisationSystem();
// Add three Authors to the same Project, appending to the end
Relationship r1 = relationshipService.create(context, author1, project1, isProjectOfPerson, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, project1, isProjectOfPublication, -1, -1);
Relationship r2 = relationshipService.create(context, author2, project1, isProjectOfPerson, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur2 = relationshipService.create(context, publication2, project1, isProjectOfPublication, -1, -1);
Relationship r3 = relationshipService.create(context, author3, project1, isProjectOfPerson, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur3 = relationshipService.create(context, publication3, project1, isProjectOfPublication, -1, -1);
// Move the first Author to leftPlace=1
relationshipService.move(context, r1, null, 1);
context.restoreAuthSystemState();
// Check relationship order
assertRightPlace(r2, 0);
assertRightPlace(r1, 1);
assertRightPlace(r3, 2);
assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r2, r1, r3));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
assertLeftPlace(ur2, 0);
assertRightPlace(ur2, 1);
assertLeftPlace(ur3, 0);
assertRightPlace(ur3, 2);
}
@Test @Test
public void moveNonUseForPlaceRelationshipDownToRightPlaceInTheMiddleNoMetadataTest() throws Exception { public void moveNonUseForPlaceRelationshipDownToRightPlaceInTheMiddleNoMetadataTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -1630,6 +1882,36 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r1, r3, r2)); assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r1, r3, r2));
} }
@Test
public void moveNonUseForPlaceRelationshipDownToRightPlaceInTheMiddleNoMetadataTest_ignoreOtherRels(
) throws Exception {
context.turnOffAuthorisationSystem();
// Add three Authors to the same Project, appending to the end
Relationship r1 = relationshipService.create(context, author1, project1, isProjectOfPerson, -1, -1);
Relationship r2 = relationshipService.create(context, author2, project1, isProjectOfPerson, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, project1, isProjectOfPublication, -1, -1);
Relationship r3 = relationshipService.create(context, author3, project1, isProjectOfPerson, -1, -1);
// Move the last Author to leftPlace=1
relationshipService.move(context, r3, null, 1);
context.restoreAuthSystemState();
// Check relationship order
assertRightPlace(r1, 0);
assertRightPlace(r3, 1);
assertRightPlace(r2, 2);
assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r1, r3, r2));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
}
@Test @Test
public void moveNonUseForPlaceRelationshipToRightPlaceAtTheEndNoMetadataTest() throws Exception { public void moveNonUseForPlaceRelationshipToRightPlaceAtTheEndNoMetadataTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -1797,6 +2079,41 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
)); ));
} }
@Test
public void deleteUseForPlaceRelationshipFromLeftMiddleWithMetadataNoCopyTest_ignoreOtherRels() throws Exception {
context.turnOffAuthorisationSystem();
// Initialize MDVs and Relationships
Relationship r1 = relationshipService.create(context, publication1, author1, isAuthorOfPublication, -1, -1);
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 1");
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, project1, isProjectOfPublication, -1, -1);
Relationship r2 = relationshipService.create(context, publication1, author2, isAuthorOfPublication, -1, -1);
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 2");
Relationship r3 = relationshipService.create(context, publication1, author3, isAuthorOfPublication, -1, -1);
relationshipService.delete(context, r2, false, false);
context.restoreAuthSystemState();
// Check relationship order
assertLeftPlace(r1, 0);
assertLeftPlace(r3, 3);
assertRelationMetadataOrder(publication1, isAuthorOfPublication, Arrays.asList(r1, r3));
assertMetadataOrder(publication1, "dc.contributor.author", List.of(
"Author, First",
"MDV 1",
"MDV 2",
"Author, Third"
));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
}
@Test @Test
public void deleteUseForPlaceRelationshipFromLeftMiddleWithMetadataCopyTest() throws Exception { public void deleteUseForPlaceRelationshipFromLeftMiddleWithMetadataCopyTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -1826,6 +2143,55 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
)); ));
} }
@Test
public void deleteUseForPlaceRelationshipFromLeftMiddleWithMetadataCopyTest_ignoreOtherRels() throws Exception {
context.turnOffAuthorisationSystem();
// Initialize MDVs and Relationships
Relationship r1 = relationshipService.create(context, publication1, author1, isAuthorOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, project1, isProjectOfPublication, -1, -1);
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 1");
// NOTE: unrelated relationship => should not be affected
Relationship ur2 = relationshipService.create(context, publication1, project2, isProjectOfPublication, -1, -1);
Relationship r2 = relationshipService.create(context, publication1, author2, isAuthorOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur3 = relationshipService.create(context, author2, project1, isProjectOfPerson, -1, -1);
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 2");
Relationship r3 = relationshipService.create(context, publication1, author3, isAuthorOfPublication, -1, -1);
relationshipService.delete(context, r2, true, false);
context.restoreAuthSystemState();
// Check relationship order
assertLeftPlace(r1, 0);
// NOTE: since R2 has been removed, but copied to left, this place remains at 4 (instead of 3)
assertLeftPlace(r3, 4);
assertRelationMetadataOrder(publication1, isAuthorOfPublication, Arrays.asList(r1, null, r3));
assertMetadataOrder(publication1, "dc.contributor.author", List.of(
"Author, First",
"MDV 1",
"Author, Second", // this is not longer a relationship
"MDV 2",
"Author, Third"
));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
assertLeftPlace(ur2, 1);
assertRightPlace(ur2, 0);
assertLeftPlace(ur3, 0);
assertRightPlace(ur3, 0);
}
@Test @Test
public void deleteUseForPlaceRelationshipFromLeftEndWithMetadataNoCopyTest() throws Exception { public void deleteUseForPlaceRelationshipFromLeftEndWithMetadataNoCopyTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -2042,6 +2408,34 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r1, r3)); assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r1, r3));
} }
@Test
public void deleteNonUseForPlaceRelationshipFromRightMiddleNoMetadataTest_ignoreOtherRels() throws Exception {
context.turnOffAuthorisationSystem();
// Add three Authors to the same Project, appending to the end
Relationship r1 = relationshipService.create(context, author1, project1, isProjectOfPerson, -1, -1);
Relationship r2 = relationshipService.create(context, author2, project1, isProjectOfPerson, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, project1, isProjectOfPublication, -1, -1);
Relationship r3 = relationshipService.create(context, author3, project1, isProjectOfPerson, -1, -1);
// Delete the second Publication
relationshipService.delete(context, r2);
context.restoreAuthSystemState();
// Check relationship order
assertRightPlace(r1, 0);
assertRightPlace(r3, 1);
assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r1, r3));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
}
@Test @Test
public void deleteNonUseForPlaceRelationshipFromRightEndNoMetadataTest() throws Exception { public void deleteNonUseForPlaceRelationshipFromRightEndNoMetadataTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -2258,6 +2652,81 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
)); ));
} }
@Test
public void changeLeftItemInUseForPlaceRelationshipInTheMiddleWithMetadataTest_ignoreOtherRels() throws Exception {
context.turnOffAuthorisationSystem();
// Add three Authors to publication1, with regular MDVs in between
Relationship r1 = relationshipService.create(context, publication1, author1, isAuthorOfPublication, -1, -1);
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 1");
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, project1, isProjectOfPublication, -1, -1);
Relationship r2 = relationshipService.create(context, publication1, author2, isAuthorOfPublication, -1, -1);
itemService.addMetadata(context, publication1, dcSchema, contributorElement, authorQualifier, null, "MDV 2");
// NOTE: unrelated relationship => should not be affected
Relationship ur2 = relationshipService.create(context, publication1, project3, isProjectOfPublication, -1, -1);
Relationship r3 = relationshipService.create(context, publication1, author3, isAuthorOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur3 = relationshipService.create(context, publication2, project2, isProjectOfPublication, -1, -1);
// Add three Authors to publication2, with regular MDVs in between
itemService.addMetadata(context, publication2, dcSchema, contributorElement, authorQualifier, null, "MDV 3");
Relationship r4 = relationshipService.create(context, publication2, author4, isAuthorOfPublication, -1, -1);
Relationship r5 = relationshipService.create(context, publication2, author5, isAuthorOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur4 = relationshipService.create(context, publication2, project1, isProjectOfPublication, -1, -1);
itemService.addMetadata(context, publication2, dcSchema, contributorElement, authorQualifier, null, "MDV 4");
Relationship r6 = relationshipService.create(context, publication2, author6, isAuthorOfPublication, -1, -1);
// Move r2 to publication 2
relationshipService.move(context, r2, publication2, null);
context.restoreAuthSystemState();
// Check relationship order for publication1
assertLeftPlace(r1, 0); // should both move down as the first Relationship was removed
assertLeftPlace(r3, 3);
assertRelationMetadataOrder(publication1, isAuthorOfPublication, List.of(r1, r3));
assertMetadataOrder(publication1, "dc.contributor.author", List.of(
"Author, First",
"MDV 1",
"MDV 2",
"Author, Third"
));
// Check relationship order for publication2
assertLeftPlace(r4, 1); // previous Relationships should stay where they were
assertLeftPlace(r5, 2);
assertLeftPlace(r6, 4);
assertLeftPlace(r2, 5); // moved Relationship should be appended to the end
assertRelationMetadataOrder(publication2, isAuthorOfPublication, List.of(r4, r5, r6, r2));
assertMetadataOrder(publication2, "dc.contributor.author", List.of(
"MDV 3",
"Author, Fourth",
"Author, Fifth",
"MDV 4",
"Author, Sixth",
"Author, Second"
));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
assertLeftPlace(ur2, 1);
assertRightPlace(ur2, 0);
assertLeftPlace(ur3, 0);
assertRightPlace(ur3, 0);
assertLeftPlace(ur4, 1);
assertRightPlace(ur4, 1);
}
@Test @Test
public void changeLeftItemInUseForPlaceRelationshipAtTheEndWithMetadataTest() throws Exception { public void changeLeftItemInUseForPlaceRelationshipAtTheEndWithMetadataTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -2372,6 +2841,51 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
assertRelationMetadataOrder(author2, isAuthorOfPublication, List.of(r4, r5, r6, r2)); assertRelationMetadataOrder(author2, isAuthorOfPublication, List.of(r4, r5, r6, r2));
} }
@Test
public void changeRightItemInUseForPlaceRelationshipInTheMiddleNoMetadataTest_ignoreOtherRels() throws Exception {
context.turnOffAuthorisationSystem();
// Add three Publications to author1, appending to the end
Relationship r1 = relationshipService.create(context, publication1, author1, isAuthorOfPublication, -1, -1);
Relationship r2 = relationshipService.create(context, publication2, author1, isAuthorOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, author1, project1, isProjectOfPerson, -1, -1);
Relationship r3 = relationshipService.create(context, publication3, author1, isAuthorOfPublication, -1, -1);
// Add three Publications to author2, appending to the end
Relationship r4 = relationshipService.create(context, publication4, author2, isAuthorOfPublication, -1, -1);
Relationship r5 = relationshipService.create(context, publication5, author2, isAuthorOfPublication, -1, -1);
Relationship r6 = relationshipService.create(context, publication6, author2, isAuthorOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur2 = relationshipService.create(context, author2, project1, isProjectOfPerson, -1, -1);
// Move r2 to author2
relationshipService.move(context, r2, null, author2);
context.restoreAuthSystemState();
// Check relationship order for author1
assertRightPlace(r1, 0);
assertRightPlace(r3, 1); // should move down as the first Relationship was removed
assertRelationMetadataOrder(author1, isAuthorOfPublication, List.of(r1, r3));
// Check relationship order for author2
assertRightPlace(r4, 0); // previous Relationships should stay where they were
assertRightPlace(r5, 1);
assertRightPlace(r6, 2);
assertRightPlace(r2, 3); // moved Relationship should be appended to the end
assertRelationMetadataOrder(author2, isAuthorOfPublication, List.of(r4, r5, r6, r2));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
assertLeftPlace(ur2, 0);
assertRightPlace(ur2, 1);
}
@Test @Test
public void changeRightItemInUseForPlaceRelationshipAtTheEndNoMetadataTest() throws Exception { public void changeRightItemInUseForPlaceRelationshipAtTheEndNoMetadataTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -2564,6 +3078,57 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
assertRelationMetadataOrder(project2, isProjectOfPerson, List.of(r4, r5, r6, r2)); assertRelationMetadataOrder(project2, isProjectOfPerson, List.of(r4, r5, r6, r2));
} }
@Test
public void changeRightItemInNonUseForPlaceRelationshipInTheMiddleTest_ignoreOtherRels() throws Exception {
context.turnOffAuthorisationSystem();
// Add three Authors to project1, appending to the end
Relationship r1 = relationshipService.create(context, author1, project1, isProjectOfPerson, -1, -1);
Relationship r2 = relationshipService.create(context, author2, project1, isProjectOfPerson, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur1 = relationshipService.create(context, publication1, project1, isProjectOfPublication, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur2 = relationshipService.create(context, publication2, project1, isProjectOfPublication, -1, -1);
Relationship r3 = relationshipService.create(context, author3, project1, isProjectOfPerson, -1, -1);
// Add three Authors to project2, appending to the end
Relationship r4 = relationshipService.create(context, author4, project2, isProjectOfPerson, -1, -1);
Relationship r5 = relationshipService.create(context, author5, project2, isProjectOfPerson, -1, -1);
// NOTE: unrelated relationship => should not be affected
Relationship ur3 = relationshipService.create(context, author5, project3, isProjectOfPerson, -1, -1);
Relationship r6 = relationshipService.create(context, author6, project2, isProjectOfPerson, -1, -1);
// Move r2 to project2
relationshipService.move(context, r2, null, project2);
context.restoreAuthSystemState();
// Check relationship order for project1
assertRightPlace(r1, 0);
assertRightPlace(r3, 1); // should move down as the first Relationship was removed
assertRelationMetadataOrder(project1, isProjectOfPerson, List.of(r1, r3));
// Check relationship order for project2
assertRightPlace(r4, 0); // previous Relationships should stay where they were
assertRightPlace(r5, 1);
assertRightPlace(r6, 2);
assertRightPlace(r2, 3); // moved Relationship should be appended to the end
assertRelationMetadataOrder(project2, isProjectOfPerson, List.of(r4, r5, r6, r2));
// check unaffected relationships
assertLeftPlace(ur1, 0);
assertRightPlace(ur1, 0);
assertLeftPlace(ur2, 0);
assertRightPlace(ur2, 1);
assertLeftPlace(ur3, 1);
assertRightPlace(ur3, 0);
}
@Test @Test
public void changeRightItemInNonUseForPlaceRelationshipAtTheEndTest() throws Exception { public void changeRightItemInNonUseForPlaceRelationshipAtTheEndTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -2753,7 +3318,7 @@ public class RelationshipServiceImplPlaceTest extends AbstractUnitTest {
} }
private String getRelationshipTypeStringForEntity(RelationshipType relationshipType, Item item) { private String getRelationshipTypeStringForEntity(RelationshipType relationshipType, Item item) {
String entityType = relationshipMetadataService.getEntityTypeStringFromMetadata(item); String entityType = itemService.getEntityTypeLabel(item);
if (StringUtils.equals(entityType, relationshipType.getLeftType().getLabel())) { if (StringUtils.equals(entityType, relationshipType.getLeftType().getLabel())) {
return relationshipType.getLeftwardType(); return relationshipType.getLeftwardType();

View File

@@ -64,6 +64,9 @@ public class ItemServiceTest extends AbstractIntegrationTestWithDatabase {
String authorQualifier = "author"; String authorQualifier = "author";
String contributorElement = "contributor"; String contributorElement = "contributor";
String dcSchema = "dc"; String dcSchema = "dc";
String subjectElement = "subject";
String descriptionElement = "description";
String abstractQualifier = "abstract";
/** /**
* This method will be run before every test as per @Before. It will * This method will be run before every test as per @Before. It will
@@ -152,6 +155,111 @@ public class ItemServiceTest extends AbstractIntegrationTestWithDatabase {
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, three", null, 3, list.get(3)); assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, three", null, 3, list.get(3));
} }
@Test
public void InsertAndMoveMetadataShiftPlaceTest_complex() throws Exception {
context.turnOffAuthorisationSystem();
// Here we add the first set of metadata to the item
itemService.addMetadata(context, item, dcSchema, contributorElement, authorQualifier, null, "test, one");
// NOTE: dc.subject should NOT affect dc.contributor.author
itemService.addMetadata(context, item, dcSchema, subjectElement, null, null, "test, sub1");
// NOTE: dc.subject should NOT affect dc.contributor.author
itemService.addMetadata(context, item, dcSchema, subjectElement, null, null, "test, sub2");
itemService.addMetadata(context, item, dcSchema, contributorElement, authorQualifier, null, "test, two");
itemService.addMetadata(context, item, dcSchema, contributorElement, authorQualifier, null, "test, three");
// NOTE: dc.description.abstract should NOT affect dc.contributor.author
itemService.addMetadata(context, item, dcSchema, descriptionElement, abstractQualifier, null, "test, abs1");
context.restoreAuthSystemState();
// The code below performs the mentioned assertions to ensure the place is correct
List<MetadataValue> list1 = itemService
.getMetadata(item, dcSchema, contributorElement, authorQualifier, Item.ANY);
assertThat(list1.size(), equalTo(3));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, one", null, 0, list1.get(0));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, two", null, 1, list1.get(1));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, three", null, 2, list1.get(2));
List<MetadataValue> list2 = itemService
.getMetadata(item, dcSchema, subjectElement, null, Item.ANY);
assertThat(list2.size(), equalTo(2));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub1", null, 0, list2.get(0));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub2", null, 1, list2.get(1));
List<MetadataValue> list3 = itemService
.getMetadata(item, dcSchema, descriptionElement, abstractQualifier, Item.ANY);
assertThat(list3.size(), equalTo(1));
assertMetadataValue(abstractQualifier, descriptionElement, dcSchema, "test, abs1", null, 0, list3.get(0));
context.turnOffAuthorisationSystem();
// This is where we add metadata at place=1
itemService.addAndShiftRightMetadata(
context, item, dcSchema, contributorElement, authorQualifier, null, "test, four", null, -1, 1
);
// Here we retrieve the list of metadata again to perform the assertions on the places below as mentioned
List<MetadataValue> list4 = itemService
.getMetadata(item, dcSchema, contributorElement, authorQualifier, Item.ANY)
.stream()
.sorted(Comparator.comparingInt(MetadataValue::getPlace))
.collect(Collectors.toList());
assertThat(list4.size(), equalTo(4));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, one", null, 0, list4.get(0));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, four", null, 1, list4.get(1));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, two", null, 2, list4.get(2));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, three", null, 3, list4.get(3));
List<MetadataValue> list5 = itemService
.getMetadata(item, dcSchema, subjectElement, null, Item.ANY);
assertThat(list5.size(), equalTo(2));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub1", null, 0, list5.get(0));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub2", null, 1, list5.get(1));
List<MetadataValue> list6 = itemService
.getMetadata(item, dcSchema, descriptionElement, abstractQualifier, Item.ANY);
assertThat(list3.size(), equalTo(1));
assertMetadataValue(abstractQualifier, descriptionElement, dcSchema, "test, abs1", null, 0, list6.get(0));
// And move metadata from place=2 to place=0
itemService.moveMetadata(context, item, dcSchema, contributorElement, authorQualifier, 2, 0);
context.restoreAuthSystemState();
// Here we retrieve the list of metadata again to perform the assertions on the places below as mentioned
List<MetadataValue> list7 = itemService
.getMetadata(item, dcSchema, contributorElement, authorQualifier, Item.ANY)
.stream()
.sorted(Comparator.comparingInt(MetadataValue::getPlace))
.collect(Collectors.toList());
assertThat(list7.size(), equalTo(4));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, two", null, 0, list7.get(0));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, one", null, 1, list7.get(1));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, four", null, 2, list7.get(2));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, three", null, 3, list7.get(3));
List<MetadataValue> list8 = itemService
.getMetadata(item, dcSchema, subjectElement, null, Item.ANY);
assertThat(list8.size(), equalTo(2));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub1", null, 0, list8.get(0));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub2", null, 1, list8.get(1));
List<MetadataValue> list9 = itemService
.getMetadata(item, dcSchema, descriptionElement, abstractQualifier, Item.ANY);
assertThat(list9.size(), equalTo(1));
assertMetadataValue(abstractQualifier, descriptionElement, dcSchema, "test, abs1", null, 0, list9.get(0));
}
@Test @Test
public void InsertAndMoveMetadataOnePlaceForwardTest() throws Exception { public void InsertAndMoveMetadataOnePlaceForwardTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
@@ -207,6 +315,112 @@ public class ItemServiceTest extends AbstractIntegrationTestWithDatabase {
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, three", null, 3, list.get(3)); assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, three", null, 3, list.get(3));
} }
@Test
public void InsertAndMoveMetadataOnePlaceForwardTest_complex() throws Exception {
context.turnOffAuthorisationSystem();
// NOTE: dc.description.abstract should NOT affect dc.contributor.author
itemService.addMetadata(context, item, dcSchema, descriptionElement, abstractQualifier, null, "test, abs1");
// Here we add the first set of metadata to the item
itemService.addMetadata(context, item, dcSchema, contributorElement, authorQualifier, null, "test, one");
// NOTE: dc.subject should NOT affect dc.contributor.author
itemService.addMetadata(context, item, dcSchema, subjectElement, null, null, "test, sub1");
itemService.addMetadata(context, item, dcSchema, contributorElement, authorQualifier, null, "test, two");
itemService.addMetadata(context, item, dcSchema, contributorElement, authorQualifier, null, "test, three");
// NOTE: dc.subject should NOT affect dc.contributor.author
itemService.addMetadata(context, item, dcSchema, subjectElement, null, null, "test, sub2");
context.restoreAuthSystemState();
// The code below performs the mentioned assertions to ensure the place is correct
List<MetadataValue> list1 = itemService
.getMetadata(item, dcSchema, contributorElement, authorQualifier, Item.ANY);
assertThat(list1.size(), equalTo(3));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, one", null, 0, list1.get(0));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, two", null, 1, list1.get(1));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, three", null, 2, list1.get(2));
List<MetadataValue> list2 = itemService
.getMetadata(item, dcSchema, subjectElement, null, Item.ANY);
assertThat(list2.size(), equalTo(2));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub1", null, 0, list2.get(0));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub2", null, 1, list2.get(1));
List<MetadataValue> list3 = itemService
.getMetadata(item, dcSchema, descriptionElement, abstractQualifier, Item.ANY);
assertThat(list3.size(), equalTo(1));
assertMetadataValue(abstractQualifier, descriptionElement, dcSchema, "test, abs1", null, 0, list3.get(0));
context.turnOffAuthorisationSystem();
// This is where we add metadata at place=1
itemService.addAndShiftRightMetadata(
context, item, dcSchema, contributorElement, authorQualifier, null, "test, four", null, -1, 1
);
// Here we retrieve the list of metadata again to perform the assertions on the places below as mentioned
List<MetadataValue> list4 = itemService
.getMetadata(item, dcSchema, contributorElement, authorQualifier, Item.ANY)
.stream()
.sorted(Comparator.comparingInt(MetadataValue::getPlace))
.collect(Collectors.toList());
assertThat(list4.size(), equalTo(4));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, one", null, 0, list4.get(0));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, four", null, 1, list4.get(1));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, two", null, 2, list4.get(2));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, three", null, 3, list4.get(3));
List<MetadataValue> list5 = itemService
.getMetadata(item, dcSchema, subjectElement, null, Item.ANY);
assertThat(list5.size(), equalTo(2));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub1", null, 0, list5.get(0));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub2", null, 1, list5.get(1));
List<MetadataValue> list6 = itemService
.getMetadata(item, dcSchema, descriptionElement, abstractQualifier, Item.ANY);
assertThat(list6.size(), equalTo(1));
assertMetadataValue(abstractQualifier, descriptionElement, dcSchema, "test, abs1", null, 0, list6.get(0));
// And move metadata from place=1 to place=2
itemService.moveMetadata(context, item, dcSchema, contributorElement, authorQualifier, 1, 2);
context.restoreAuthSystemState();
// Here we retrieve the list of metadata again to perform the assertions on the places below as mentioned
List<MetadataValue> list7 = itemService
.getMetadata(item, dcSchema, contributorElement, authorQualifier, Item.ANY)
.stream()
.sorted(Comparator.comparingInt(MetadataValue::getPlace))
.collect(Collectors.toList());
assertThat(list7.size(), equalTo(4));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, one", null, 0, list7.get(0));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, two", null, 1, list7.get(1));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, four", null, 2, list7.get(2));
assertMetadataValue(authorQualifier, contributorElement, dcSchema, "test, three", null, 3, list7.get(3));
List<MetadataValue> list8 = itemService
.getMetadata(item, dcSchema, subjectElement, null, Item.ANY);
assertThat(list8.size(), equalTo(2));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub1", null, 0, list8.get(0));
assertMetadataValue(null, subjectElement, dcSchema, "test, sub2", null, 1, list8.get(1));
List<MetadataValue> list9 = itemService
.getMetadata(item, dcSchema, descriptionElement, abstractQualifier, Item.ANY);
assertThat(list9.size(), equalTo(1));
assertMetadataValue(abstractQualifier, descriptionElement, dcSchema, "test, abs1", null, 0, list9.get(0));
}
@Test @Test
public void testDeleteItemWithMultipleVersions() throws Exception { public void testDeleteItemWithMultipleVersions() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();

View File

@@ -10,7 +10,6 @@ import java.sql.SQLException;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.dspace.app.rest.authorization.AuthorizationFeature; import org.dspace.app.rest.authorization.AuthorizationFeature;
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation; import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
import org.dspace.app.rest.model.BaseObjectRest; import org.dspace.app.rest.model.BaseObjectRest;
@@ -58,13 +57,6 @@ public class CanCreateVersionFeature implements AuthorizationFeature {
} }
Item item = itemService.find(context, UUID.fromString(((ItemRest) object).getUuid())); Item item = itemService.find(context, UUID.fromString(((ItemRest) object).getUuid()));
if (Objects.nonNull(item)) { if (Objects.nonNull(item)) {
// The property versioning.block.entity is used to disable versioning for items with EntityType
boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
boolean hasEntityType = StringUtils.isNotBlank(itemService.
getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY));
if (isBlockEntity && hasEntityType) {
return false;
}
if (authorizeService.isAdmin(context, item)) { if (authorizeService.isAdmin(context, item)) {
return true; return true;
} }

View File

@@ -9,14 +9,12 @@ package org.dspace.app.rest.authorization.impl;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation; import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
import org.dspace.app.rest.converter.ItemConverter; import org.dspace.app.rest.converter.ItemConverter;
import org.dspace.app.rest.model.BaseObjectRest; import org.dspace.app.rest.model.BaseObjectRest;
import org.dspace.app.rest.model.ItemRest; import org.dspace.app.rest.model.ItemRest;
import org.dspace.app.rest.model.VersionRest; import org.dspace.app.rest.model.VersionRest;
import org.dspace.app.rest.projection.DefaultProjection; import org.dspace.app.rest.projection.DefaultProjection;
import org.dspace.content.Item;
import org.dspace.content.service.ItemService; import org.dspace.content.service.ItemService;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.services.ConfigurationService; import org.dspace.services.ConfigurationService;
@@ -57,12 +55,6 @@ public class CanDeleteVersionFeature extends DeleteFeature {
Version version = versioningService.getVersion(context, ((VersionRest)object).getId()); Version version = versioningService.getVersion(context, ((VersionRest)object).getId());
if (Objects.nonNull(version) && Objects.nonNull(version.getItem())) { if (Objects.nonNull(version) && Objects.nonNull(version.getItem())) {
ItemRest itemRest = itemConverter.convert(version.getItem(), DefaultProjection.DEFAULT); ItemRest itemRest = itemConverter.convert(version.getItem(), DefaultProjection.DEFAULT);
boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
boolean hasEntityType = StringUtils.isNotBlank(
itemService.getMetadataFirstValue(version.getItem(), "dspace", "entity", "type", Item.ANY));
if (isBlockEntity && hasEntityType) {
return false;
}
return super.isAuthorized(context, itemRest); return super.isAuthorized(context, itemRest);
} }
} }

View File

@@ -9,14 +9,11 @@ package org.dspace.app.rest.authorization.impl;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.dspace.app.rest.authorization.AuthorizationFeature; import org.dspace.app.rest.authorization.AuthorizationFeature;
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation; import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
import org.dspace.app.rest.model.BaseObjectRest; import org.dspace.app.rest.model.BaseObjectRest;
import org.dspace.app.rest.model.VersionRest; import org.dspace.app.rest.model.VersionRest;
import org.dspace.authorize.service.AuthorizeService; import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Item;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.services.ConfigurationService; import org.dspace.services.ConfigurationService;
import org.dspace.versioning.Version; import org.dspace.versioning.Version;
@@ -37,8 +34,6 @@ public class CanEditVersionFeature implements AuthorizationFeature {
public static final String NAME = "canEditVersion"; public static final String NAME = "canEditVersion";
@Autowired
private ItemService itemService;
@Autowired @Autowired
private AuthorizeService authorizeService; private AuthorizeService authorizeService;
@Autowired @Autowired
@@ -56,12 +51,6 @@ public class CanEditVersionFeature implements AuthorizationFeature {
} }
Version version = versioningService.getVersion(context, (((VersionRest) object).getId())); Version version = versioningService.getVersion(context, (((VersionRest) object).getId()));
if (Objects.nonNull(version) && Objects.nonNull(version.getItem())) { if (Objects.nonNull(version) && Objects.nonNull(version.getItem())) {
boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
boolean hasEntityType = StringUtils.isNotBlank(
itemService.getMetadataFirstValue(version.getItem(), "dspace", "entity", "type", Item.ANY));
if (isBlockEntity && hasEntityType) {
return false;
}
return authorizeService.isAdmin(context, version.getItem()); return authorizeService.isAdmin(context, version.getItem());
} }
} }

View File

@@ -10,7 +10,6 @@ import java.sql.SQLException;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.dspace.app.rest.authorization.AuthorizationFeature; import org.dspace.app.rest.authorization.AuthorizationFeature;
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation; import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation;
import org.dspace.app.rest.model.BaseObjectRest; import org.dspace.app.rest.model.BaseObjectRest;
@@ -54,12 +53,6 @@ public class CanManageVersionsFeature implements AuthorizationFeature {
} }
Item item = itemService.find(context, UUID.fromString(((ItemRest) object).getUuid())); Item item = itemService.find(context, UUID.fromString(((ItemRest) object).getUuid()));
if (Objects.nonNull(item)) { if (Objects.nonNull(item)) {
boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
boolean hasEntityType = StringUtils.isNotBlank(itemService.
getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY));
if (isBlockEntity && hasEntityType) {
return false;
}
return authorizeService.isAdmin(context, item); return authorizeService.isAdmin(context, item);
} }
} }

View File

@@ -110,10 +110,6 @@ public class VersionRestRepository extends DSpaceRestRepository<VersionRest, Int
throw new UnprocessableEntityException("The given URI list could not be properly parsed to one result"); throw new UnprocessableEntityException("The given URI list could not be properly parsed to one result");
} }
boolean hasEntityType = StringUtils.isNotBlank(itemService.
getMetadataFirstValue(item, "dspace", "entity", "type", Item.ANY));
boolean isBlockEntity = configurationService.getBooleanProperty("versioning.block.entity", true);
EPerson submitter = item.getSubmitter(); EPerson submitter = item.getSubmitter();
boolean isAdmin = authorizeService.isAdmin(context); boolean isAdmin = authorizeService.isAdmin(context);
boolean canCreateVersion = configurationService.getBooleanProperty("versioning.submitterCanCreateNewVersion"); boolean canCreateVersion = configurationService.getBooleanProperty("versioning.submitterCanCreateNewVersion");
@@ -121,10 +117,6 @@ public class VersionRestRepository extends DSpaceRestRepository<VersionRest, Int
if (!isAdmin && !(canCreateVersion && Objects.equals(submitter, context.getCurrentUser()))) { if (!isAdmin && !(canCreateVersion && Objects.equals(submitter, context.getCurrentUser()))) {
throw new AuthorizeException("The logged user doesn't have the rights to create a new version."); throw new AuthorizeException("The logged user doesn't have the rights to create a new version.");
} }
if (hasEntityType && isBlockEntity) {
throw new AuthorizeException("You are trying to create a new version for an entity" +
" which is blocked by the configuration");
}
WorkflowItem workflowItem = null; WorkflowItem workflowItem = null;
WorkspaceItem workspaceItem = null; WorkspaceItem workspaceItem = null;

View File

@@ -722,38 +722,7 @@ public class VersionRestRepositoryIT extends AbstractControllerIntegrationTest {
} }
@Test @Test
public void createFirstVersionItemWithentityTypeByAdminAndPropertyBlockEntityEnableTest() throws Exception { public void createFirstVersionItemWithEntityTypeTest() throws Exception {
configurationService.setProperty("versioning.block.entity", true);
context.turnOffAuthorisationSystem();
Community rootCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col = CollectionBuilder.createCollection(context, rootCommunity)
.withName("Collection 1")
.withEntityType("Publication")
.build();
Item itemA = ItemBuilder.createItem(context, col)
.withTitle("Public item")
.withIssueDate("2021-04-19")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
context.restoreAuthSystemState();
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(post("/api/versioning/versions")
.param("summary", "test summary!")
.contentType(MediaType.parseMediaType(RestMediaTypes.TEXT_URI_LIST_VALUE))
.content("/api/core/items/" + itemA.getID()))
.andExpect(status().isForbidden());
}
@Test
public void createFirstVersionItemWithEntityTypeAndPropertyBlockEntityDisabledTest() throws Exception {
configurationService.setProperty("versioning.block.entity", false);
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context) parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community") .withName("Parent Community")
@@ -795,9 +764,8 @@ public class VersionRestRepositoryIT extends AbstractControllerIntegrationTest {
} }
@Test @Test
public void createFirstVersionItemWithEntityTypeBySubmitterAndPropertyBlockEntityDisabledTest() throws Exception { public void createFirstVersionItemWithEntityTypeBySubmitterTest() throws Exception {
configurationService.setProperty("versioning.submitterCanCreateNewVersion", true); configurationService.setProperty("versioning.submitterCanCreateNewVersion", true);
configurationService.setProperty("versioning.block.entity", false);
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
Community rootCommunity = CommunityBuilder.createCommunity(context) Community rootCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community") .withName("Parent Community")

View File

@@ -304,57 +304,9 @@ public class CanCreateVersionFeatureIT extends AbstractControllerIntegrationTest
} }
@Test @Test
public void checkCanCreateVersionFeatureAndPropertyBlockEntityEnableTest() throws Exception { public void checkCanCreateVersionFeatureTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
configurationService.setProperty("versioning.block.entity", true);
Community rootCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col = CollectionBuilder.createCollection(context, rootCommunity)
.withName("Collection 1")
.withEntityType("Publication")
.withAdminGroup(eperson)
.build();
Item itemA = ItemBuilder.createItem(context, col)
.withTitle("Public item")
.withIssueDate("2021-04-19")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
context.restoreAuthSystemState();
ItemRest itemRestA = itemConverter.convert(itemA, DefaultProjection.DEFAULT);
String tokenEPerson = getAuthToken(eperson.getEmail(), password);
String tokenAdmin = getAuthToken(admin.getEmail(), password);
String tokenUser = getAuthToken(user.getEmail(), password);
// define authorization that we know not exists
Authorization user2ItemA = new Authorization(user, canCreateVersionFeature, itemRestA);
Authorization admin2ItemA = new Authorization(admin, canCreateVersionFeature, itemRestA);
Authorization eperson2ItemA = new Authorization(eperson, canCreateVersionFeature, itemRestA);
getClient(tokenAdmin).perform(get("/api/authz/authorizations/" + admin2ItemA.getID()))
.andExpect(status().isNotFound());
getClient(tokenUser).perform(get("/api/authz/authorizations/" + user2ItemA.getID()))
.andExpect(status().isNotFound());
getClient(tokenEPerson).perform(get("/api/authz/authorizations/" + eperson2ItemA.getID()))
.andExpect(status().isNotFound());
}
@Test
public void checkCanCreateVersionFeatureAndPropertyBlockEntityDisabledTest() throws Exception {
context.turnOffAuthorisationSystem();
configurationService.setProperty("versioning.block.entity", false);
Community rootCommunity = CommunityBuilder.createCommunity(context) Community rootCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community") .withName("Parent Community")
.build(); .build();
@@ -396,51 +348,4 @@ public class CanCreateVersionFeatureIT extends AbstractControllerIntegrationTest
.andExpect(status().isNotFound()); .andExpect(status().isNotFound());
} }
@Test
public void checkCanCreateVersionFeatureAndPropertyBlockEntityUnsetedTest() throws Exception {
context.turnOffAuthorisationSystem();
configurationService.setProperty("versioning.submitterCanCreateNewVersion", true);
configurationService.setProperty("versioning.block.entity", null);
Community rootCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col = CollectionBuilder.createCollection(context, rootCommunity)
.withName("Collection 1")
.withEntityType("Publication")
.withSubmitterGroup(eperson)
.build();
Item itemA = ItemBuilder.createItem(context, col)
.withTitle("Public item")
.withIssueDate("2021-04-19")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
context.restoreAuthSystemState();
ItemRest itemRestA = itemConverter.convert(itemA, DefaultProjection.DEFAULT);
String tokenEPerson = getAuthToken(eperson.getEmail(), password);
String tokenAdmin = getAuthToken(admin.getEmail(), password);
String tokenUser = getAuthToken(user.getEmail(), password);
// define authorization that we know not exists
Authorization user2ItemA = new Authorization(user, canCreateVersionFeature, itemRestA);
Authorization admin2ItemA = new Authorization(admin, canCreateVersionFeature, itemRestA);
Authorization eperson2ItemA = new Authorization(eperson, canCreateVersionFeature, itemRestA);
getClient(tokenAdmin).perform(get("/api/authz/authorizations/" + admin2ItemA.getID()))
.andExpect(status().isNotFound());
getClient(tokenUser).perform(get("/api/authz/authorizations/" + user2ItemA.getID()))
.andExpect(status().isNotFound());
getClient(tokenEPerson).perform(get("/api/authz/authorizations/" + eperson2ItemA.getID()))
.andExpect(status().isNotFound());
}
} }

View File

@@ -28,7 +28,6 @@ import org.dspace.content.Item;
import org.dspace.content.WorkspaceItem; import org.dspace.content.WorkspaceItem;
import org.dspace.content.service.WorkspaceItemService; import org.dspace.content.service.WorkspaceItemService;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.services.ConfigurationService;
import org.dspace.versioning.Version; import org.dspace.versioning.Version;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Before; import org.junit.Before;
@@ -47,8 +46,6 @@ public class CanDeleteVersionFeatureIT extends AbstractControllerIntegrationTest
@Autowired @Autowired
private WorkspaceItemService workspaceItemService; private WorkspaceItemService workspaceItemService;
@Autowired @Autowired
private ConfigurationService configurationService;
@Autowired
private AuthorizationFeatureService authorizationFeatureService; private AuthorizationFeatureService authorizationFeatureService;
@Autowired @Autowired
private org.dspace.content.service.InstallItemService installItemService; private org.dspace.content.service.InstallItemService installItemService;
@@ -259,59 +256,9 @@ public class CanDeleteVersionFeatureIT extends AbstractControllerIntegrationTest
} }
@Test @Test
public void canDeleteVersionFeatureAndPropertyBlockEntityEnableTest() throws Exception { public void canDeleteVersionFeatureTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
configurationService.setProperty("versioning.block.entity", true);
Community rootCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col = CollectionBuilder.createCollection(context, rootCommunity)
.withName("Collection 1")
.withEntityType("Publication")
.build();
Item itemA = ItemBuilder.createItem(context, col)
.withTitle("Public item")
.withIssueDate("2021-04-19")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
Version version = VersionBuilder.createVersion(context, itemA, "My test summary").build();
WorkspaceItem workspaceItem = workspaceItemService.findByItem(context, version.getItem());
installItemService.installItem(context, workspaceItem);
context.restoreAuthSystemState();
VersionRest versionRest = versionConverter.convert(version, DefaultProjection.DEFAULT);
String tokenEPerson = getAuthToken(eperson.getEmail(), password);
String tokenAdmin = getAuthToken(admin.getEmail(), password);
// define authorization that we know not exists
Authorization admin2ItemA = new Authorization(admin, canDeleteVersionFeature, versionRest);
Authorization eperson2ItemA = new Authorization(eperson, canDeleteVersionFeature, versionRest);
Authorization anonymous2ItemA = new Authorization(null, canDeleteVersionFeature, versionRest);
getClient(tokenAdmin).perform(get("/api/authz/authorizations/" + admin2ItemA.getID()))
.andExpect(status().isNotFound());
getClient(tokenEPerson).perform(get("/api/authz/authorizations/" + eperson2ItemA.getID()))
.andExpect(status().isNotFound());
getClient().perform(get("/api/authz/authorizations/" + anonymous2ItemA.getID()))
.andExpect(status().isNotFound());
}
@Test
public void canDeleteVersionFeatureAndPropertyBlockEntityDisabledTest() throws Exception {
context.turnOffAuthorisationSystem();
configurationService.setProperty("versioning.block.entity", false);
Community rootCommunity = CommunityBuilder.createCommunity(context) Community rootCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community") .withName("Parent Community")
.build(); .build();

View File

@@ -202,70 +202,7 @@ public class CanEditVersionFeatureIT extends AbstractControllerIntegrationTest {
} }
@Test @Test
public void canEditVersionsFeatureByColAndComAdminsAndPropertyBlockEntityEnableTest() throws Exception { public void canEditVersionsFeatureByColAndComAdminsTest2() throws Exception {
configurationService.setProperty("versioning.block.entity", true);
context.turnOffAuthorisationSystem();
EPerson adminComA = EPersonBuilder.createEPerson(context)
.withEmail("testComAdminA@test.com")
.withPassword(password)
.build();
EPerson adminCol1 = EPersonBuilder.createEPerson(context)
.withEmail("testCol1Admin@test.com")
.withPassword(password)
.build();
Community rootCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community subCommunityA = CommunityBuilder.createSubCommunity(context, rootCommunity)
.withName("Sub Community A")
.withAdminGroup(adminComA)
.build();
Collection col1 = CollectionBuilder.createCollection(context, subCommunityA)
.withName("Collection 1")
.withEntityType("Publication")
.withSubmitterGroup(eperson)
.withAdminGroup(adminCol1)
.build();
Item item = ItemBuilder.createItem(context, col1)
.withTitle("Public item")
.withIssueDate("2021-04-19")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
Version version = VersionBuilder.createVersion(context, item, "My test summary").build();
context.restoreAuthSystemState();
VersionRest versionRest = versionConverter.convert(version, DefaultProjection.DEFAULT);
String tokenAdmin = getAuthToken(admin.getEmail(), password);
String tokenAdminComA = getAuthToken(adminComA.getEmail(), password);
String tokenAdminCol1 = getAuthToken(adminCol1.getEmail(), password);
// define authorization that we know not exists
Authorization adminOfComAToVersion = new Authorization(adminComA, canEditVersionFeature, versionRest);
Authorization adminOfCol1ToVersion = new Authorization(adminCol1, canEditVersionFeature, versionRest);
Authorization adminToVersion = new Authorization(admin, canEditVersionFeature, versionRest);
getClient(tokenAdminComA).perform(get("/api/authz/authorizations/" + adminOfComAToVersion.getID()))
.andExpect(status().isNotFound());
getClient(tokenAdminCol1).perform(get("/api/authz/authorizations/" + adminOfCol1ToVersion.getID()))
.andExpect(status().isNotFound());
getClient(tokenAdmin).perform(get("/api/authz/authorizations/" + adminToVersion.getID()))
.andExpect(status().isNotFound());
}
@Test
public void canEditVersionsFeatureByColAndComAdminsAndPropertyBlockEntityDisabledTest() throws Exception {
configurationService.setProperty("versioning.block.entity", false);
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
EPerson adminComA = EPersonBuilder.createEPerson(context) EPerson adminComA = EPersonBuilder.createEPerson(context)
.withEmail("testComAdminA@test.com") .withEmail("testComAdminA@test.com")

View File

@@ -28,7 +28,6 @@ import org.dspace.content.Collection;
import org.dspace.content.Community; import org.dspace.content.Community;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.services.ConfigurationService;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -47,9 +46,6 @@ public class CanManageVersionsFeatureIT extends AbstractControllerIntegrationTes
@Autowired @Autowired
private ItemConverter itemConverter; private ItemConverter itemConverter;
@Autowired
private ConfigurationService configurationService;
@Autowired @Autowired
private AuthorizationFeatureService authorizationFeatureService; private AuthorizationFeatureService authorizationFeatureService;
@@ -207,180 +203,4 @@ public class CanManageVersionsFeatureIT extends AbstractControllerIntegrationTes
.andExpect(status().isNotFound()); .andExpect(status().isNotFound());
} }
@Test
public void canManageVersionsFeatureAdminsAndPropertyBlockEntityEnableTest() throws Exception {
configurationService.setProperty("versioning.block.entity", true);
context.turnOffAuthorisationSystem();
EPerson adminComA = EPersonBuilder.createEPerson(context)
.withEmail("testComAdminA@test.com")
.withPassword(password)
.build();
EPerson adminComB = EPersonBuilder.createEPerson(context)
.withEmail("testComBdminA@test.com")
.withPassword(password)
.build();
EPerson adminCol1 = EPersonBuilder.createEPerson(context)
.withEmail("testCol1Admin@test.com")
.withPassword(password)
.build();
EPerson adminCol2 = EPersonBuilder.createEPerson(context)
.withEmail("testCol2Admin@test.com")
.withPassword(password)
.build();
Community rootCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community subCommunityA = CommunityBuilder.createSubCommunity(context, rootCommunity)
.withName("Sub Community A")
.withAdminGroup(adminComA)
.build();
CommunityBuilder.createSubCommunity(context, rootCommunity)
.withName("Sub Community B")
.withAdminGroup(adminComB)
.build();
Collection col1 = CollectionBuilder.createCollection(context, subCommunityA)
.withName("Collection 1")
.withEntityType("Publication")
.withSubmitterGroup(eperson)
.withAdminGroup(adminCol1)
.build();
CollectionBuilder.createCollection(context, subCommunityA)
.withName("Collection 2")
.withAdminGroup(adminCol2)
.build();
Item itemA = ItemBuilder.createItem(context, col1)
.withTitle("Public item")
.withIssueDate("2021-04-19")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
context.restoreAuthSystemState();
ItemRest itemRestA = itemConverter.convert(itemA, DefaultProjection.DEFAULT);
String tokenAdminComA = getAuthToken(adminComA.getEmail(), password);
String tokenAdminComB = getAuthToken(adminComB.getEmail(), password);
String tokenAdminCol1 = getAuthToken(adminCol1.getEmail(), password);
String tokenAdminCol2 = getAuthToken(adminCol2.getEmail(), password);
// define authorization that we know not exists
Authorization adminOfComAToItemA = new Authorization(adminComA, canManageVersionsFeature, itemRestA);
Authorization adminOfCol1ToItemA = new Authorization(adminCol1, canManageVersionsFeature, itemRestA);
Authorization adminOfComBToItemA = new Authorization(adminComB, canManageVersionsFeature, itemRestA);
Authorization adminOfCol2ToItemA = new Authorization(adminCol2, canManageVersionsFeature, itemRestA);
getClient(tokenAdminComA).perform(get("/api/authz/authorizations/" + adminOfComAToItemA.getID()))
.andExpect(status().isNotFound());
getClient(tokenAdminCol1).perform(get("/api/authz/authorizations/" + adminOfCol1ToItemA.getID()))
.andExpect(status().isNotFound());
getClient(tokenAdminComB).perform(get("/api/authz/authorizations/" + adminOfComBToItemA.getID()))
.andExpect(status().isNotFound());
getClient(tokenAdminCol2).perform(get("/api/authz/authorizations/" + adminOfCol2ToItemA.getID()))
.andExpect(status().isNotFound());
}
@Test
public void canManageVersionsFeatureAdminsAndPropertyBlockEntityDisabledTest() throws Exception {
configurationService.setProperty("versioning.block.entity", false);
context.turnOffAuthorisationSystem();
EPerson adminComA = EPersonBuilder.createEPerson(context)
.withEmail("testComAdminA@test.com")
.withPassword(password)
.build();
EPerson adminComB = EPersonBuilder.createEPerson(context)
.withEmail("testComBdminA@test.com")
.withPassword(password)
.build();
EPerson adminCol1 = EPersonBuilder.createEPerson(context)
.withEmail("testCol1Admin@test.com")
.withPassword(password)
.build();
EPerson adminCol2 = EPersonBuilder.createEPerson(context)
.withEmail("testCol2Admin@test.com")
.withPassword(password)
.build();
Community rootCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community subCommunityA = CommunityBuilder.createSubCommunity(context, rootCommunity)
.withName("Sub Community A")
.withAdminGroup(adminComA)
.build();
CommunityBuilder.createSubCommunity(context, rootCommunity)
.withName("Sub Community B")
.withAdminGroup(adminComB)
.build();
Collection col1 = CollectionBuilder.createCollection(context, subCommunityA)
.withName("Collection 1")
.withEntityType("Publication")
.withSubmitterGroup(eperson)
.withAdminGroup(adminCol1)
.build();
CollectionBuilder.createCollection(context, subCommunityA)
.withName("Collection 2")
.withAdminGroup(adminCol2)
.build();
Item itemA = ItemBuilder.createItem(context, col1)
.withTitle("Public item")
.withIssueDate("2021-04-19")
.withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
context.restoreAuthSystemState();
ItemRest itemRestA = itemConverter.convert(itemA, DefaultProjection.DEFAULT);
String tokenAdminComA = getAuthToken(adminComA.getEmail(), password);
String tokenAdminComB = getAuthToken(adminComB.getEmail(), password);
String tokenAdminCol1 = getAuthToken(adminCol1.getEmail(), password);
String tokenAdminCol2 = getAuthToken(adminCol2.getEmail(), password);
// define authorizations that we know must exists
Authorization adminOfComAToItemA = new Authorization(adminComA, canManageVersionsFeature, itemRestA);
Authorization adminOfCol1ToItemA = new Authorization(adminCol1, canManageVersionsFeature, itemRestA);
// define authorization that we know not exists
Authorization adminOfComBToItemA = new Authorization(adminComB, canManageVersionsFeature, itemRestA);
Authorization adminOfCol2ToItemA = new Authorization(adminCol2, canManageVersionsFeature, itemRestA);
getClient(tokenAdminComA).perform(get("/api/authz/authorizations/" + adminOfComAToItemA.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$", Matchers.is(
AuthorizationMatcher.matchAuthorization(adminOfComAToItemA))));
getClient(tokenAdminCol1).perform(get("/api/authz/authorizations/" + adminOfCol1ToItemA.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$", Matchers.is(
AuthorizationMatcher.matchAuthorization(adminOfCol1ToItemA))));
getClient(tokenAdminComB).perform(get("/api/authz/authorizations/" + adminOfComBToItemA.getID()))
.andExpect(status().isNotFound());
getClient(tokenAdminCol2).perform(get("/api/authz/authorizations/" + adminOfCol2ToItemA.getID()))
.andExpect(status().isNotFound());
}
} }

View File

@@ -20,7 +20,3 @@ versioning.item.history.include.submitter=false
# If you want to allow submitters to create new versions of there items, set # If you want to allow submitters to create new versions of there items, set
# the property submitterCanCreateNewVersion true. # the property submitterCanCreateNewVersion true.
# versioning.submitterCanCreateNewVersion=false # versioning.submitterCanCreateNewVersion=false
# The property versioning.block.entity is used to disable versioning
# for items with EntityType, the default value is true if it unset.
versioning.block.entity=false