@POST @Consumes("application/json") public Response create(Reporter entity) { em.persist(entity); return Response.created( UriBuilder.fromResource(ReporterEndpoint.class) .path(String.valueOf(entity.getId())) .build()) .build(); }
@PUT @Path("/{id:[0-9][0-9]*}") @Consumes("application/json") public Response update(@PathParam("id") Long id, Reporter entity) { if (entity == null) { return Response.status(Status.BAD_REQUEST).build(); } if (id == null) { return Response.status(Status.BAD_REQUEST).build(); } if (!id.equals(entity.getId())) { return Response.status(Status.CONFLICT).entity(entity).build(); } if (em.find(Reporter.class, id) == null) { return Response.status(Status.NOT_FOUND).build(); } try { entity = em.merge(entity); } catch (OptimisticLockException e) { return Response.status(Response.Status.CONFLICT).entity(e.getEntity()).build(); } return Response.noContent().build(); }