use of nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException in project timbuctoo by HuygensING.
the class SingleEntity method delete.
@DELETE
public Response delete(@PathParam("collection") String collectionName, @HeaderParam("Authorization") String authHeader, @PathParam("id") UUIDParam id) {
Optional<User> user;
try {
user = userValidator.getUserFromAccessToken(authHeader);
} catch (UserValidationException e) {
user = Optional.empty();
}
Optional<User> newUser = user;
if (!newUser.isPresent()) {
return Response.status(Response.Status.UNAUTHORIZED).build();
} else {
return transactionEnforcer.executeAndReturn(timbuctooActions -> {
JsonCrudService jsonCrudService = crudServiceFactory.newJsonCrudService(timbuctooActions);
try {
jsonCrudService.delete(collectionName, id.get(), newUser.get());
return commitAndReturn(Response.noContent().build());
} catch (InvalidCollectionException e) {
return rollbackAndReturn(Response.status(Response.Status.NOT_FOUND).entity(jsnO("message", jsn(e.getMessage()))).build());
} catch (NotFoundException e) {
return rollbackAndReturn(Response.status(Response.Status.NOT_FOUND).entity(jsnO("message", jsn("not found"))).build());
} catch (PermissionFetchingException e) {
return rollbackAndReturn(Response.status(Response.Status.FORBIDDEN).entity(jsnO("message", jsn(e.getMessage()))).build());
} catch (IOException e) {
return rollbackAndReturn(Response.status(Response.Status.BAD_REQUEST).entity(jsnO("message", jsn(e.getMessage()))).build());
}
});
}
}
Aggregations