-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a7d8c07
Showing
7 changed files
with
385 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>it.gov.pagopa.swclient.mil</groupId> | ||
<artifactId>bom</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>common</artifactId> | ||
<version>0.0.6-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<description>Common classes for Multi-channel Integration Layer of SW Client Project</description> | ||
|
||
<developers> | ||
<developer> | ||
<name>Antonio Tarricone</name> | ||
<email>[email protected]</email> | ||
<organization>PagoPA S.p.A.</organization> | ||
</developer> | ||
</developers> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-validator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-jackson</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>${quarkus.platform.group-id}</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<version>${quarkus.platform.version}</version> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
<goal>generate-code</goal> | ||
<goal>generate-code-tests</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,19 @@ | ||
/* | ||
* Channel.java | ||
* | ||
* 26 nov 2022 | ||
*/ | ||
package it.gov.pagopa.swclient.mil.dto; | ||
|
||
/** | ||
* Supported channels | ||
* | ||
* @author Antonio Tarricone | ||
*/ | ||
public enum Channel { | ||
ATM, | ||
POS, | ||
TOTEM, | ||
CASH_REGISTER, | ||
CSA | ||
} |
129 changes: 129 additions & 0 deletions
129
src/main/java/it/gov/pagopa/swclient/mil/dto/CommonHeader.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,129 @@ | ||
/* | ||
* CommonHeader.java | ||
* | ||
* 26 nov 2022 | ||
*/ | ||
package it.gov.pagopa.swclient.mil.dto; | ||
|
||
import java.util.StringJoiner; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Pattern; | ||
import javax.validation.constraints.Size; | ||
import javax.ws.rs.HeaderParam; | ||
|
||
/** | ||
* Common header attributes | ||
* | ||
* @author Antonio Tarricone | ||
*/ | ||
public class CommonHeader { | ||
/* | ||
* Version of the required API | ||
*/ | ||
@HeaderParam("Version") | ||
@Size(max = 64, message = "Version size must be at most {max}") | ||
@Pattern(regexp = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$" , message = "Version must match {regexp}") | ||
private String version; | ||
|
||
/* | ||
* Acquirer ID assigned by PagoPA | ||
*/ | ||
@HeaderParam("AcquirerId") | ||
@NotNull(message = "AcquirerId must not be null") | ||
@Pattern(regexp = "^\\d{1,11}$", message = "AcquirerId must match {regexp}") | ||
private String acquirerId; | ||
|
||
/* | ||
* Channel originating the request | ||
*/ | ||
@HeaderParam("Channel") | ||
@NotNull(message = "Channel must not be null") | ||
@Pattern(regexp = "^(ATM|POS|TOTEM|CASH_REGISTER|CSA)$", message = "Channel must match {regexp}") | ||
private String channel; | ||
|
||
/* | ||
* ID of the terminal originating the transaction. It must be unique per acquirer and channel. | ||
*/ | ||
@HeaderParam("TerminalId") | ||
@NotNull(message = "TerminalId must not be null") | ||
@Pattern(regexp = "^[0-9a-zA-Z]{8}$", message = "TerminalId must match {regexp}") | ||
private String terminalId; | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
/** | ||
* | ||
* @param version | ||
*/ | ||
public void setVersion(String version) { | ||
this.version = version; | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public String getAcquirerId() { | ||
return acquirerId; | ||
} | ||
|
||
/** | ||
* | ||
* @param acquirerId | ||
*/ | ||
public void setAcquirerId(String acquirerId) { | ||
this.acquirerId = acquirerId; | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public Channel getChannel() { | ||
return Channel.valueOf(channel); | ||
} | ||
|
||
/** | ||
* | ||
* @param channel | ||
*/ | ||
public void setChannel(Channel channel) { | ||
this.channel = channel.name(); | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public String getTerminalId() { | ||
return terminalId; | ||
} | ||
|
||
/** | ||
* | ||
* @param terminalId | ||
*/ | ||
public void setTerminalId(String terminalId) { | ||
this.terminalId = terminalId; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", CommonHeader.class.getSimpleName() + "[", "]") | ||
.add("version='" + version + "'") | ||
.add("acquirerId='" + acquirerId + "'") | ||
.add("channel=" + channel) | ||
.add("terminalId='" + terminalId + "'") | ||
.toString(); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/it/gov/pagopa/swclient/mil/dto/Violation.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,65 @@ | ||
/* | ||
* Violation.java | ||
* | ||
* 26 nov 2022 | ||
*/ | ||
package it.gov.pagopa.swclient.mil.dto; | ||
|
||
import java.util.StringJoiner; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Pattern; | ||
|
||
/** | ||
* Violation description for BAD REQUEST response body | ||
* | ||
* @author Antonio Tarricone | ||
*/ | ||
public class Violation { | ||
/* | ||
* Violation description | ||
*/ | ||
@NotNull(message = "message must not be null") | ||
@Pattern(regexp = "^[\u0001-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]{1,256}$", message = "message must match {regexp}") | ||
private String message; | ||
|
||
/** | ||
* | ||
*/ | ||
public Violation() { | ||
} | ||
|
||
/** | ||
* | ||
* @param message | ||
*/ | ||
public Violation(String message) { | ||
this.message = message; | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
/** | ||
* | ||
* @param message | ||
*/ | ||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", Violation.class.getSimpleName() + "[", "]") | ||
.add("message='" + message + "'") | ||
.toString(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/it/gov/pagopa/swclient/mil/dto/Violations.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,66 @@ | ||
/* | ||
* Violations.java | ||
* | ||
* 26 nov 2022 | ||
*/ | ||
package it.gov.pagopa.swclient.mil.dto; | ||
|
||
import java.util.List; | ||
import java.util.StringJoiner; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
|
||
/** | ||
* List of violations for BAD REQUEST response body | ||
* | ||
* @author Antonio Tarricone | ||
*/ | ||
public class Violations { | ||
/* | ||
* List of violations | ||
*/ | ||
@NotNull(message = "violations must not be null") | ||
@Size(max = 32, message = "violations size must be at most {max}") | ||
private List<Violation> violations; | ||
|
||
/** | ||
* | ||
*/ | ||
public Violations() { | ||
} | ||
|
||
/** | ||
* | ||
* @param violations | ||
*/ | ||
public Violations(@NotNull(message = "violations must not be null") @Size(max = 32, message = "violations size must be at most {max}") List<Violation> violations) { | ||
this.violations = violations; | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public List<Violation> getViolations() { | ||
return violations; | ||
} | ||
|
||
/** | ||
* | ||
* @param violations | ||
*/ | ||
public void setViolations(List<Violation> violations) { | ||
this.violations = violations; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", Violations.class.getSimpleName() + "[", "]") | ||
.add("violations=" + violations) | ||
.toString(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/it/gov/pagopa/swclient/mil/util/CommonConstraintViolationExceptionMapper.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,30 @@ | ||
package it.gov.pagopa.swclient.mil.util; | ||
|
||
import java.util.List; | ||
|
||
import javax.validation.ConstraintViolationException; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import io.quarkus.logging.Log; | ||
import it.gov.pagopa.swclient.mil.dto.Violation; | ||
import it.gov.pagopa.swclient.mil.dto.Violations; | ||
|
||
@Provider | ||
public class CommonConstraintViolationExceptionMapper implements ExceptionMapper<ConstraintViolationException> { | ||
public Response toResponse(ConstraintViolationException e) { | ||
List<Violation> violationList = e.getConstraintViolations().stream() | ||
.map(c -> new Violation(c.getMessage())) | ||
.toList(); | ||
|
||
Violations violations = new Violations(violationList); | ||
|
||
Log.errorf("[%s] Constraint violation: %s", Error.CONTRAINT_VIOLATION, violations); | ||
|
||
return Response | ||
.status(Response.Status.BAD_REQUEST.getStatusCode(), Error.CONTRAINT_VIOLATION) | ||
.entity(violations) | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Error.java | ||
* | ||
* 26 nov 2022 | ||
*/ | ||
package it.gov.pagopa.swclient.mil.util; | ||
|
||
/** | ||
* | ||
* @author Antonio Tarricone | ||
*/ | ||
public final class Error { | ||
public static final String MODULE_ID = "000"; | ||
public static final String CONTRAINT_VIOLATION = MODULE_ID + "0000"; | ||
|
||
private Error() { | ||
} | ||
} |