mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 22:43:12 +00:00
[Task 71502] added forceDelete method to the RelationshipService that won't check the cardinality of the relationships. Used this in the ItemService delete and added tests
This commit is contained in:
@@ -331,21 +331,43 @@ 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);
|
||||
} 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);
|
||||
} else {
|
||||
throw new AuthorizeException(
|
||||
"You do not have write rights on this relationship's items");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts virtual metadata from RelationshipMetadataValue objects to actual item metadata.
|
||||
*
|
||||
|
Reference in New Issue
Block a user