Commit 10e37220357c560c248dedfb41161628c7859429

Authored by Cleverson Sacramento
1 parent d3076754
Exists in master

Mais atualizações da extensão e arquétipo rest

archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/BookmarkREST.java
... ... @@ -8,6 +8,7 @@ import javax.ws.rs.Consumes;
8 8 import javax.ws.rs.DELETE;
9 9 import javax.ws.rs.GET;
10 10 import javax.ws.rs.POST;
  11 +import javax.ws.rs.PUT;
11 12 import javax.ws.rs.Path;
12 13 import javax.ws.rs.PathParam;
13 14 import javax.ws.rs.Produces;
... ... @@ -21,9 +22,7 @@ import br.gov.frameworkdemoiselle.BadRequestException;
21 22 import br.gov.frameworkdemoiselle.NotFoundException;
22 23 import br.gov.frameworkdemoiselle.transaction.Transactional;
23 24  
24   -//@ValidateRequest
25 25 @Path("bookmark")
26   -// @Consumes(APPLICATION_JSON)
27 26 public class BookmarkREST {
28 27  
29 28 @Inject
... ... @@ -50,8 +49,8 @@ public class BookmarkREST {
50 49  
51 50 @POST
52 51 @Transactional
53   - @Consumes("application/json")
54 52 @Produces("text/plain")
  53 + @Consumes("application/json")
55 54 public Response insert(Bookmark entity, @Context UriInfo uriInfo) {
56 55 if (entity.getId() != null) {
57 56 throw new BadRequestException();
... ... @@ -63,6 +62,23 @@ public class BookmarkREST {
63 62 return Response.created(location).entity(id).build();
64 63 }
65 64  
  65 + @PUT
  66 + @Path("{id}")
  67 + @Transactional
  68 + @Consumes("application/json")
  69 + public void update(@PathParam("id") Long id, Bookmark entity) {
  70 + if (entity.getId() != null) {
  71 + throw new BadRequestException();
  72 + }
  73 +
  74 + if (bc.load(id) == null) {
  75 + throw new NotFoundException();
  76 + }
  77 +
  78 + entity.setId(id);
  79 + bc.update(entity);
  80 + }
  81 +
66 82 @DELETE
67 83 @Transactional
68 84 @Consumes("application/json")
... ...
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConstraintViolationExceptionMapper.java 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +//package br.gov.frameworkdemoiselle.internal.implementation;
  2 +//
  3 +//import java.util.Arrays;
  4 +//
  5 +//import javax.validation.ConstraintViolation;
  6 +//import javax.validation.ConstraintViolationException;
  7 +//import javax.ws.rs.core.Context;
  8 +//import javax.ws.rs.core.Response;
  9 +//import javax.ws.rs.ext.ExceptionMapper;
  10 +//import javax.ws.rs.ext.Provider;
  11 +//
  12 +//@Provider
  13 +//public class ConstraintViolationExceptionMapper implements ExceptionMapper<Exception> {
  14 +//
  15 +// @Context
  16 +// private Response response;
  17 +//
  18 +// @Override
  19 +// public Response toResponse(Exception exception) {
  20 +//
  21 +// Throwable rootCause = exception;
  22 +// while (rootCause != null) {
  23 +// if (rootCause instanceof ConstraintViolationException) {
  24 +// break;
  25 +// }
  26 +//
  27 +// rootCause = rootCause.getCause();
  28 +// }
  29 +//
  30 +// if (rootCause != null) {
  31 +// for (ConstraintViolation<?> violation : ((ConstraintViolationException) rootCause)
  32 +// .getConstraintViolations()) {
  33 +// String parts[] = violation.getPropertyPath().toString().split("\\.|\\[|\\]\\.");
  34 +// String property = null;
  35 +//
  36 +// if (parts.length > 1) {
  37 +// property = parts[1];
  38 +//
  39 +// for (String part : Arrays.copyOfRange(parts, 2, parts.length)) {
  40 +// property += "." + part;
  41 +// }
  42 +// }
  43 +//
  44 +// System.out.println(property);
  45 +// }
  46 +// }
  47 +//
  48 +// return null;
  49 +// }
  50 +// }
... ...
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultExceptionMapper.java
1 1 //package br.gov.frameworkdemoiselle.internal.implementation;
2 2 //
3   -//import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
  3 +//import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
4 4 //
5 5 //import java.util.ResourceBundle;
6 6 //
7   -//import javax.inject.Inject;
8 7 //import javax.ws.rs.core.Response;
9 8 //import javax.ws.rs.ext.ExceptionMapper;
10 9 //import javax.ws.rs.ext.Provider;
11 10 //
12 11 //import org.slf4j.Logger;
13 12 //
14   -//import br.gov.frameworkdemoiselle.annotation.Name;
  13 +//import br.gov.frameworkdemoiselle.util.Beans;
  14 +//import br.gov.frameworkdemoiselle.util.NamedQualifier;
15 15 //
16 16 //@Provider
17 17 //public class DefaultExceptionMapper implements ExceptionMapper<Throwable> {
18 18 //
19   -// @Inject
20   -// @Name("demoiselle-rest-bundle")
21   -// private ResourceBundle bundle;
  19 +// @Override
  20 +// public Response toResponse(Throwable exception) {
  21 +// ResourceBundle bundle = Beans.getReference(ResourceBundle.class, new NamedQualifier("demoiselle-rest-bundle"));
  22 +// Logger logger = Beans.getReference(Logger.class);
22 23 //
23   -// @Inject
24   -// private Logger logger;
  24 +// logger.error(exception.getMessage(), exception);
25 25 //
26   -// @Override
27   -// public Response toResponse(Throwable throwable) {
28   -// logger.error(throwable.getMessage(), throwable);
  26 +// // throw new DemoiselleException(cause);
29 27 //
30 28 // String message = bundle.getString("internal.server.error");
31   -// return Response.status(SC_INTERNAL_SERVER_ERROR).entity(message).build();
  29 +// return Response.status(INTERNAL_SERVER_ERROR).entity(message).build();
32 30 // }
33 31 //}
... ...