class StateRest {

    @PUT
    @Path("{stateId}")
    @Consumes(MediaType.APPLICATION_JSON)
    @RolesAllowed("user")
    @ApiOperation("Updates State as long as it belongs to the User making the request")
    public Response updateState(@Context ContainerRequestContext context,
                         @PathParam("stateId") String stateId,
                         String newStateJson) {
        String username = RestUtils.getActiveUsername(context);
        try {
            if (!stateManager.stateExistsForUser(factory.createIRI(stateId), username)) {
                throw ErrorUtils.sendError("Not allowed", Response.Status.UNAUTHORIZED);
            }
            Model newState = transformer.mobiModel(Rio.parse(IOUtils.toInputStream(newStateJson), "",
                    RDFFormat.JSONLD));
            if (newState.isEmpty()) {
                throw ErrorUtils.sendError("Empty state model", Response.Status.BAD_REQUEST);
            }
            stateManager.updateState(factory.createIRI(stateId), newState);
        } catch (IOException ex) {
            throw ErrorUtils.sendError(ex, "Invalid JSON-LD", Response.Status.BAD_REQUEST);
        } catch (IllegalArgumentException ex) {
            throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.NOT_FOUND);
        } catch (MobiException ex) {
            throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
        }
        return Response.ok().build();
    }

}