Skip to content

Commit

Permalink
fixed exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciaM1 committed Nov 24, 2023
1 parent 1213fa4 commit 6b91981
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public enum AppErrorCodeEnum {
RESOURCE_FILE_DOES_NOT_EXIST("ATMLM_4000031", "The referenced Resource file does not exist", NOT_EXISTING_REFERENCED_ENTITY),
WORKFLOW_RESOURCE_WITH_SAME_SHA256_ALREADY_EXISTS("ATMLM_4000032","A workflow resource with the same content already exists", CONSTRAINT_VIOLATION),
DEPLOYED_FILE_WAS_NOT_RETRIEVED("ATMLM_4000033","Error with Process communication: the referenced file was not retrieved", INTERNAL),
WORKFLOW_RESOURCE_NOT_DEPLOYED_CANNOT_ROLLBACK("ATMLM_4000034","CamundaDefinitionId of the referenced resource is null: cannot rollback", NOT_EXISTING_REFERENCED_ENTITY);

WORKFLOW_RESOURCE_NOT_DEPLOYED_CANNOT_ROLLBACK("ATMLM_4000034","CamundaDefinitionId of the referenced resource is null: cannot rollback", NOT_EXISTING_REFERENCED_ENTITY),
WORKFLOW_RESOURCE_CANNOT_BE_ROLLED_BACK("ATMLM_4000035","Cannot rollback: the referenced resource coincides with the latest deployed version", CANNOT_ROLLBACK);
private final String errorCode;
private final String errorMessage;
private final AppErrorType type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public enum AppErrorType {
ID_NOT_FOUND,
INVALID_ARGUMENT,
NOT_UPDATABLE,
NOT_UPLOADABLE
NOT_UPLOADABLE,
CANNOT_ROLLBACK
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.DEPLOY_ERROR;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.OBJECT_STORE_SAVE_FILE_ERROR;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.WORKFLOW_FILE_DOES_NOT_EXIST;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.WORKFLOW_RESOURCE_CANNOT_BE_ROLLED_BACK;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.WORKFLOW_RESOURCE_CANNOT_BE_UPDATED;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.WORKFLOW_RESOURCE_FILE_WITH_SAME_CAMUNDA_DEFINITION_KEY_ALREADY_EXISTS;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.WORKFLOW_RESOURCE_FILE_WITH_SAME_CONTENT_ALREADY_EXIST;
Expand Down Expand Up @@ -339,20 +340,22 @@ public Uni<WorkflowResource> rollback(UUID id) {
.onItem()
.transformToUni(Unchecked.function(workflow -> {
if (workflow.isEmpty()) {
throw new AtmLayerException(Response.Status.NOT_FOUND, WORKFLOW_FILE_DOES_NOT_EXIST);
throw new AtmLayerException("The referenced workflow resource does not exist",Response.Status.NOT_FOUND, WORKFLOW_FILE_DOES_NOT_EXIST);
}
WorkflowResource workflowResourceToRollBack = workflow.get();
if (workflowResourceToRollBack.getStatus().getValue().equals(StatusEnum.DEPLOYED.getValue())){
throw new AtmLayerException("Cannot rollback: the referenced resource is the latest version deployed", Response.Status.BAD_REQUEST,WORKFLOW_RESOURCE_CANNOT_BE_ROLLED_BACK);
}
String camundaId = workflowResourceToRollBack.getCamundaDefinitionId();
if (camundaId == null) {
throw new AtmLayerException("CamundaDefinitionId of the referenced resource is null: cannot rollback", Response.Status.NOT_FOUND, WORKFLOW_RESOURCE_NOT_DEPLOYED_CANNOT_ROLLBACK);
}
return processClient.getDeployedResource(camundaId)
.onItem()
.transformToUni(Unchecked.function(file -> update(id, file, true)))
.onFailure()
.recoverWithUni(exception ->
Uni.createFrom().failure(new AtmLayerException("Error retrieving workflow resource from Process", Response.Status.INTERNAL_SERVER_ERROR, DEPLOYED_FILE_WAS_NOT_RETRIEVED))
);
Uni.createFrom().failure(new AtmLayerException("Error retrieving workflow resource from Process", Response.Status.INTERNAL_SERVER_ERROR, DEPLOYED_FILE_WAS_NOT_RETRIEVED)))
.onItem()
.transformToUni(Unchecked.function(file -> update(id, file, true)));
}));
}
}

0 comments on commit 6b91981

Please sign in to comment.