mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 14:33:09 +00:00
Merge branch 'main' into w2p-77489_tilted-relationships-tests
This commit is contained in:
@@ -244,6 +244,10 @@ public class RelationshipServiceImpl implements RelationshipService {
|
||||
Integer maxCardinality,
|
||||
RelationshipType relationshipType,
|
||||
boolean isLeft) throws SQLException {
|
||||
if (maxCardinality == null) {
|
||||
//no need to check the relationships
|
||||
return true;
|
||||
}
|
||||
List<Relationship> rightRelationships = findByItemAndRelationshipType(context, itemToProcess, relationshipType,
|
||||
isLeft);
|
||||
if (maxCardinality != null && rightRelationships.size() >= maxCardinality) {
|
||||
@@ -253,7 +257,8 @@ public class RelationshipServiceImpl implements RelationshipService {
|
||||
}
|
||||
|
||||
private boolean verifyEntityTypes(Item itemToProcess, EntityType entityTypeToProcess) {
|
||||
List<MetadataValue> list = itemService.getMetadata(itemToProcess, "relationship", "type", null, Item.ANY);
|
||||
List<MetadataValue> list = itemService.getMetadata(itemToProcess, "relationship", "type",
|
||||
null, Item.ANY, false);
|
||||
if (list.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -341,22 +346,44 @@ public class RelationshipServiceImpl implements RelationshipService {
|
||||
if (isRelationshipValidToDelete(context, relationship) &&
|
||||
copyToItemPermissionCheck(context, relationship, copyToLeftItem, copyToRightItem)) {
|
||||
// To delete a relationship, a user must have WRITE permissions on one of the related Items
|
||||
copyMetadataValues(context, relationship, copyToLeftItem, copyToRightItem);
|
||||
if (authorizeService.authorizeActionBoolean(context, relationship.getLeftItem(), Constants.WRITE) ||
|
||||
authorizeService.authorizeActionBoolean(context, relationship.getRightItem(), Constants.WRITE)) {
|
||||
relationshipDAO.delete(context, relationship);
|
||||
updatePlaceInRelationship(context, relationship);
|
||||
updateItemsInRelationship(context, relationship);
|
||||
} else {
|
||||
throw new AuthorizeException(
|
||||
"You do not have write rights on this relationship's items");
|
||||
}
|
||||
deleteRelationshipAndCopyToItem(context, relationship, copyToLeftItem, copyToRightItem);
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException("The relationship given was not valid");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceDelete(Context context, Relationship relationship, boolean copyToLeftItem, boolean copyToRightItem)
|
||||
throws SQLException, AuthorizeException {
|
||||
log.info(org.dspace.core.LogManager.getHeader(context, "delete_relationship",
|
||||
"relationship_id=" + relationship.getID() + "&" +
|
||||
"copyMetadataValuesToLeftItem=" + copyToLeftItem + "&" +
|
||||
"copyMetadataValuesToRightItem=" + copyToRightItem));
|
||||
if (copyToItemPermissionCheck(context, relationship, copyToLeftItem, copyToRightItem)) {
|
||||
// To delete a relationship, a user must have WRITE permissions on one of the related Items
|
||||
deleteRelationshipAndCopyToItem(context, relationship, copyToLeftItem, copyToRightItem);
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException("The relationship given was not valid");
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteRelationshipAndCopyToItem(Context context, Relationship relationship, boolean copyToLeftItem,
|
||||
boolean copyToRightItem) throws SQLException, AuthorizeException {
|
||||
copyMetadataValues(context, relationship, copyToLeftItem, copyToRightItem);
|
||||
if (authorizeService.authorizeActionBoolean(context, relationship.getLeftItem(), Constants.WRITE) ||
|
||||
authorizeService.authorizeActionBoolean(context, relationship.getRightItem(), Constants.WRITE)) {
|
||||
relationshipDAO.delete(context, relationship);
|
||||
updatePlaceInRelationship(context, relationship);
|
||||
updateItemsInRelationship(context, relationship);
|
||||
} else {
|
||||
throw new AuthorizeException(
|
||||
"You do not have write rights on this relationship's items");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Utility method to ensure discovery is updated for the 2 items
|
||||
|
Reference in New Issue
Block a user