-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/hibernate-orm-panache' into develop
Implementazione esempio di uso ORM con Hibernate-Panache + JAX-RS Resources
- Loading branch information
Showing
24 changed files
with
927 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ on: | |
push: | ||
branches: | ||
- main | ||
- develop | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
<modelVersion>4.0.0</modelVersion> | ||
<groupId>it.dontesta.eventbus</groupId> | ||
<artifactId>eventbus-logging-filter-jaxrs</artifactId> | ||
<version>1.1.1-SNAPSHOT</version> | ||
<version>1.2.0-SNAPSHOT</version> | ||
|
||
<name>eventbus-logging-filter-jaxrs</name> | ||
<description>Event Bus Logging Filter JAX-RS</description> | ||
|
@@ -44,7 +44,7 @@ | |
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> | ||
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id> | ||
<quarkus.platform.version>3.9.2</quarkus.platform.version> | ||
<quarkus.platform.version>3.10.0</quarkus.platform.version> | ||
<skipITs>true</skipITs> | ||
<surefire-plugin.version>3.2.5</surefire-plugin.version> | ||
<sonar.organization>amusarra-github</sonar.organization> | ||
|
@@ -108,6 +108,14 @@ | |
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-smallrye-health</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-orm-panache</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-jdbc-h2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-jacoco</artifactId> | ||
|
@@ -118,6 +126,11 @@ | |
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-mockito</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
|
@@ -209,8 +222,7 @@ | |
<goal>generateKeyPair</goal> | ||
</goals> | ||
<configuration> | ||
<keystore>${project.build.outputDirectory}/${quarkus.http.ssl.certificate.key-store-file} | ||
</keystore> | ||
<keystore>${project.build.outputDirectory}/${quarkus.http.ssl.certificate.key-store-file}</keystore> | ||
<dname>cn=${project.artifactId}, ou=${project.groupId}, o=dontesta.it, c=IT</dname> | ||
<keypass>${quarkus.http.ssl.certificate.key-store-password}</keypass> | ||
<storepass>${quarkus.http.ssl.certificate.key-store-password}</storepass> | ||
|
@@ -241,15 +253,9 @@ | |
</plugins> | ||
</build> | ||
<scm> | ||
<connection> | ||
scm:git:[email protected]:amusarra/eventbus-logging-filter-jaxrs.git | ||
</connection> | ||
<url> | ||
scm:git:[email protected]:amusarra/eventbus-logging-filter-jaxrs.git | ||
</url> | ||
<developerConnection> | ||
scm:git:[email protected]:amusarra/eventbus-logging-filter-jaxrs.git | ||
</developerConnection> | ||
<connection>scm:git:[email protected]:amusarra/eventbus-logging-filter-jaxrs.git</connection> | ||
<url>scm:git:[email protected]:amusarra/eventbus-logging-filter-jaxrs.git</url> | ||
<developerConnection>scm:git:[email protected]:amusarra/eventbus-logging-filter-jaxrs.git</developerConnection> | ||
<tag>HEAD</tag> | ||
</scm> | ||
<profiles> | ||
|
@@ -262,7 +268,8 @@ | |
</activation> | ||
<properties> | ||
<skipITs>false</skipITs> | ||
<quarkus.package.type>native</quarkus.package.type> | ||
<quarkus.native.enabled>true</quarkus.native.enabled> | ||
<quarkus.package.jar.enabled>false</quarkus.package.jar.enabled> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/it/dontesta/eventbus/orm/panache/entity/Horse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package it.dontesta.eventbus.orm.panache.entity; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheEntity; | ||
import jakarta.persistence.Cacheable; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.ManyToMany; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
/** | ||
* This class represents the Horse entity. | ||
*/ | ||
@Entity | ||
@Cacheable | ||
public class Horse extends PanacheEntity { | ||
|
||
@Column(length = 60) | ||
public String name; | ||
|
||
@Column(length = 15) | ||
public String coat; | ||
|
||
@Column(length = 60) | ||
public String breed; | ||
|
||
public LocalDate dateOfBirth; | ||
|
||
@ManyToMany | ||
public List<Owner> owners; | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/it/dontesta/eventbus/orm/panache/entity/Owner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package it.dontesta.eventbus.orm.panache.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonBackReference; | ||
import io.quarkus.hibernate.orm.panache.PanacheEntity; | ||
import jakarta.persistence.Cacheable; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.ManyToMany; | ||
import java.util.List; | ||
|
||
/** | ||
* This class represents the Owner entity. | ||
*/ | ||
@Entity | ||
@Cacheable | ||
public class Owner extends PanacheEntity { | ||
|
||
@Column(length = 60) | ||
public String name; | ||
|
||
@Column(length = 60) | ||
public String surname; | ||
|
||
@Column(length = 60, unique = true) | ||
public String email; | ||
|
||
@Column(length = 20) | ||
public String phoneNumber; | ||
|
||
@Column(length = 60) | ||
public String address; | ||
|
||
@Column(length = 60) | ||
public String city; | ||
|
||
@Column(length = 2) | ||
public String state; | ||
|
||
@Column(length = 10) | ||
public String zipCode; | ||
|
||
@Column(length = 60) | ||
public String country; | ||
|
||
@ManyToMany(mappedBy = "owners") | ||
@JsonBackReference | ||
public List<Horse> horses; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/it/dontesta/eventbus/orm/panache/repository/HorseRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package it.dontesta.eventbus.orm.panache.repository; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheRepository; | ||
import it.dontesta.eventbus.orm.panache.entity.Horse; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import java.util.List; | ||
|
||
/** | ||
* This class is a Panache repository for the Horse entity. | ||
*/ | ||
@ApplicationScoped | ||
public class HorseRepository implements PanacheRepository<Horse> { | ||
public List<Horse> findOrderedByName() { | ||
return find("ORDER BY name").list(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/it/dontesta/eventbus/orm/panache/repository/OwnerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package it.dontesta.eventbus.orm.panache.repository; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheRepository; | ||
import it.dontesta.eventbus.orm.panache.entity.Owner; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import java.util.List; | ||
|
||
/** | ||
* This class represents the Panache repository for the Owner entity. | ||
*/ | ||
@ApplicationScoped | ||
public class OwnerRepository implements PanacheRepository<Owner> { | ||
public List<Owner> findOrderedByName() { | ||
return find("ORDER BY name").list(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/it/dontesta/eventbus/ws/mappers/ErrorMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package it.dontesta.eventbus.ws.mappers; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
import org.jboss.logging.Logger; | ||
|
||
/** | ||
* This class represents the error mapper for the RESTful web services. | ||
*/ | ||
@Provider | ||
public class ErrorMapper implements ExceptionMapper<Throwable> { | ||
|
||
@Inject | ||
Logger log; | ||
|
||
@Inject | ||
ObjectMapper objectMapper; | ||
|
||
@Override | ||
public Response toResponse(Throwable exception) { | ||
log.error("An error occurred", exception); | ||
|
||
int code = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); | ||
|
||
if (exception instanceof WebApplicationException webAppException) { | ||
code = webAppException.getResponse().getStatus(); | ||
} | ||
|
||
ObjectNode exceptionJson = objectMapper.createObjectNode(); | ||
exceptionJson.put("code", code); | ||
exceptionJson.put("exceptionType", exception.getClass().getName()); | ||
|
||
if (exception.getMessage() != null) { | ||
exceptionJson.put("error", exception.getMessage()); | ||
} | ||
|
||
return Response.status(code).entity(exceptionJson).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.