Skip to content

Commit

Permalink
The exceptions are caught in the ProvenanceProvider and changed order…
Browse files Browse the repository at this point in the history
… when calling provenance methods.
  • Loading branch information
milanmajchrak committed Dec 13, 2024
1 parent 8ff24e0 commit 51302fa
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
328 changes: 186 additions & 142 deletions dspace-api/src/main/java/org/dspace/core/ProvenanceProvider.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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<Bundle> bundles = item.getBundles(Constants.CONTENT_BUNDLE_NAME);
for (Bundle clarinBundle : bundles) {
List<Bitstream> bitstreamList = clarinBundle.getBitstreams();
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MetadataValue> metadataValues = dsoService.getMetadata(dso,
Expand All @@ -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");
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 51302fa

Please sign in to comment.