Search in sources :

Example 6 with PermissionFetchingException

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());
            }
        });
    }
}
Also used : UserValidationException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) PermissionFetchingException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException) JsonCrudService(nl.knaw.huygens.timbuctoo.crud.JsonCrudService) InvalidCollectionException(nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) IOException(java.io.IOException) DELETE(javax.ws.rs.DELETE)

Aggregations

PermissionFetchingException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException)6 IOException (java.io.IOException)5 InvalidCollectionException (nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException)3 JsonCrudService (nl.knaw.huygens.timbuctoo.crud.JsonCrudService)3 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)3 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)3 UserValidationException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException)3 NotFoundException (nl.knaw.huygens.timbuctoo.core.NotFoundException)2 BasicDataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)2 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)2 DataStorageSaveException (nl.knaw.huygens.timbuctoo.v5.datastorage.exceptions.DataStorageSaveException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 UUID (java.util.UUID)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 AlreadyUpdatedException (nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException)1 DataSetPublishException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataSetPublishException)1 DataStoreCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)1 NotEnoughPermissionsException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.NotEnoughPermissionsException)1