From 51302fab665c037246901e94ce09fe320132bc5a Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Fri, 13 Dec 2024 10:52:47 +0100 Subject: [PATCH] The exceptions are caught in the ProvenanceProvider and changed order when calling provenance methods. --- .../bulkaccesscontrol/BulkAccessControl.java | 1 - .../org/dspace/core/ProvenanceProvider.java | 328 ++++++++++-------- .../app/rest/ItemAddBundleController.java | 4 +- .../rest/MappedCollectionRestController.java | 4 +- .../operation/BitstreamRemoveOperation.java | 2 +- .../DSpaceObjectMetadataAddOperation.java | 5 - .../DSpaceObjectMetadataRemoveOperation.java | 9 +- .../DSpaceObjectMetadataReplaceOperation.java | 21 -- .../ItemDiscoverableReplaceOperation.java | 15 +- 9 files changed, 194 insertions(+), 195 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/app/bulkaccesscontrol/BulkAccessControl.java b/dspace-api/src/main/java/org/dspace/app/bulkaccesscontrol/BulkAccessControl.java index deeb451ff648..7382a79ba4a7 100644 --- a/dspace-api/src/main/java/org/dspace/app/bulkaccesscontrol/BulkAccessControl.java +++ b/dspace-api/src/main/java/org/dspace/app/bulkaccesscontrol/BulkAccessControl.java @@ -469,7 +469,6 @@ private void setItemPolicies(Item item, BulkAccessControlInput accessControl) itemAccessConditions.get(accessCondition.getName()))); itemService.adjustItemPolicies(context, item, item.getOwningCollection(), false); - provenanceProvider.setItemPolicies(context, item, accessControl); } diff --git a/dspace-api/src/main/java/org/dspace/core/ProvenanceProvider.java b/dspace-api/src/main/java/org/dspace/core/ProvenanceProvider.java index f62a2d583781..08c1ab01bc97 100644 --- a/dspace-api/src/main/java/org/dspace/core/ProvenanceProvider.java +++ b/dspace-api/src/main/java/org/dspace/core/ProvenanceProvider.java @@ -47,9 +47,6 @@ public class ProvenanceProvider { private static final Logger log = LogManager.getLogger(ProvenanceProvider.class); private ItemService itemService = ContentServiceFactory.getInstance().getItemService(); - private ResourcePolicyService resourcePolicyService = - AuthorizeServiceFactory.getInstance().getResourcePolicyService(); - private ClarinItemService clarinItemService = ClarinServiceFactory.getInstance().getClarinItemService(); private ClarinLicenseResourceMappingService clarinResourceMappingService = ClarinServiceFactory.getInstance().getClarinLicenseResourceMappingService(); @@ -57,46 +54,6 @@ public class ProvenanceProvider { private final ProvenanceMessageProvider messageProvider = new ProvenanceMessageProvider(); - private void addProvenanceMetadata(Context context, Item item, String msg) - throws SQLException, AuthorizeException { - itemService.addMetadata(context, item, MetadataSchemaEnum.DC.getName(), - "description", "provenance", "en", msg); - itemService.update(context, item); - } - - private String extractAccessConditions(List accessConditions) { - return accessConditions.stream() - .map(AccessCondition::getName) - .collect(Collectors.joining(";")); - } - - private Item findItemByBitstream(Context context, Bitstream bitstream) throws SQLException { - List items = clarinItemService.findByBitstreamUUID(context, bitstream.getID()); - if (items.isEmpty()) { - log.warn("Bitstream (" + bitstream.getID() + ") is not assigned to any item."); - return null; - } - return items.get(0); - } - - private String findLicenseInBundles(Item item, String bundleName, String currentLicense, Context context) - throws SQLException { - List bundles = item.getBundles(bundleName); - for (Bundle clarinBundle : bundles) { - List bitstreamList = clarinBundle.getBitstreams(); - for (Bitstream bundleBitstream : bitstreamList) { - if (Objects.isNull(currentLicense)) { - List mappings = - this.clarinResourceMappingService.findByBitstreamUUID(context, bundleBitstream.getID()); - if (CollectionUtils.isNotEmpty(mappings)) { - return mappings.get(0).getLicense().getName(); - } - } - } - } - return currentLicense; - } - public void setItemPolicies(Context context, Item item, BulkAccessControlInput accessControl) throws SQLException, AuthorizeException { String resPoliciesStr = extractAccessConditions(accessControl.getItem().getAccessConditions()); @@ -107,108 +64,140 @@ public void setItemPolicies(Context context, Item item, BulkAccessControlInput a } } - public void removeReadPolicies(Context context, DSpaceObject dso, List resPolicies) - throws SQLException, AuthorizeException { + public void removeReadPolicies(Context context, DSpaceObject dso, List resPolicies) { if (resPolicies.isEmpty()) { return; } String resPoliciesStr = messageProvider.getMessage(resPolicies); - if (dso.getType() == Constants.ITEM) { - Item item = (Item) dso; - String msg = messageProvider.getMessage(context, - ProvenanceMessageTemplates.RESOURCE_POLICIES_REMOVED.getTemplate(), - resPoliciesStr.isEmpty() ? "empty" : resPoliciesStr, "item", item.getID()); - addProvenanceMetadata(context, item, msg); - } else if (dso.getType() == Constants.BITSTREAM) { - Bitstream bitstream = (Bitstream) dso; - Item item = findItemByBitstream(context, bitstream); - if (Objects.nonNull(item)) { + try { + if (dso.getType() == Constants.ITEM) { + Item item = (Item) dso; String msg = messageProvider.getMessage(context, - ProvenanceMessageTemplates.RESOURCE_POLICIES_REMOVED.getTemplate(), - resPoliciesStr.isEmpty() ? "empty" : resPoliciesStr, "bitstream", bitstream.getID()); + ProvenanceMessageTemplates.RESOURCE_POLICIES_REMOVED.getTemplate(), + resPoliciesStr.isEmpty() ? "empty" : resPoliciesStr, "item", item.getID()); addProvenanceMetadata(context, item, msg); + } else if (dso.getType() == Constants.BITSTREAM) { + Bitstream bitstream = (Bitstream) dso; + Item item = findItemByBitstream(context, bitstream); + if (Objects.nonNull(item)) { + String msg = messageProvider.getMessage(context, + ProvenanceMessageTemplates.RESOURCE_POLICIES_REMOVED.getTemplate(), + resPoliciesStr.isEmpty() ? "empty" : resPoliciesStr, "bitstream", bitstream.getID()); + addProvenanceMetadata(context, item, msg); + } } + } catch (SQLException | AuthorizeException e) { + log.error("Unable to remove read policies from the DSpace object.", e); } } public void setBitstreamPolicies(Context context, Bitstream bitstream, Item item, - BulkAccessControlInput accessControl) throws SQLException, AuthorizeException { + BulkAccessControlInput accessControl) { String accConditionsStr = extractAccessConditions(accessControl.getBitstream().getAccessConditions()); if (StringUtils.isNotBlank(accConditionsStr)) { String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.ACCESS_CONDITION.getTemplate(), accConditionsStr, "bitstream", bitstream.getID()); - addProvenanceMetadata(context, item, msg); + try { + addProvenanceMetadata(context, item, msg); + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when setting bitstream policies.", e); + } } } - public void editLicense(Context context, Item item, boolean newLicense) throws SQLException, AuthorizeException { + public void editLicense(Context context, Item item, boolean newLicense) { String oldLicense = null; - oldLicense = findLicenseInBundles(item, Constants.LICENSE_BUNDLE_NAME, oldLicense, context); - if (oldLicense == null) { - oldLicense = findLicenseInBundles(item, Constants.CONTENT_BUNDLE_NAME, oldLicense, context); + + try { + oldLicense = findLicenseInBundles(item, Constants.LICENSE_BUNDLE_NAME, oldLicense, context); + if (oldLicense == null) { + oldLicense = findLicenseInBundles(item, Constants.CONTENT_BUNDLE_NAME, oldLicense, context); + } + + String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.EDIT_LICENSE.getTemplate(), item, + Objects.isNull(oldLicense) ? "empty" : oldLicense, + !newLicense ? "removed" : Objects.isNull(oldLicense) ? "added" : "updated"); + addProvenanceMetadata(context, item, msg); + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when editing Item's license.", e); } - String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.EDIT_LICENSE.getTemplate(), item, - Objects.isNull(oldLicense) ? "empty" : oldLicense, - !newLicense ? "removed" : Objects.isNull(oldLicense) ? "added" : "updated"); - addProvenanceMetadata(context, item, msg); } - public void moveItem(Context context, Item item, Collection collection) throws SQLException, AuthorizeException { - String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.MOVE_ITEM.getTemplate(), - item, collection.getID()); - // Update item in DB - // Because a user can move an item without authorization turn off authorization - context.turnOffAuthorisationSystem(); - addProvenanceMetadata(context, item, msg); - context.restoreAuthSystemState(); + public void moveItem(Context context, Item item, Collection collection) { + try { + String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.MOVE_ITEM.getTemplate(), + item, collection.getID()); + // Update item in DB + // Because a user can move an item without authorization turn off authorization + context.turnOffAuthorisationSystem(); + addProvenanceMetadata(context, item, msg); + context.restoreAuthSystemState(); + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when moving an item to a different collection.", + e); + } } - public void mappedItem(Context context, Item item, Collection collection) throws SQLException, AuthorizeException { + public void mappedItem(Context context, Item item, Collection collection) { String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.MAPPED_ITEM.getTemplate(), collection.getID()); - addProvenanceMetadata(context, item, msg); + try { + addProvenanceMetadata(context, item, msg); + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when mapping an item into a collection.", e); + } } - public void deletedItemFromMapped(Context context, Item item, Collection collection) - throws SQLException, AuthorizeException { + public void deletedItemFromMapped(Context context, Item item, Collection collection) { String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.DELETED_ITEM_FROM_MAPPED.getTemplate(), collection.getID()); - addProvenanceMetadata(context, item, msg); - } - - public void deleteBitstream(Context context,Bitstream bitstream) throws SQLException, AuthorizeException { - Item item = findItemByBitstream(context, bitstream); - if (Objects.nonNull(item)) { - String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.EDIT_BITSTREAM.getTemplate(), - item, item.getID(), messageProvider.getMessage(bitstream)); + try { addProvenanceMetadata(context, item, msg); + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when deleting an item from a mapped collection.", + e); } } - public void addMetadata(Context context, DSpaceObject dso, MetadataField metadataField) - throws SQLException, AuthorizeException { - if (Constants.ITEM == dso.getType()) { - String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.ITEM_METADATA.getTemplate(), - messageProvider.getMetadataField(metadataField), "added"); - addProvenanceMetadata(context, (Item) dso, msg); - } - - if (dso.getType() == Constants.BITSTREAM) { - Bitstream bitstream = (Bitstream) dso; + public void deleteBitstream(Context context,Bitstream bitstream) { + try { Item item = findItemByBitstream(context, bitstream); if (Objects.nonNull(item)) { - String msg = messageProvider.getMessage(context, - ProvenanceMessageTemplates.BITSTREAM_METADATA.getTemplate(), item, - messageProvider.getMetadataField(metadataField), "added by", - messageProvider.getMessage(bitstream)); + String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.EDIT_BITSTREAM.getTemplate(), + item, item.getID(), messageProvider.getMessage(bitstream)); addProvenanceMetadata(context, item, msg); } + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when deleting a bitstream.", e); } } - public void removeMetadata(Context context, DSpaceObject dso, MetadataField metadataField) - throws SQLException, AuthorizeException { + public void addMetadata(Context context, DSpaceObject dso, MetadataField metadataField) { + try { + if (Constants.ITEM == dso.getType()) { + String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.ITEM_METADATA.getTemplate(), + messageProvider.getMetadataField(metadataField), "added"); + addProvenanceMetadata(context, (Item) dso, msg); + } + + if (dso.getType() == Constants.BITSTREAM) { + Bitstream bitstream = (Bitstream) dso; + Item item = findItemByBitstream(context, bitstream); + if (Objects.nonNull(item)) { + String msg = messageProvider.getMessage(context, + ProvenanceMessageTemplates.BITSTREAM_METADATA.getTemplate(), item, + messageProvider.getMetadataField(metadataField), "added by", + messageProvider.getMessage(bitstream)); + addProvenanceMetadata(context, item, msg); + } + } + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when adding metadata to a DSpace object.", e); + } + } + + public void removeMetadata(Context context, DSpaceObject dso, MetadataField metadataField) { if (dso.getType() != Constants.BITSTREAM) { return; } @@ -222,62 +211,83 @@ public void removeMetadata(Context context, DSpaceObject dso, MetadataField meta oldMtdValue = mtd.get(0).getValue(); } Bitstream bitstream = (Bitstream) dso; - Item item = findItemByBitstream(context, bitstream); - if (Objects.nonNull(item)) { - String msg = messageProvider.getMessage(context, - ProvenanceMessageTemplates.BITSTREAM_METADATA.getTemplate(), item, - messageProvider.getMetadata(messageProvider.getMetadataField(oldMtdKey), oldMtdValue), - "deleted from", messageProvider.getMessage(bitstream)); - addProvenanceMetadata(context, item, msg); + try { + Item item = findItemByBitstream(context, bitstream); + if (Objects.nonNull(item)) { + String msg = messageProvider.getMessage(context, + ProvenanceMessageTemplates.BITSTREAM_METADATA.getTemplate(), item, + messageProvider.getMetadata(messageProvider.getMetadataField(oldMtdKey), oldMtdValue), + "deleted from", messageProvider.getMessage(bitstream)); + addProvenanceMetadata(context, item, msg); + } + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when removing metadata from a dso.", e); } + } public void removeMetadataAtIndex(Context context, DSpaceObject dso, List metadataValues, - int indexInt) throws SQLException, AuthorizeException { + int indexInt) { if (dso.getType() != Constants.ITEM) { return; } // Remember removed mtd String oldMtdKey = messageProvider.getMetadataField(metadataValues.get(indexInt).getMetadataField()); String oldMtdValue = metadataValues.get(indexInt).getValue(); - String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.ITEM_METADATA.getTemplate(), - (Item) dso, messageProvider.getMetadata(oldMtdKey, oldMtdValue), "deleted"); - addProvenanceMetadata(context, (Item) dso, msg); + try { + String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.ITEM_METADATA.getTemplate(), + (Item) dso, messageProvider.getMetadata(oldMtdKey, oldMtdValue), "deleted"); + addProvenanceMetadata(context, (Item) dso, msg); + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when removing metadata at a specific index " + + "from a dso", e); + } } - public void replaceMetadata(Context context, DSpaceObject dso, MetadataField metadataField, String oldMtdVal) - throws SQLException, AuthorizeException { + public void replaceMetadata(Context context, DSpaceObject dso, MetadataField metadataField, String oldMtdVal) { if (dso.getType() != Constants.ITEM) { return; } - String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.ITEM_METADATA.getTemplate(), - (Item) dso,messageProvider.getMetadata(messageProvider.getMetadataField(metadataField), - oldMtdVal), "updated"); - addProvenanceMetadata(context, (Item) dso, msg); + try { + String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.ITEM_METADATA.getTemplate(), + (Item) dso,messageProvider.getMetadata(messageProvider.getMetadataField(metadataField), + oldMtdVal), "updated"); + addProvenanceMetadata(context, (Item) dso, msg); + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when replacing metadata in a dso.", e); + } + } - public void replaceMetadataSingle(Context context, DSpaceObject dso, MetadataField metadataField, String oldMtdVal) - throws SQLException, AuthorizeException { + public void replaceMetadataSingle(Context context, DSpaceObject dso, MetadataField metadataField, + String oldMtdVal) { if (dso.getType() != Constants.BITSTREAM) { return; } Bitstream bitstream = (Bitstream) dso; - Item item = findItemByBitstream(context, bitstream); - if (Objects.nonNull(item)) { - String msg = messageProvider.getMessage(context, - ProvenanceMessageTemplates.ITEM_REPLACE_SINGLE_METADATA.getTemplate(), item, - messageProvider.getMessage(bitstream), - messageProvider.getMetadata(messageProvider.getMetadataField(metadataField), oldMtdVal)); - addProvenanceMetadata(context, item, msg);; + try { + Item item = findItemByBitstream(context, bitstream); + if (Objects.nonNull(item)) { + String msg = messageProvider.getMessage(context, + ProvenanceMessageTemplates.ITEM_REPLACE_SINGLE_METADATA.getTemplate(), item, + messageProvider.getMessage(bitstream), + messageProvider.getMetadata(messageProvider.getMetadataField(metadataField), oldMtdVal)); + addProvenanceMetadata(context, item, msg);; + } + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when replacing metadata in a item.", e); } } - public void makeDiscoverable(Context context, Item item, boolean discoverable) - throws SQLException, AuthorizeException { - String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.DISCOVERABLE.getTemplate(), - item, discoverable ? "" : "non-") + messageProvider.getMessage(item); - addProvenanceMetadata(context, item, msg); + public void makeDiscoverable(Context context, Item item, boolean discoverable) { + try { + String msg = messageProvider.getMessage(context, ProvenanceMessageTemplates.DISCOVERABLE.getTemplate(), + item, discoverable ? "" : "non-") + messageProvider.getMessage(item); + addProvenanceMetadata(context, item, msg); + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when making an item discoverable.", e); + } } public void uploadBitstream(Context context, Bundle bundle) { @@ -287,14 +297,48 @@ public void uploadBitstream(Context context, Bundle bundle) { item, bundle.getID()); addProvenanceMetadata(context,item, msg); itemService.update(context, item); - } catch (SQLException ex) { - String msg = "SQLException in BundleUploadBitstreamConverter.uploadBitstream when " + - "adding new provenance metadata."; - log.error(msg, ex); - } catch (AuthorizeException ex) { - String msg = "AuthorizeException in BundleUploadBitstreamConverter.uploadBitstream " + - "when adding new provenance metadata."; - log.error(msg, ex); + } catch (SQLException | AuthorizeException e) { + log.error("Unable to add new provenance metadata when updating an item's bitstream.", e); } } + + private void addProvenanceMetadata(Context context, Item item, String msg) + throws SQLException, AuthorizeException { + itemService.addMetadata(context, item, MetadataSchemaEnum.DC.getName(), + "description", "provenance", "en", msg); + itemService.update(context, item); + } + + private String extractAccessConditions(List accessConditions) { + return accessConditions.stream() + .map(AccessCondition::getName) + .collect(Collectors.joining(";")); + } + + private Item findItemByBitstream(Context context, Bitstream bitstream) throws SQLException { + List items = clarinItemService.findByBitstreamUUID(context, bitstream.getID()); + if (items.isEmpty()) { + log.warn("Bitstream (" + bitstream.getID() + ") is not assigned to any item."); + return null; + } + return items.get(0); + } + + private String findLicenseInBundles(Item item, String bundleName, String currentLicense, Context context) + throws SQLException { + List bundles = item.getBundles(bundleName); + for (Bundle clarinBundle : bundles) { + List bitstreamList = clarinBundle.getBitstreams(); + for (Bitstream bundleBitstream : bitstreamList) { + if (Objects.isNull(currentLicense)) { + List mappings = + this.clarinResourceMappingService.findByBitstreamUUID(context, bundleBitstream.getID()); + if (CollectionUtils.isNotEmpty(mappings)) { + return mappings.get(0).getLicense().getName(); + } + } + } + } + return currentLicense; + } } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/ItemAddBundleController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/ItemAddBundleController.java index 4656936e0c89..de17013773f7 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/ItemAddBundleController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/ItemAddBundleController.java @@ -168,7 +168,7 @@ public ItemRest updateLicenseForBundle(@PathVariable UUID uuid, log.warn("Cannot find clarin license with id: " + licenseId + ". The old license will be detached, " + "but the new one will not be attached."); } - provenanceProvider.editLicense(context, item, !Objects.isNull(clarinLicense)); + List bundles = item.getBundles(Constants.CONTENT_BUNDLE_NAME); for (Bundle clarinBundle : bundles) { List bitstreamList = clarinBundle.getBitstreams(); @@ -185,8 +185,8 @@ public ItemRest updateLicenseForBundle(@PathVariable UUID uuid, if (Objects.nonNull(clarinLicense)) { clarinLicenseService.addLicenseMetadataToItem(context, clarinLicense, item); } - itemService.update(context, item); + provenanceProvider.editLicense(context, item, !Objects.isNull(clarinLicense)); context.commit(); return converter.toRest(item, utils.obtainProjection()); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/MappedCollectionRestController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/MappedCollectionRestController.java index cbdc46444719..960e53fde1c4 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/MappedCollectionRestController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/MappedCollectionRestController.java @@ -107,8 +107,8 @@ public void createCollectionToItemRelation(@PathVariable UUID uuid, collectionService.addItem(context, collectionToMapTo, item); collectionService.update(context, collectionToMapTo); - provenanceProvider.mappedItem(context, item, collectionToMapTo); itemService.update(context, item); + provenanceProvider.mappedItem(context, item, collectionToMapTo); } else { throw new UnprocessableEntityException("Not a valid collection or item uuid."); } @@ -154,8 +154,8 @@ public void deleteCollectionToItemRelation(@PathVariable UUID uuid, @PathVariabl if (collection.getID() != owningCollectionUuid && item.getCollections().contains(collection)) { collectionService.removeItem(context, collection, item); collectionService.update(context, collection); - provenanceProvider.deletedItemFromMapped(context,item, collection); itemService.update(context, item); + provenanceProvider.deletedItemFromMapped(context,item, collection); context.commit(); } } else { diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/BitstreamRemoveOperation.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/BitstreamRemoveOperation.java index 0826ad16adcb..1a0b4ca16554 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/BitstreamRemoveOperation.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/BitstreamRemoveOperation.java @@ -54,8 +54,8 @@ public Bitstream perform(Context context, Bitstream resource, Operation operatio } authorizeBitstreamRemoveAction(context, bitstreamToDelete, Constants.DELETE); try { - provenanceProvider.deleteBitstream(context, bitstreamToDelete); bitstreamService.delete(context, bitstreamToDelete); + provenanceProvider.deleteBitstream(context, bitstreamToDelete); } catch (AuthorizeException | IOException e) { throw new RuntimeException(e.getMessage(), e); } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataAddOperation.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataAddOperation.java index 6982044d555b..cee0e1113035 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataAddOperation.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataAddOperation.java @@ -80,11 +80,6 @@ private void add(Context context, DSpaceObject dso, DSpaceObjectService dsoServi "metadata to dso."; log.error(msg, e); throw new DSpaceBadRequestException(msg, e); - } catch (AuthorizeException e) { - msg = "AuthorizeException in DspaceObjectMetadataAddOperation.add " + - "trying to add metadata to dso."; - log.error(msg, e); - throw new DSpaceBadRequestException(msg, e); } } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataRemoveOperation.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataRemoveOperation.java index 5f5f54785d41..28b78cf7cd4a 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataRemoveOperation.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataRemoveOperation.java @@ -73,10 +73,10 @@ private void remove(Context context, DSpaceObject dso, DSpaceObjectService dsoSe String msg; try { if (index == null) { - provenanceProvider.removeMetadata(context, dso, metadataField); // remove all metadata of this type dsoService.clearMetadata(context, dso, metadataField.getMetadataSchema().getName(), metadataField.getElement(), metadataField.getQualifier(), Item.ANY); + provenanceProvider.removeMetadata(context, dso, metadataField); } else { // remove metadata at index List metadataValues = dsoService.getMetadata(dso, @@ -85,10 +85,10 @@ private void remove(Context context, DSpaceObject dso, DSpaceObjectService dsoSe int indexInt = Integer.parseInt(index); if (indexInt >= 0 && metadataValues.size() > indexInt && metadataValues.get(indexInt) != null) { - provenanceProvider.removeMetadataAtIndex(context, dso, metadataValues, indexInt); // remove that metadata dsoService.removeMetadataValues(context, dso, Arrays.asList(metadataValues.get(indexInt))); + provenanceProvider.removeMetadataAtIndex(context, dso, metadataValues, indexInt); } else { throw new UnprocessableEntityException("UnprocessableEntityException - There is no metadata of " + "this type at that index"); @@ -103,11 +103,6 @@ private void remove(Context context, DSpaceObject dso, DSpaceObjectService dsoSe "trying to remove metadata from dso."; log.error(msg, ex); throw new DSpaceBadRequestException(msg, ex); - } catch (AuthorizeException ex) { - msg = "AuthorizeException in DspaceObjectMetadataRemoveOperation.remove " + - "trying to replace metadata from dso."; - log.error(msg, ex); - throw new DSpaceBadRequestException(msg, ex); } } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataReplaceOperation.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataReplaceOperation.java index 2f7c4fdffcef..88ca03b31af2 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataReplaceOperation.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataReplaceOperation.java @@ -169,22 +169,11 @@ private void replaceSingleMetadataValue(Context context, DSpaceObject dso, DSpac existingMdv.setValue(metadataValue.getValue()); dsoService.setMetadataModified(dso); provenanceProvider.replaceMetadata(context, dso, metadataField, oldMtdVal); - } else { throw new UnprocessableEntityException("There is no metadata of this type at that index"); } } catch (NumberFormatException e) { throw new IllegalArgumentException("This index (" + index + ") is not valid number.", e); - } catch (SQLException e) { - msg = "SQLException in DspaceObjectMetadataReplaceOperation.replaceSingleMetadataValue " + - "trying to replace metadata from dso."; - log.error(msg, e); - throw new DSpaceBadRequestException(msg, e); - } catch (AuthorizeException e) { - msg = "AuthorizeException in DspaceObjectMetadataReplaceOperation.replaceSingleMetadataValue " + - "trying to replace metadata from dso."; - log.error(msg, e); - throw new DSpaceBadRequestException(msg, e); } } @@ -231,16 +220,6 @@ private void replaceSinglePropertyOfMdValue(Context context, DSpaceObject dso, D } catch (NumberFormatException e) { throw new IllegalArgumentException("Not all numbers are valid numbers. " + "(Index and confidence should be nr)", e); - } catch (SQLException e) { - msg = "SQLException in DspaceObjectMetadataReplaceOperation.replaceSinglePropertyOfMdValue " + - "trying to replace metadata from dso."; - log.error(msg, e); - throw new DSpaceBadRequestException(msg, e); - } catch (AuthorizeException e) { - msg = "AuthorizeException in DspaceObjectMetadataReplaceOperation.replaceSinglePropertyOfMdValue " + - "trying to replace metadata from dso."; - log.error(msg, e); - throw new DSpaceBadRequestException(msg, e); } } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ItemDiscoverableReplaceOperation.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ItemDiscoverableReplaceOperation.java index ad901d03a927..fcf39effe0d9 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ItemDiscoverableReplaceOperation.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ItemDiscoverableReplaceOperation.java @@ -47,20 +47,7 @@ public R perform(Context context, R object, Operation operation) { throw new UnprocessableEntityException("A template item cannot be discoverable."); } item.setDiscoverable(discoverable); - String msg; - try { - provenanceProvider.makeDiscoverable(context, item, discoverable); - } catch (SQLException ex) { - msg = "SQLException occurred when item making " + (discoverable ? "" : "non-") - + "discoverable."; - log.error(msg, ex); - throw new RuntimeException(msg, ex); - } catch (AuthorizeException ex) { - msg = "AuthorizeException occurred when item making " - + (discoverable ? "" : "non-") + "discoverable."; - log.error(msg, ex); - throw new RuntimeException(msg, ex); - } + provenanceProvider.makeDiscoverable(context, item, discoverable); return object; } else { throw new DSpaceBadRequestException("ItemDiscoverableReplaceOperation does not support this operation");