-
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.
feat: Revision create terminal and initialized solutions (#15)
- Loading branch information
1 parent
3e1b01d
commit 75fb5d5
Showing
20 changed files
with
657 additions
and
79 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/java/it/pagopa/swclient/mil/papos/dao/SolutionEntity.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,15 @@ | ||
package it.pagopa.swclient.mil.papos.dao; | ||
|
||
import io.quarkus.mongodb.panache.PanacheMongoEntity; | ||
import io.quarkus.mongodb.panache.common.MongoEntity; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@MongoEntity(database = "mil", collection = "solutions") | ||
public class SolutionEntity extends PanacheMongoEntity { | ||
|
||
private String pspId; | ||
private String locationCode; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/it/pagopa/swclient/mil/papos/dao/SolutionRepository.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,9 @@ | ||
package it.pagopa.swclient.mil.papos.dao; | ||
|
||
import io.quarkus.mongodb.panache.reactive.ReactivePanacheMongoRepositoryBase; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import org.bson.types.ObjectId; | ||
|
||
@ApplicationScoped | ||
public class SolutionRepository implements ReactivePanacheMongoRepositoryBase<SolutionEntity, ObjectId> { | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/it/pagopa/swclient/mil/papos/model/SolutionDto.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.pagopa.swclient.mil.papos.model; | ||
|
||
import it.pagopa.swclient.mil.papos.util.ErrorCodes; | ||
import it.pagopa.swclient.mil.papos.util.RegexPatterns; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Pattern; | ||
|
||
public record SolutionDto(@NotNull(message = ErrorCodes.ERROR_PSPID_MUST_NOT_BE_NULL_MSG) | ||
@Pattern(regexp = RegexPatterns.ASCII_PRINTABLE_1_TO_64_PATTERN) | ||
String pspId, | ||
|
||
@NotNull(message = ErrorCodes.ERROR_PAYEECODE_MUST_NOT_BE_NULL_MSG) | ||
@Pattern(regexp = RegexPatterns.EXACT_ELEVEN_NUM_PATTERN) | ||
String locationCode) { | ||
|
||
} |
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
100 changes: 100 additions & 0 deletions
100
src/main/java/it/pagopa/swclient/mil/papos/resource/SolutionResource.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,100 @@ | ||
package it.pagopa.swclient.mil.papos.resource; | ||
|
||
import io.quarkus.logging.Log; | ||
import io.smallrye.mutiny.Uni; | ||
import it.pagopa.swclient.mil.papos.model.SolutionDto; | ||
import it.pagopa.swclient.mil.papos.service.SolutionService; | ||
import it.pagopa.swclient.mil.papos.util.ErrorCodes; | ||
import it.pagopa.swclient.mil.papos.util.Errors; | ||
import it.pagopa.swclient.mil.papos.util.RegexPatterns; | ||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Pattern; | ||
import jakarta.ws.rs.*; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
@Path("/solutions") | ||
public class SolutionResource { | ||
private final SolutionService solutionService; | ||
|
||
public SolutionResource(SolutionService solutionService) { | ||
this.solutionService = solutionService; | ||
} | ||
|
||
@POST | ||
@Path("/") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@RolesAllowed({"mil_papos_admin"}) | ||
public Uni<Response> createSolution( | ||
@HeaderParam("RequestId") | ||
@NotNull(message = ErrorCodes.ERROR_REQUESTID_MUST_NOT_BE_NULL_MSG) | ||
@Pattern(regexp = RegexPatterns.REQUEST_ID_PATTERN) String requestId, | ||
@Valid @NotNull(message = ErrorCodes.ERROR_DTO_MUST_NOT_BE_NULL_MSG) SolutionDto solution) { | ||
|
||
Log.debugf("SolutionResource -> createSolution - Input requestId, solutionDto: %s, %s", requestId, solution); | ||
|
||
return solutionService.createSolution(solution) | ||
.onFailure() | ||
.transform(err -> { | ||
Log.errorf(err, "SolutionResource -> createSolution: unexpected error during persist for solution [%s]", solution); | ||
|
||
return new InternalServerErrorException(Response | ||
.status(Response.Status.INTERNAL_SERVER_ERROR) | ||
.entity(new Errors(ErrorCodes.ERROR_GENERIC_FROM_DB, ErrorCodes.ERROR_GENERIC_FROM_DB_MSG)) | ||
.build()); | ||
}) | ||
.onItem() | ||
.transform(solutionSaved -> { | ||
Log.debugf("SolutionResource -> createSolution: solution saved correctly on DB [%s]", solutionSaved); | ||
|
||
return Response | ||
.status(Response.Status.CREATED) | ||
.entity(solutionSaved) | ||
.build(); | ||
}); | ||
} | ||
|
||
@GET | ||
@Path("/{solutionId}") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@RolesAllowed({"mil_papos_admin"}) | ||
public Uni<Response> findSolution( | ||
@HeaderParam("RequestId") | ||
@NotNull(message = ErrorCodes.ERROR_REQUESTID_MUST_NOT_BE_NULL_MSG) | ||
@Pattern(regexp = RegexPatterns.REQUEST_ID_PATTERN) String requestId, | ||
@PathParam(value = "solutionId") String solutionId) { | ||
|
||
Log.debugf("SolutionResource -> findSolution: Input requestId, solutionId: %s, %s", requestId, solutionId); | ||
|
||
return solutionService.findById(solutionId) | ||
.onFailure() | ||
.transform(err -> { | ||
Log.errorf(err, "SolutionResource -> findSolution: error during search solution with solutionId: [%s]", solutionId); | ||
|
||
return new InternalServerErrorException(Response | ||
.status(Response.Status.INTERNAL_SERVER_ERROR) | ||
.entity(new Errors(ErrorCodes.ERROR_GENERIC_FROM_DB, ErrorCodes.ERROR_GENERIC_FROM_DB_MSG)) | ||
.build()); | ||
}) | ||
.onItem() | ||
.transformToUni(solution -> { | ||
if (solution == null) { | ||
Log.errorf("SolutionResource -> findSolution: error 404 during searching solution with solutionId: [%s, %s]", solutionId); | ||
|
||
return Uni.createFrom().failure(new NotFoundException(Response | ||
.status(Response.Status.NOT_FOUND) | ||
.entity(new Errors(ErrorCodes.ERROR_SOLUTION_NOT_FOUND, ErrorCodes.ERROR_SOLUTION_NOT_FOUND_MSG)) | ||
.build())); | ||
} | ||
|
||
return Uni.createFrom().item(Response | ||
.status(Response.Status.OK) | ||
.entity(solution) | ||
.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.