diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java index 3764f3f272..50082bf4d5 100644 --- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java +++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/ItemRestRepository.java @@ -181,6 +181,10 @@ public class ItemRestRepository extends DSpaceRestRepository { Item item = null; try { item = is.find(context, id); + if (item == null) { + throw new ResourceNotFoundException(ItemRest.CATEGORY + "." + ItemRest.NAME + + " with id: " + id + " not found"); + } if (is.isInProgressSubmission(context, item)) { throw new UnprocessableEntityException("The item cannot be deleted. " + "It's part of a in-progress submission."); diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java index d1f46541e3..181f1dd075 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java @@ -1696,4 +1696,33 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest { .andExpect(status().isOk()); } + @Test + public void deleteOneWrongUuidResourceNotFoundTest() throws Exception { + context.turnOffAuthorisationSystem(); + + //** GIVEN ** + //1. A community with one collection. + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + Collection col1 = CollectionBuilder + .createCollection(context, parentCommunity).withName("Collection 1").build(); + + //2. One public item, one workspace item and one template item. + Item publicItem = ItemBuilder.createItem(context, col1) + .withTitle("Public item 1") + .withIssueDate("2017-10-17") + .withAuthor("Smith, Donald").withAuthor("Doe, John") + .withSubject("ExtraEntry") + .build(); + + + String token = getAuthToken(admin.getEmail(), password); + + //Delete public item + getClient(token).perform(delete("/api/core/items/" + parentCommunity.getID())) + .andExpect(status().is(404)); + + } + } \ No newline at end of file