Skip to content

Commit

Permalink
added missing try-catch and harmonized error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wetret committed Oct 31, 2024
1 parent eb27dcb commit 617b6d5
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.hl7.fhir.r4.model.DocumentReference;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.ResourceType;
import org.hl7.fhir.r4.model.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
Expand Down Expand Up @@ -48,6 +49,7 @@ public void afterPropertiesSet() throws Exception
@Override
protected void doExecute(DelegateExecution execution, Variables variables)
{
Task task = variables.getStartTask();
String projectIdentifier = variables
.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_PROJECT_IDENTIFIER);
String dmsIdentifier = variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DMS_IDENTIFIER);
Expand All @@ -56,14 +58,26 @@ protected void doExecute(DelegateExecution execution, Variables variables)
"Creating transferable data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}'",
dmsIdentifier, projectIdentifier, variables.getStartTask().getId());

DocumentReference documentReference = variables
.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DOCUMENT_REFERENCE);
Resource resource = variables.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RESOURCE);
Bundle bundle = createTransactionBundle(variables, projectIdentifier, documentReference, resource);

dataLogger.logResource("Created Transfer Bundle", bundle);

variables.setResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET, bundle);
try
{
DocumentReference documentReference = variables
.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DOCUMENT_REFERENCE);
Resource resource = variables.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RESOURCE);

Bundle bundle = createTransactionBundle(variables, projectIdentifier, documentReference, resource);
dataLogger.logResource("Created Transfer Bundle", bundle);

variables.setResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET, bundle);
}
catch (Exception exception)
{
logger.warn(
"Could not create transferable data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
dmsIdentifier, projectIdentifier, task.getId(), exception.getMessage());

String error = "Create transferable data-set failed - " + exception.getMessage();
throw new RuntimeException(error, exception);
}
}

private Bundle createTransactionBundle(Variables variables, String projectIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,16 @@ protected void doExecute(DelegateExecution execution, Variables variables)
ConstantsDataTransfer.CODESYSTEM_DATA_TRANSFER_VALUE_DATA_SET_STATUS, "Decrypt data-set failed"));
variables.updateTask(task);

variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE,
"Decrypt data-set failed");

logger.warn(
"Could not decrypt data-set with id '{}' from organization '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET_REFERENCE),
task.getRequester().getIdentifier().getValue(),
variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_PROJECT_IDENTIFIER), task.getId(),
exception.getMessage());
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR,
"Decrypt data-set - " + exception.getMessage());

String error = "Decrypt data-set failed - " + exception.getMessage();
variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE, error);
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR, error, exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ protected void doExecute(DelegateExecution execution, Variables variables)
logger.warn(
"Could not permanently delete data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
dmsIdentifier, projectIdentifier, task.getId(), exception.getMessage());
throw new RuntimeException("Could not permanently delete data-set for DMS '" + dmsIdentifier
+ "' and project-identifier '" + projectIdentifier + "' referenced in Task with id '" + task.getId()
+ "' - " + exception.getMessage(), exception);

String error = "Permanently deleting encrypted transferable data-set failed - " + exception.getMessage();
throw new RuntimeException(error, exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ protected void doExecute(DelegateExecution execution, Variables variables)
ConstantsDataTransfer.CODESYSTEM_DATA_TRANSFER_VALUE_DATA_SET_STATUS, "Download data-set failed"));
variables.updateTask(task);

variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE,
"Download data-set failed");

logger.warn(
"Could not download data-set with id '{}' from organization '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
dataSetReference.getValue(), sendingOrganization, projectIdentifier, task.getId(),
exception.getMessage());
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR,
"Download data-set - " + exception.getMessage());

String error = "Download data-set failed - " + exception.getMessage();
variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE, error);
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR, error, exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ protected void doExecute(DelegateExecution execution, Variables variables)
String projectIdentifier = variables
.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_PROJECT_IDENTIFIER);
String dmsIdentifier = variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DMS_IDENTIFIER);
Bundle toEncrypt = variables.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET);
String localOrganizationIdentifier = api.getOrganizationProvider().getLocalOrganizationIdentifierValue()
.orElseThrow(() -> new RuntimeException("LocalOrganizationIdentifierValue is null"));

logger.info(
"Encrypting transferable data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}'",
dmsIdentifier, projectIdentifier, task.getId());

try
{
Bundle toEncrypt = variables.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET);
String localOrganizationIdentifier = api.getOrganizationProvider().getLocalOrganizationIdentifierValue()
.orElseThrow(() -> new RuntimeException("LocalOrganizationIdentifierValue is null"));

PublicKey publicKey = readPublicKey(dmsIdentifier);
byte[] encrypted = encrypt(publicKey, toEncrypt, localOrganizationIdentifier, dmsIdentifier);

Expand All @@ -76,9 +77,9 @@ protected void doExecute(DelegateExecution execution, Variables variables)
logger.warn(
"Could not encrypt data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
dmsIdentifier, projectIdentifier, task.getId(), exception.getMessage());
throw new RuntimeException("Could not encrypt data-set for DMS '" + dmsIdentifier
+ "' and project-identifier '" + projectIdentifier + "' referenced in Task with id '" + task.getId()
+ "' - " + exception.getMessage(), exception);

