Skip to content

Commit

Permalink
fixed deploy/
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciaM1 committed Oct 31, 2023
1 parent ebd933e commit 6f93177
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.CONSTRAINT_VIOLATION;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.GENERIC;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_DEPLOYABLE_STATUS;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_EXISTING_REFERENCED_ENTITY;

/**
Expand All @@ -13,9 +14,10 @@
public enum AppErrorCodeEnum {

ATMLM_500("ATMLM_500", "An unexpected error has occurred, see logs for more info", GENERIC),
BPMN_FILE_WITH_SAME_CONTENT_ALREADY_EXIST("ATMLM_4000001", "A BPMN file with the same content already Exist", CONSTRAINT_VIOLATION),
BPMN_FILE_DOES_NOT_EXIST("ATMLM_4000002", "The referenced BPMN file does not exists", NOT_EXISTING_REFERENCED_ENTITY),
BPMN_FILE_NOT_DEPLOYED("ATMLM_4000003", "The referenced BPMN file is not deployed", NOT_EXISTING_REFERENCED_ENTITY);
BPMN_FILE_WITH_SAME_CONTENT_ALREADY_EXIST("ATMLM_4000001", "A BPMN file with the same content already exists", CONSTRAINT_VIOLATION),
BPMN_FILE_DOES_NOT_EXIST("ATMLM_4000002", "The referenced BPMN file does not exist", NOT_EXISTING_REFERENCED_ENTITY),
BPMN_FILE_NOT_DEPLOYED("ATMLM_4000003", "The referenced BPMN file is not deployed", NOT_EXISTING_REFERENCED_ENTITY),
BPMN_FILE_CANNOT_BE_DEPLOYED("ATMLM_4000004","The referenced BPMN file can not be deployed", NOT_DEPLOYABLE_STATUS);

private final String errorCode;
private final String errorMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public enum AppErrorType {
VALIDATION,
CONSTRAINT_VIOLATION,
NOT_EXISTING_REFERENCED_ENTITY,
NOT_VALID_REFERENCED_ENTITY
NOT_VALID_REFERENCED_ENTITY,
NOT_DEPLOYABLE_STATUS
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfig;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersion;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersionPK;
import it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum;
import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException;
import it.gov.pagopa.atmlayer.service.model.service.BpmnVersionService;
Expand Down Expand Up @@ -34,6 +35,7 @@
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.BPMN_FILE_DOES_NOT_EXIST;
import static it.gov.pagopa.atmlayer.service.model.utils.BpmnUtils.getAcquirerConfigs;
Expand Down Expand Up @@ -103,19 +105,21 @@ public Uni<BpmnVersion> createBPMN(@RequestBody(required = true) @Valid BpmnCrea
return bpmnVersionService.save(bpmnVersion);
}

// @POST
// @Path("/deploy/{uuid}/version/{version}")
// @Produces(MediaType.APPLICATION_JSON)
// public Uni<BpmnVersion> deployBPMN(@PathParam("uuid") UUID uuid,
// @PathParam("version") Long version){
// bpmnVersionService.checkBpmnFileExistence(uuid,version)
// .onItem()
// .transform(x -> {
// if (x) {
// bpmnVersionService.setDeployInProgress(uuid, version);
// }
// });
// }
@POST
@Path("/deploy/{uuid}/version/{version}")
@Produces(MediaType.APPLICATION_JSON)
public Uni<BpmnVersion> deployBPMN(@PathParam("uuid") UUID uuid,
@PathParam("version") Long version){
return bpmnVersionService.checkBpmnFileExistence(uuid,version)
.onItem()
.transformToUni(x -> {
if (!x) {
String errorMessage = "The referenced BPMN file can not be deployed";
throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, AppErrorCodeEnum.BPMN_FILE_CANNOT_BE_DEPLOYED);
}
return bpmnVersionService.setDeployInProgress(uuid, version);
});
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfig;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersion;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersionPK;
import it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum;
import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException;
Expand All @@ -28,6 +29,7 @@
import java.util.UUID;

import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.BPMN_FILE_WITH_SAME_CONTENT_ALREADY_EXIST;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_EXISTING_REFERENCED_ENTITY;

@ApplicationScoped
@Slf4j
Expand Down Expand Up @@ -103,25 +105,35 @@ private static Uni<List<BpmnBankConfig>> addFunctionTypeToAssociations(List<Bpmn

@Override
@WithTransaction
public Uni<BpmnVersion> setDeployInProgress(UUID uuid, Long version) {
BpmnVersionPK key= new BpmnVersionPK(uuid, version);
public Uni<BpmnVersion> setDeployInProgress(UUID id, Long modelVersion) {
BpmnVersionPK key= new BpmnVersionPK(id, modelVersion);
return this.findByPk(key)
.onItem()
.transform(optionalBpmn ->{
if (optionalBpmn.isPresent()){
BpmnVersion bpmnToDeploy = optionalBpmn.get();
bpmnToDeploy.setStatus(StatusEnum.WAITING_DEPLOY);
this.bpmnVersionRepository.persist(bpmnToDeploy);
.transformToUni(optionalBpmn ->{
if (optionalBpmn.isEmpty()){
String errorMessage = String.format("One or some of the referenced BPMN files do not exists: %s", key);
throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, AppErrorCodeEnum.BPMN_FILE_DOES_NOT_EXIST);
}
throw new RuntimeException();
BpmnVersion bpmnToDeploy = optionalBpmn.get();
bpmnToDeploy.setStatus(StatusEnum.WAITING_DEPLOY);
return this.bpmnVersionRepository.persist(bpmnToDeploy);
}
);
}

@Override
public Uni<Boolean> checkBpmnFileExistence(UUID id, Long modelVersion) {
return this.bpmnVersionRepository.findById(new BpmnVersionPK(id, modelVersion))
BpmnVersionPK key= new BpmnVersionPK(id, modelVersion);
return this.findByPk(key)
.onItem()
.transform(bpmnVersion -> bpmnVersion.getStatus().equals(StatusEnum.CREATED) || bpmnVersion.getStatus().equals(StatusEnum.DEPLOY_ERROR));
.transform(optionalBpmn -> {
if (optionalBpmn.isEmpty()) {
String errorMessage = String.format("One or some of the referenced BPMN files do not exists: %s", key);
throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, AppErrorCodeEnum.BPMN_FILE_DOES_NOT_EXIST);
}
BpmnVersion bpmnVersion=optionalBpmn.get();
return bpmnVersion.getStatus().equals(StatusEnum.CREATED) || bpmnVersion.getStatus().equals(StatusEnum.DEPLOY_ERROR);
}
);
}
}

0 comments on commit 6f93177

Please sign in to comment.