Skip to content

Commit

Permalink
deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
ElisKina-dev committed Oct 31, 2023
1 parent 5eb0b21 commit c6177b2
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DeployedProcessInfoDto {
private String category;
private String description;
private String name;
private Long version;
private Integer version;
private String resource;
private UUID deploymentId;
private String diagram;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import it.gov.pagopa.atmlayer.service.model.client.ProcessClient;
import it.gov.pagopa.atmlayer.service.model.dto.BpmnAssociationDto;
import it.gov.pagopa.atmlayer.service.model.dto.BpmnCreationDto;
import it.gov.pagopa.atmlayer.service.model.dto.DeployResponseDto;
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;
Expand Down Expand Up @@ -47,13 +48,14 @@
@Tag(name = "BPMN", description = "BPMN operations")
@Slf4j
public class BpmnResource {
@Inject
BpmnVersionService bpmnVersionService;
@Inject
BpmnEntityValidator bpmnEntityValidator;
@Inject
@RestClient
ProcessClient processClient;

@Inject
BpmnVersionService bpmnVersionService;
@Inject
BpmnEntityValidator bpmnEntityValidator;
@Inject
@RestClient
ProcessClient processClient;
// @GET
// @Consumes(MediaType.APPLICATION_JSON)
// @Produces(MediaType.TEXT_PLAIN)
Expand All @@ -63,70 +65,76 @@ public class BpmnResource {
// return "String file: " + xml;
// }

@GET
@Path("/{bpmnId}/version/{version}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<BpmnVersion> getEncodedFile(@PathParam("bpmnId") UUID bpmnId,
@PathParam("version") Long version) {
BpmnVersionPK key = BpmnVersionPK.builder()
.bpmnId(bpmnId)
.modelVersion(version)
.build();
return this.bpmnVersionService.findByPk(key)
.onItem()
.transform(Unchecked.function(x -> {
if (x.isEmpty()) {
throw new AtmLayerException(Response.Status.NOT_FOUND, BPMN_FILE_DOES_NOT_EXIST);
}
return x.get();
}));
}
@GET
@Path("/{bpmnId}/version/{version}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<BpmnVersion> getEncodedFile(@PathParam("bpmnId") UUID bpmnId,
@PathParam("version") Long version) {
BpmnVersionPK key = BpmnVersionPK.builder()
.bpmnId(bpmnId)
.modelVersion(version)
.build();
return this.bpmnVersionService.findByPk(key)
.onItem()
.transform(Unchecked.function(x -> {
if (x.isEmpty()) {
throw new AtmLayerException(Response.Status.NOT_FOUND, BPMN_FILE_DOES_NOT_EXIST);
}
return x.get();
}));
}

@PUT
@Path("/bank/{acquirerId}/associations/function/{functionType}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<BpmnBankConfig>> associateBPMN(@PathParam("acquirerId") String acquirerId,
@PathParam("functionType") FunctionTypeEnum functionTypeEnum,
@RequestBody(required = true) @Valid BpmnAssociationDto bpmnAssociationDto) throws NoSuchAlgorithmException, IOException {
List<BpmnBankConfig> configs = getAcquirerConfigs(bpmnAssociationDto, acquirerId, functionTypeEnum);
Set<BpmnVersionPK> bpmnIds = BpmnUtils.extractBpmnUUIDFromAssociations(configs);
return bpmnEntityValidator.validateExistenceAndStatus(bpmnIds)
.onItem().transformToUni(x -> this.bpmnVersionService.putAssociations(acquirerId, functionTypeEnum, configs));
}
@PUT
@Path("/bank/{acquirerId}/associations/function/{functionType}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<BpmnBankConfig>> associateBPMN(@PathParam("acquirerId") String acquirerId,
@PathParam("functionType") FunctionTypeEnum functionTypeEnum,
@RequestBody(required = true) @Valid BpmnAssociationDto bpmnAssociationDto)
throws NoSuchAlgorithmException, IOException {
List<BpmnBankConfig> configs = getAcquirerConfigs(bpmnAssociationDto, acquirerId,
functionTypeEnum);
Set<BpmnVersionPK> bpmnIds = BpmnUtils.extractBpmnUUIDFromAssociations(configs);
return bpmnEntityValidator.validateExistenceAndStatus(bpmnIds)
.onItem().transformToUni(
x -> this.bpmnVersionService.putAssociations(acquirerId, functionTypeEnum, configs));
}

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Uni<BpmnVersion> createBPMN(@RequestBody(required = true) @Valid BpmnCreationDto bpmnCreationDto) throws NoSuchAlgorithmException, IOException {
BpmnVersion bpmnVersion = BpmnDtoMapper.toBpmnVersion(bpmnCreationDto);
return bpmnVersionService.save(bpmnVersion);
}
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Uni<BpmnVersion> createBPMN(
@RequestBody(required = true) @Valid BpmnCreationDto bpmnCreationDto)
throws NoSuchAlgorithmException, IOException {
BpmnVersion bpmnVersion = BpmnDtoMapper.toBpmnVersion(bpmnCreationDto);
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) {
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.setBpmnVersionStatus(uuid, version, StatusEnum.WAITING_DEPLOY);
})
.onItem()
.transformToUni(bpmnWaiting -> {
try {
processClient.deploy("url");
return bpmnVersionService.setBpmnVersionStatus(uuid, version, StatusEnum.DEPLOYED);
} catch (Exception e) {
bpmnVersionService.setBpmnVersionStatus(uuid, version, StatusEnum.DEPLOY_ERROR);
throw new RuntimeException("deploy failed");
}
});
}
@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.setBpmnVersionStatus(uuid, version, StatusEnum.WAITING_DEPLOY);
})
.onItem()
.transformToUni(bpmnWaiting -> {
return processClient.deploy("url")
.onItem()
.transformToUni(response -> bpmnVersionService.setDeployInfo(uuid, version, response))
.onItem()
.transformToUni(bpmnUpdated -> bpmnVersionService.setBpmnVersionStatus(uuid, version,
StatusEnum.DEPLOYED));
// return bpmnVersionService.setBpmnVersionStatus(uuid, version, StatusEnum.DEPLOYED);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.gov.pagopa.atmlayer.service.model.service;

import io.smallrye.mutiny.Uni;
import it.gov.pagopa.atmlayer.service.model.dto.DeployResponseDto;
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;
Expand All @@ -16,21 +17,25 @@
import java.util.UUID;

public interface BpmnVersionService {
String decodeBase64(String s) throws IOException;

Uni<List<BpmnVersion>> findByPKSet(Set<BpmnVersionPK> bpmnVersionPKSet);
String decodeBase64(String s) throws IOException;

String calculateSHA256(File file) throws NoSuchAlgorithmException, IOException;
Uni<List<BpmnVersion>> findByPKSet(Set<BpmnVersionPK> bpmnVersionPKSet);

Uni<BpmnVersion> save(BpmnVersion bpmnVersion);
String calculateSHA256(File file) throws NoSuchAlgorithmException, IOException;

public Uni<Optional<BpmnVersion>> findBySHA256(String sha256);
Uni<BpmnVersion> save(BpmnVersion bpmnVersion);

Uni<Optional<BpmnVersion>> findByPk(BpmnVersionPK bpmnVersionPK);
public Uni<Optional<BpmnVersion>> findBySHA256(String sha256);

Uni<List<BpmnBankConfig>> putAssociations(String acquirerId, FunctionTypeEnum functionTypeEnum, List<BpmnBankConfig> bpmnBankConfigs);
Uni<Optional<BpmnVersion>> findByPk(BpmnVersionPK bpmnVersionPK);

Uni<BpmnVersion> setBpmnVersionStatus(UUID id, Long modelVersion, StatusEnum status);
Uni<List<BpmnBankConfig>> putAssociations(String acquirerId, FunctionTypeEnum functionTypeEnum,
List<BpmnBankConfig> bpmnBankConfigs);

public Uni<Boolean> checkBpmnFileExistence(UUID id, Long modelVersion);
Uni<BpmnVersion> setBpmnVersionStatus(UUID id, Long modelVersion, StatusEnum status);

public Uni<Boolean> checkBpmnFileExistence(UUID id, Long modelVersion);

public Uni<BpmnVersion> setDeployInfo(UUID id, Long modelVersion, DeployResponseDto response);
}
Loading

0 comments on commit c6177b2

Please sign in to comment.