Commit 2e89b1bc5897944b1a56318e5a2b37afe609e86f
1 parent
6fc5f4c5
Exists in
master
Atualização do arquétipo
Showing
11 changed files
with
86 additions
and
84 deletions
Show diff stats
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/business/BookmarkBC.java
| ... | ... | @@ -5,7 +5,7 @@ import br.gov.frameworkdemoiselle.stereotype.BusinessController; |
| 5 | 5 | import br.gov.frameworkdemoiselle.template.DelegateCrud; |
| 6 | 6 | import br.gov.frameworkdemoiselle.transaction.Transactional; |
| 7 | 7 | |
| 8 | -import ${package}.domain.Bookmark; | |
| 8 | +import ${package}.entity.Bookmark; | |
| 9 | 9 | import ${package}.persistence.BookmarkDAO; |
| 10 | 10 | |
| 11 | 11 | @BusinessController | ... | ... |
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/domain/Bookmark.java
| ... | ... | @@ -1,63 +0,0 @@ |
| 1 | -package ${package}.domain; | |
| 2 | - | |
| 3 | -import static javax.persistence.GenerationType.SEQUENCE; | |
| 4 | - | |
| 5 | -import java.io.Serializable; | |
| 6 | - | |
| 7 | -import javax.persistence.Column; | |
| 8 | -import javax.persistence.Entity; | |
| 9 | -import javax.persistence.GeneratedValue; | |
| 10 | -import javax.persistence.Id; | |
| 11 | - | |
| 12 | -@Entity | |
| 13 | -public class Bookmark implements Serializable { | |
| 14 | - | |
| 15 | - private static final long serialVersionUID = 1L; | |
| 16 | - | |
| 17 | - /* | |
| 18 | - * If you are using Glassfish then remove the strategy attribute | |
| 19 | - */ | |
| 20 | - @Id | |
| 21 | - @GeneratedValue(strategy = SEQUENCE) | |
| 22 | - private Long id; | |
| 23 | - | |
| 24 | - @Column | |
| 25 | - private String description; | |
| 26 | - | |
| 27 | - @Column | |
| 28 | - private String link; | |
| 29 | - | |
| 30 | - public Bookmark() { | |
| 31 | - super(); | |
| 32 | - } | |
| 33 | - | |
| 34 | - public Bookmark(String description, String link) { | |
| 35 | - this.description = description; | |
| 36 | - this.link = link; | |
| 37 | - } | |
| 38 | - | |
| 39 | - public Long getId() { | |
| 40 | - return id; | |
| 41 | - } | |
| 42 | - | |
| 43 | - public void setId(Long id) { | |
| 44 | - this.id = id; | |
| 45 | - } | |
| 46 | - | |
| 47 | - public String getDescription() { | |
| 48 | - return description; | |
| 49 | - } | |
| 50 | - | |
| 51 | - public void setDescription(String description) { | |
| 52 | - this.description = description; | |
| 53 | - } | |
| 54 | - | |
| 55 | - public String getLink() { | |
| 56 | - return link; | |
| 57 | - } | |
| 58 | - | |
| 59 | - public void setLink(String link) { | |
| 60 | - this.link = link; | |
| 61 | - } | |
| 62 | - | |
| 63 | -} |
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/entity/Bookmark.java
0 → 100644
| ... | ... | @@ -0,0 +1,64 @@ |
| 1 | +package ${package}.domain; | |
| 2 | + | |
| 3 | +import static javax.persistence.GenerationType.SEQUENCE; | |
| 4 | + | |
| 5 | +import java.io.Serializable; | |
| 6 | + | |
| 7 | +import javax.persistence.Entity; | |
| 8 | +import javax.persistence.GeneratedValue; | |
| 9 | +import javax.persistence.Id; | |
| 10 | +import javax.validation.constraints.NotNull; | |
| 11 | +import javax.validation.constraints.Pattern; | |
| 12 | + | |
| 13 | +@Entity | |
| 14 | +public class Bookmark implements Serializable { | |
| 15 | + | |
| 16 | + private static final long serialVersionUID = 1L; | |
| 17 | + | |
| 18 | + /* | |
| 19 | + * If you are using Glassfish then remove the strategy attribute | |
| 20 | + */ | |
| 21 | + @Id | |
| 22 | + @GeneratedValue(strategy = SEQUENCE) | |
| 23 | + private Long id; | |
| 24 | + | |
| 25 | + @NotNull | |
| 26 | + private String description; | |
| 27 | + | |
| 28 | + @NotNull | |
| 29 | + @Pattern(regexp = "^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$", message = "formato inválido") | |
| 30 | + private String link; | |
| 31 | + | |
| 32 | + public Bookmark() { | |
| 33 | + super(); | |
| 34 | + } | |
| 35 | + | |
| 36 | + public Bookmark(String description, String link) { | |
| 37 | + this.description = description; | |
| 38 | + this.link = link; | |
| 39 | + } | |
| 40 | + | |
| 41 | + public Long getId() { | |
| 42 | + return id; | |
| 43 | + } | |
| 44 | + | |
| 45 | + public void setId(Long id) { | |
| 46 | + this.id = id; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public String getDescription() { | |
| 50 | + return description; | |
| 51 | + } | |
| 52 | + | |
| 53 | + public void setDescription(String description) { | |
| 54 | + this.description = description; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public String getLink() { | |
| 58 | + return link; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public void setLink(String link) { | |
| 62 | + this.link = link; | |
| 63 | + } | |
| 64 | +} | ... | ... |
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/message/readme.txt
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/persistence/BookmarkDAO.java
| ... | ... | @@ -3,7 +3,7 @@ package ${package}.persistence; |
| 3 | 3 | import br.gov.frameworkdemoiselle.stereotype.PersistenceController; |
| 4 | 4 | import br.gov.frameworkdemoiselle.template.JPACrud; |
| 5 | 5 | |
| 6 | -import ${package}.domain.Bookmark; | |
| 6 | +import ${package}.entity.Bookmark; | |
| 7 | 7 | |
| 8 | 8 | @PersistenceController |
| 9 | 9 | public class BookmarkDAO extends JPACrud<Bookmark, Long> { | ... | ... |
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/BookmarkREST.java
| ... | ... | @@ -17,10 +17,11 @@ import javax.ws.rs.core.Response; |
| 17 | 17 | import javax.ws.rs.core.UriInfo; |
| 18 | 18 | |
| 19 | 19 | import ${package}.business.BookmarkBC; |
| 20 | -import ${package}.domain.Bookmark; | |
| 20 | +import ${package}.entity.Bookmark; | |
| 21 | 21 | import br.gov.frameworkdemoiselle.BadRequestException; |
| 22 | 22 | import br.gov.frameworkdemoiselle.NotFoundException; |
| 23 | 23 | import br.gov.frameworkdemoiselle.transaction.Transactional; |
| 24 | +import br.gov.frameworkdemoiselle.validation.Validate; | |
| 24 | 25 | |
| 25 | 26 | @Path("bookmark") |
| 26 | 27 | public class BookmarkREST { |
| ... | ... | @@ -48,6 +49,7 @@ public class BookmarkREST { |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | 51 | @POST |
| 52 | + @Validate | |
| 51 | 53 | @Transactional |
| 52 | 54 | @Produces("text/plain") |
| 53 | 55 | @Consumes("application/json") |
| ... | ... | @@ -61,9 +63,11 @@ public class BookmarkREST { |
| 61 | 63 | } |
| 62 | 64 | |
| 63 | 65 | @PUT |
| 66 | + @Validate | |
| 64 | 67 | @Path("{id}") |
| 65 | 68 | @Transactional |
| 66 | 69 | @Consumes("application/json") |
| 70 | + @Produces("application/json") | |
| 67 | 71 | public void update(@PathParam("id") Long id, Bookmark entity) { |
| 68 | 72 | checkId(entity); |
| 69 | 73 | load(id); | ... | ... |
archetype/html-rest/src/main/resources/archetype-resources/src/main/resources/META-INF/persistence.xml
| ... | ... | @@ -8,7 +8,7 @@ |
| 8 | 8 | <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL"> |
| 9 | 9 | <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source> |
| 10 | 10 | |
| 11 | - <class>${package}.domain.Bookmark</class> | |
| 11 | + <class>${package}.entity.Bookmark</class> | |
| 12 | 12 | |
| 13 | 13 | <properties> |
| 14 | 14 | <property name="hibernate.show_sql" value="true" /> |
| ... | ... | @@ -23,7 +23,7 @@ |
| 23 | 23 | <persistence-unit name="bookmark-ds" transaction-type="JTA"> |
| 24 | 24 | <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> |
| 25 | 25 | |
| 26 | - <class>${package}.domain.Bookmark</class> | |
| 26 | + <class>${package}.entity.Bookmark</class> | |
| 27 | 27 | |
| 28 | 28 | <exclude-unlisted-classes>true</exclude-unlisted-classes> |
| 29 | 29 | <properties> |
| ... | ... | @@ -41,7 +41,7 @@ |
| 41 | 41 | <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL"> |
| 42 | 42 | <non-jta-data-source>java:/DefaultDS</non-jta-data-source> |
| 43 | 43 | |
| 44 | - <class>${package}.domain.Bookmark</class> | |
| 44 | + <class>${package}.entity.Bookmark</class> | |
| 45 | 45 | |
| 46 | 46 | <properties> |
| 47 | 47 | <property name="hibernate.show_sql" value="true" /> |
| ... | ... | @@ -57,7 +57,7 @@ |
| 57 | 57 | <persistence-unit name="bookmark-ds" transaction-type="JTA"> |
| 58 | 58 | <jta-data-source>java:/DefaultDS</jta-data-source> |
| 59 | 59 | |
| 60 | - <class>${package}.domain.Bookmark</class> | |
| 60 | + <class>${package}.entity.Bookmark</class> | |
| 61 | 61 | <exclude-unlisted-classes>true</exclude-unlisted-classes> |
| 62 | 62 | <properties> |
| 63 | 63 | <property name="hibernate.show_sql" value="true" /> |
| ... | ... | @@ -74,7 +74,7 @@ |
| 74 | 74 | <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL"> |
| 75 | 75 | <non-jta-data-source>jdbc/__default</non-jta-data-source> |
| 76 | 76 | |
| 77 | - <class>${package}.domain.Bookmark</class> | |
| 77 | + <class>${package}.entity.Bookmark</class> | |
| 78 | 78 | |
| 79 | 79 | <properties> |
| 80 | 80 | <property name="eclipselink.logging.level" value="FINE" /> |
| ... | ... | @@ -89,7 +89,7 @@ |
| 89 | 89 | <persistence-unit name="bookmark-ds" transaction-type="JTA"> |
| 90 | 90 | <jta-data-source>jdbc/__TimerPool</jta-data-source> |
| 91 | 91 | |
| 92 | - <class>${package}.domain.Bookmark</class> | |
| 92 | + <class>${package}.entity.Bookmark</class> | |
| 93 | 93 | |
| 94 | 94 | <properties> |
| 95 | 95 | <property name="eclipselink.logging.level" value="FINE" /> |
| ... | ... | @@ -103,7 +103,7 @@ |
| 103 | 103 | <!-- |
| 104 | 104 | <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL"> |
| 105 | 105 | |
| 106 | - <class>${package}.domain.Bookmark</class> | |
| 106 | + <class>${package}.entity.Bookmark</class> | |
| 107 | 107 | |
| 108 | 108 | <properties> |
| 109 | 109 | <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" /> | ... | ... |
archetype/html-rest/src/main/resources/archetype-resources/src/test/java/business/BookmarkBCTest.java
| ... | ... | @@ -12,7 +12,7 @@ import org.junit.Test; |
| 12 | 12 | import org.junit.runner.RunWith; |
| 13 | 13 | |
| 14 | 14 | import br.gov.frameworkdemoiselle.junit.DemoiselleRunner; |
| 15 | -import ${package}.domain.Bookmark; | |
| 15 | +import ${package}.entity.Bookmark; | |
| 16 | 16 | |
| 17 | 17 | @RunWith(DemoiselleRunner.class) |
| 18 | 18 | public class BookmarkBCTest { | ... | ... |
archetype/html-rest/src/main/resources/archetype-resources/src/test/resources/META-INF/persistence.xml
| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | --> |
| 8 | 8 | <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL"> |
| 9 | 9 | |
| 10 | - <class>${package}.domain.Bookmark</class> | |
| 10 | + <class>${package}.entity.Bookmark</class> | |
| 11 | 11 | |
| 12 | 12 | <properties> |
| 13 | 13 | <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" /> |
| ... | ... | @@ -30,7 +30,7 @@ |
| 30 | 30 | <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL"> |
| 31 | 31 | <non-jta-data-source>java:/DefaultDS</non-jta-data-source> |
| 32 | 32 | |
| 33 | - <class>${package}.domain.Bookmark</class> | |
| 33 | + <class>${package}.entity.Bookmark</class> | |
| 34 | 34 | |
| 35 | 35 | <properties> |
| 36 | 36 | <property name="hibernate.show_sql" value="true" /> |
| ... | ... | @@ -46,7 +46,7 @@ |
| 46 | 46 | <persistence-unit name="bookmark-ds" transaction-type="JTA"> |
| 47 | 47 | <jta-data-source>java:/DefaultDS</jta-data-source> |
| 48 | 48 | |
| 49 | - <class>${package}.domain.Bookmark</class> | |
| 49 | + <class>${package}.entity.Bookmark</class> | |
| 50 | 50 | |
| 51 | 51 | <properties> |
| 52 | 52 | <property name="hibernate.show_sql" value="true" /> | ... | ... |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/PreconditionFailedException.java
| 1 | 1 | package br.gov.frameworkdemoiselle; |
| 2 | 2 | |
| 3 | -import static javax.servlet.http.HttpServletResponse.SC_PRECONDITION_FAILED; | |
| 4 | - | |
| 5 | 3 | import java.util.HashSet; |
| 6 | 4 | import java.util.Set; |
| 7 | 5 | |
| 8 | -import javax.xml.ws.http.HTTPException; | |
| 9 | - | |
| 10 | -public class PreconditionFailedException extends HTTPException { | |
| 6 | +public class PreconditionFailedException extends Exception { | |
| 11 | 7 | |
| 12 | 8 | private static final long serialVersionUID = 1L; |
| 13 | 9 | |
| 14 | 10 | private Set<Violation> violations = new HashSet<Violation>(); |
| 15 | 11 | |
| 16 | 12 | public PreconditionFailedException() { |
| 17 | - super(SC_PRECONDITION_FAILED); | |
| 18 | 13 | } |
| 19 | 14 | |
| 20 | 15 | public PreconditionFailedException addViolation(String property, String message) { | ... | ... |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/PreconditionFailedExceptionMapper.java
| 1 | 1 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 2 | 2 | |
| 3 | +import static javax.ws.rs.core.Response.Status.PRECONDITION_FAILED; | |
| 4 | + | |
| 3 | 5 | import javax.ws.rs.core.Response; |
| 4 | 6 | import javax.ws.rs.ext.ExceptionMapper; |
| 5 | 7 | import javax.ws.rs.ext.Provider; |
| ... | ... | @@ -11,6 +13,6 @@ public class PreconditionFailedExceptionMapper implements ExceptionMapper<Precon |
| 11 | 13 | |
| 12 | 14 | @Override |
| 13 | 15 | public Response toResponse(PreconditionFailedException exception) { |
| 14 | - return Response.status(exception.getStatusCode()).entity(exception.getViolations()).build(); | |
| 16 | + return Response.status(PRECONDITION_FAILED).entity(exception.getViolations()).build(); | |
| 15 | 17 | } |
| 16 | 18 | } | ... | ... |