Fixed the 500 internal server error when calling item delete endpoint with invalid UUID

This commit is contained in:
Raf Ponsaerts
2018-12-07 09:58:13 +01:00
parent 2e446bf9a3
commit db8f6f1bb8
2 changed files with 33 additions and 0 deletions

View File

@@ -181,6 +181,10 @@ public class ItemRestRepository extends DSpaceRestRepository<ItemRest, UUID> {
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.");

View File

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