Skip to content

Commit

Permalink
added search endpoint for bpmn model given the configuration of an ATM
Browse files Browse the repository at this point in the history
  • Loading branch information
candreac committed Nov 1, 2023
2 parents 98bb310 + 2207fb2 commit 9041410
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_DEPLOYABLE_STATUS;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_DEPLOYED_STATUS;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_EXISTING_REFERENCED_ENTITY;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_VALID_REFERENCED_ENTITY;

/**
* Enumeration for application error codes and messages
Expand All @@ -24,6 +25,8 @@ public enum AppErrorCodeEnum {
BPMN_FILE_CANNOT_BE_DEPLOYED("ATMLM_4000004", "The referenced BPMN file can not be deployed", NOT_DEPLOYABLE_STATUS),
BPMN_FUNCTION_TYPE_DIFFERENT_FROM_REQUESTED("ATMLM_4000005", "The referenced BPMN file has a function type different from the requested", INVALID_FUNCTION_TYPE),
BPMN_CANNOT_BE_DELETED_FOR_STATUS("ATMLM_4000006", "The referenced BPMN file can not be deleted in the actual state", NOT_DELETABLE),
MULTIPLE_BPMN_FILE_FOR_SINGLE_CONFIGURATION("ATMLM_4000007", "Multiple BPMN file found for a single configuration", INTERNAL),
NO_BPMN_FOUND_FOR_CONFIGURATION("ATMLM_4000008", "No runnable BPMN found for configuration", NOT_VALID_REFERENCED_ENTITY),
OBJECT_STORE_SAVE_FILE_ERROR("ATMLM_4000100", "Error on persisting file on Object Store ", INTERNAL);

private final String errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,15 @@ public Uni<List<BpmnBankConfig>> findByAcquirerIdAndFunctionType(String acquirer
params.put("functionType", functionType);
return list("select b from BpmnBankConfig b where b.bpmnBankConfigPK.acquirerId = :acquirerId and b.functionType= :functionType", params);
}

public Uni<List<BpmnBankConfig>> findByTriadAndFunctionType(String acquirerId, String branchId, String terminalId, FunctionTypeEnum functionType) {
Map<String, Object> params = new HashMap<>();
params.put("acquirerId", acquirerId);
params.put("branchId", branchId);
params.put("terminalId", terminalId);
params.put("functionType", functionType);
return find("select b from BpmnBankConfig b " +
"where b.bpmnBankConfigPK.branchId= :branchId and b.bpmnBankConfigPK.acquirerId = :acquirerId and b.functionType= :functionType " +
"and b.bpmnBankConfigPK.terminalId= :terminalId", params).list();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
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.BankConfigUtilityValues;
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;
import it.gov.pagopa.atmlayer.service.model.service.BpmnFileStorageService;
import it.gov.pagopa.atmlayer.service.model.service.BpmnVersionService;
import it.gov.pagopa.atmlayer.service.model.service.impl.BpmnBankConfigService;
import it.gov.pagopa.atmlayer.service.model.utils.BpmnDtoMapper;
import it.gov.pagopa.atmlayer.service.model.utils.BpmnUtils;
import it.gov.pagopa.atmlayer.service.model.validators.BpmnEntityValidator;
Expand All @@ -39,6 +41,7 @@
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

Expand All @@ -54,6 +57,10 @@ public class BpmnResource {

@Inject
BpmnVersionService bpmnVersionService;

@Inject
BpmnBankConfigService bpmnBankConfigService;

@Inject
BpmnEntityValidator bpmnEntityValidator;
@Inject
Expand Down Expand Up @@ -144,4 +151,33 @@ public Uni<BpmnVersion> deployBPMN(@PathParam("uuid") UUID uuid,
StatusEnum.DEPLOYED));
});
}

@GET
@Path("/function/{functionType}/bank{acquirerId}/branch/{branchId}/terminal/{terminalId}")
@Produces(MediaType.APPLICATION_JSON)
public Uni<Optional<BpmnVersion>> findBPMNByTriad(@PathParam("functionType") FunctionTypeEnum functionTypeEnum,
@PathParam("acquirerId") String acquirerId,
@PathParam("branchId") String branchId,
@PathParam("terminalId") String terminalId) {
return bpmnBankConfigService.findByConfigurationsAndFunction(acquirerId, branchId, terminalId, functionTypeEnum)
.onItem()
.transformToUni(x1 -> {
if (x1.isPresent()) {
return bpmnVersionService.findByPk(new BpmnVersionPK(x1.get().getBpmnBankConfigPK().getBpmnId(), x1.get().getBpmnBankConfigPK().getBpmnModelVersion()));
}
return bpmnBankConfigService.findByConfigurationsAndFunction(acquirerId, branchId, BankConfigUtilityValues.NULL_VALUE.getValue(), functionTypeEnum)
.onItem().transformToUni(x2 -> {
if (x2.isPresent()) {
return bpmnVersionService.findByPk(new BpmnVersionPK(x2.get().getBpmnBankConfigPK().getBpmnId(), x2.get().getBpmnBankConfigPK().getBpmnModelVersion()));
}
return bpmnBankConfigService.findByConfigurationsAndFunction(acquirerId, BankConfigUtilityValues.NULL_VALUE.getValue(), BankConfigUtilityValues.NULL_VALUE.getValue(), functionTypeEnum)
.onItem().transformToUni(Unchecked.function(x3 -> {
if (x3.isPresent()) {
return bpmnVersionService.findByPk(new BpmnVersionPK(x3.get().getBpmnBankConfigPK().getBpmnId(), x3.get().getBpmnBankConfigPK().getBpmnModelVersion()));
}
throw new AtmLayerException("No runnable BPMN found for selection", Response.Status.BAD_REQUEST, AppErrorCodeEnum.NO_BPMN_FOUND_FOR_CONFIGURATION);
}));
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import io.quarkus.hibernate.reactive.panache.common.WithTransaction;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.unchecked.Unchecked;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfig;
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.repository.BpmnBankConfigRepository;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.Response;

import java.util.List;
import java.util.Optional;

@ApplicationScoped
public class BpmnBankConfigService {
Expand All @@ -28,4 +33,15 @@ public Uni<List<BpmnBankConfig>> findByAcquirerIdAndFunctionType(String acquirer
public Uni<Long> deleteByAcquirerIdAndFunctionType(String acquirerId, FunctionTypeEnum functionTypeEnum) {
return this.bankConfigRepository.deleteByAcquirerIdAndFunctionType(acquirerId, functionTypeEnum);
}

public Uni<Optional<BpmnBankConfig>> findByConfigurationsAndFunction(String acquirerId, String branchId, String terminalId, FunctionTypeEnum functionTypeEnum) {
return this.bankConfigRepository.findByTriadAndFunctionType(acquirerId, branchId, terminalId, functionTypeEnum)
.onItem().transformToUni(Unchecked.function(x -> {
if (!x.isEmpty() && x.size() > 1) {
throw new AtmLayerException("Multiple BPMN found for a single configuration.", Response.Status.INTERNAL_SERVER_ERROR, AppErrorCodeEnum.ATMLM_500);
}

return Uni.createFrom().item(x.isEmpty() ? Optional.empty() : Optional.ofNullable(x.get(0)));
}));
}
}

0 comments on commit 9041410

Please sign in to comment.