String error = "Encrypt transferable data-set failed - " + exception.getMessage();
throw new RuntimeException(error, exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ protected void doExecute(DelegateExecution delegateExecution, Variables variable
String error = variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE);

sendMail(task, projectIdentifier, error);

task.setStatus(Task.TaskStatus.FAILED);
api.getFhirWebserviceClientProvider().getLocalWebserviceClient()
.withRetry(ConstantsBase.DSF_CLIENT_RETRY_6_TIMES, ConstantsBase.DSF_CLIENT_RETRY_INTERVAL_5MIN)
.update(task);
variables.updateTask(task);
}

private void sendMail(Task task, String projectIdentifier, String error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,16 @@ protected void doExecute(DelegateExecution execution, Variables variables)
ConstantsDataTransfer.CODESYSTEM_DATA_TRANSFER_VALUE_DATA_SET_STATUS, "Insert data-set failed"));
variables.updateTask(task);

variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE,
"Insert data-set failed");

logger.warn(
"Could not insert data-set with id '{}' from organization '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET_REFERENCE),
task.getRequester().getIdentifier().getValue(),
variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_PROJECT_IDENTIFIER), task.getId(),
exception.getMessage());
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR,
"Insert data-set - " + exception.getMessage());

String error = "Insert data-set failed - " + exception.getMessage();
variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE, error);
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR, error, exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ protected void doExecute(DelegateExecution execution, Variables variables)
"Could not read data-set on FHIR server with baseUrl '{}' for DMS '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
fhirClient.getFhirBaseUrl(), dmsIdentifier, projectIdentifier, task.getId(),
exception.getMessage());
throw new RuntimeException(
"Could not read data-set on FHIR server with baseUrl '" + fhirClient.getFhirBaseUrl()
+ "' for DMS '" + dmsIdentifier + "' and project-identifier '" + projectIdentifier
+ "' referenced in Task with id '" + task.getId() + "' - " + exception.getMessage());

String error = "Read data-set failed - " + exception.getMessage();
throw new RuntimeException(error, exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public StoreData(ProcessPluginApi api)
protected void doExecute(DelegateExecution execution, Variables variables)
{
Task task = variables.getStartTask();
byte[] bundleEncrypted = variables
.getByteArray(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET_ENCRYPTED);
String dmsIdentifier = variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DMS_IDENTIFIER);
String projectIdentifier = variables
.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_PROJECT_IDENTIFIER);
byte[] bundleEncrypted = variables
.getByteArray(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET_ENCRYPTED);

logger.info(
"Storing encrypted transferable data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}'",
Expand All @@ -60,9 +60,9 @@ protected void doExecute(DelegateExecution execution, Variables variables)
logger.warn(
"Could not store data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
dmsIdentifier, projectIdentifier, task.getId(), exception.getMessage());
throw new RuntimeException("Could not store data-set for DMS '" + dmsIdentifier
+ "' and project-identifier '" + projectIdentifier + "' referenced in Task with id '" + task.getId()
+ "' - " + exception.getMessage(), exception);

String error = "Store encrypted transferable data-set failed - " + exception.getMessage();
throw new RuntimeException(error, exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ private void doWriteStatusLogAndSendMail(Task.TaskOutputComponent output, Task t
{
String errorLog = error.isBlank() ? "" : " - " + error;
logger.warn(
"Task with id '{}' for project-identifier '{}' and DMS with identifier '{}' has data-set status code '{}'{}",
task.getId(), projectIdentifier, dmsIdentifier, code, errorLog);
"Could not deliver encrypted transferable data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}'{}",
dmsIdentifier, projectIdentifier, task.getId(), errorLog);

sendErrorMail(task, projectIdentifier, dmsIdentifier, code, error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
Expand Down Expand Up @@ -36,17 +37,31 @@ public void afterPropertiesSet() throws Exception
@Override
protected void doExecute(DelegateExecution execution, Variables variables)
{
Task task = variables.getStartTask();
String projectIdentifier = variables
.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_PROJECT_IDENTIFIER);
String dmsIdentifier = variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DMS_IDENTIFIER);
Resource resource = variables.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RESOURCE);

logger.info("Validating data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}'",
dmsIdentifier, projectIdentifier, variables.getStartTask().getId());

String mimeType = mimeTypeHelper.getMimeType(resource);
byte[] data = mimeTypeHelper.getData(resource);
try
{
Resource resource = variables.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RESOURCE);

mimeTypeHelper.validate(data, mimeType);
String mimeType = mimeTypeHelper.getMimeType(resource);
byte[] data = mimeTypeHelper.getData(resource);

mimeTypeHelper.validate(data, mimeType);
}
catch (Exception exception)
{
logger.warn(
"Could not validate data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
dmsIdentifier, projectIdentifier, task.getId(), exception.getMessage());

String error = "Validate data-set failed - " + exception.getMessage();
throw new RuntimeException(error, exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,16 @@ protected void doExecute(DelegateExecution execution, Variables variables)
ConstantsDataTransfer.CODESYSTEM_DATA_TRANSFER_VALUE_DATA_SET_STATUS, "Validate data-set failed"));
variables.updateTask(task);

variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE,
"Validate data-set failed");

logger.warn(
"Could not validate data-set with id '{}' from organization '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET_REFERENCE),
task.getRequester().getIdentifier().getValue(),
variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_PROJECT_IDENTIFIER), task.getId(),
exception.getMessage());
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR,
"Validate data-set - " + exception.getMessage());

String error = "Validate data-set failed - " + exception.getMessage();
variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE, error);
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR, error, exception);
}
}
}

0 comments on commit 617b6d5

Please sign in to comment.