Skip to content

Commit

Permalink
same structure for all emails
Browse files Browse the repository at this point in the history
  • Loading branch information
wetret committed Sep 13, 2023
1 parent 8e8ec48 commit d0a5a6e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ private void sendMail(Task task, Variables variables)

String subject = "Error in process '" + ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_RECEIVE + "'";
String message = "Could not download and insert new data-set in process '"
+ ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_RECEIVE + "' from organization '"
+ task.getRequester().getIdentifier().getValue() + "' in Task with id '" + task.getId() + "':\n"
+ "- status code: " + ConstantsBase.CODESYSTEM_DATA_SET_STATUS_VALUE_RECEIVE_ERROR + "\n" + "- error: "
+ ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_RECEIVE + "' for Task with id '" + task.getId()
+ "' from organization '" + task.getRequester().getIdentifier().getValue() + "' in Task with id '"
+ task.getId() + "':\n" + "- status code: "
+ ConstantsBase.CODESYSTEM_DATA_SET_STATUS_VALUE_RECEIVE_ERROR + "\n" + "- error: "
+ (error == null ? "none" : error);

api.getMailService().send(subject, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ private void sendMail(Task task, Variables variables)

String subject = "Error in process '" + ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SEND_ERROR + "'";
String message = "Could not send data-set in process '" + ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_SEND
+ "' to DMS with identifier '" + dmsIdentifier + "' for project-identifier '" + projectIdentifier
+ "' in Task with id '" + task.getId() + "':\n" + "- status code: " + statusCode + "\n" + "- error: "
+ (error == null ? "none" : error);
+ "' for Task with id '" + task.getId() + "' to DMS with identifier '" + dmsIdentifier
+ "' for project-identifier '" + projectIdentifier + "':\n" + "- status code: " + statusCode + "\n"
+ "- error: " + (error == null ? "none" : error);

api.getMailService().send(subject, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected void doExecute(DelegateExecution execution, Variables variables)
ConstantsDataTransfer.CODESYSTEM_DATA_TRANSFER_VALUE_DATA_SET_STATUS));
variables.updateTask(task);

sendMail(createdIds, sendingOrganization, projectIdentifier);
sendMail(task, createdIds, sendingOrganization, projectIdentifier);
}
catch (Exception exception)
{
Expand Down Expand Up @@ -116,17 +116,18 @@ private List<IdType> storeData(Variables variables, FhirClient fhirClient, Bundl
return idsOfCreatedResources;
}

private void sendMail(List<IdType> createdIds, String sendingOrganization, String projectIdentifier)
private void sendMail(Task task, List<IdType> createdIds, String sendingOrganization, String projectIdentifier)
{
String subject = "New data-set received in process '" + ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_RECEIVE
+ "'";
StringBuilder message = new StringBuilder("New data-set has been stored for project-identifier '")
.append(projectIdentifier).append("' in process '")
.append(ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_RECEIVE).append("' received from organization '")
.append(sendingOrganization).append("' and can be accessed using the following links:\n");
StringBuilder message = new StringBuilder("A new data-set has been stored in process '"
+ ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_RECEIVE + "' for Task with id '" + task.getId()
+ "' received from organization '" + sendingOrganization + "' for project-identifier '"
+ projectIdentifier + "' with status code '" + ConstantsBase.CODESYSTEM_DATA_SET_STATUS_VALUE_RECEIVE_OK
+ "' and can be accessed using the following links:\n");

for (IdType id : createdIds)
message.append("- ").append(id.getValue()).append("\n");
message.append(id.getValue()).append("\n");

api.getMailService().send(subject, message.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ private void writeStatusLogAndSendMail(Task startTask, String projectIdentifier,
{
startTask.getOutput().stream().filter(o -> o.getValue() instanceof Coding)
.filter(o -> ConstantsBase.CODESYSTEM_DATA_SET_STATUS.equals(((Coding) o.getValue()).getSystem()))
.forEach(o -> doWriteStatusLogAndSendMail(o, startTask.getId(), projectIdentifier, dmsIdentifier));
.forEach(o -> doWriteStatusLogAndSendMail(o, startTask, projectIdentifier, dmsIdentifier));
}

private void doWriteStatusLogAndSendMail(Task.TaskOutputComponent output, String startTaskId,
String projectIdentifier, String dmsIdentifier)
private void doWriteStatusLogAndSendMail(Task.TaskOutputComponent output, Task task, String projectIdentifier,
String dmsIdentifier)
{
Coding status = (Coding) output.getValue();
String code = status.getCode();
Expand All @@ -101,40 +101,40 @@ private void doWriteStatusLogAndSendMail(Task.TaskOutputComponent output, String
{
logger.info(
"Task with id '{}' for project-identifier '{}' and DMS with identifier '{}' has data-set status code '{}'",
startTaskId, projectIdentifier, dmsIdentifier, code);
task, projectIdentifier, dmsIdentifier, code);

sendSuccessfulMail(projectIdentifier, dmsIdentifier, code);
sendSuccessfulMail(task, projectIdentifier, dmsIdentifier, code);
}
else
{
String errorLog = error.isBlank() ? "" : " - " + error;
logger.warn(
"Task with id '{}' for project-identifier '{}' and DMS with identifier '{}' has data-set status code '{}'{}",
startTaskId, projectIdentifier, dmsIdentifier, code, errorLog);
task.getId(), projectIdentifier, dmsIdentifier, code, errorLog);

sendErrorMail(startTaskId, projectIdentifier, dmsIdentifier, code, error);
sendErrorMail(task, projectIdentifier, dmsIdentifier, code, error);
}
}

private void sendSuccessfulMail(String projectIdentifier, String dmsIdentifier, String code)
private void sendSuccessfulMail(Task task, String projectIdentifier, String dmsIdentifier, String code)
{
String subject = "Data-set successfully delivered in process '"
+ ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_SEND + "'";
String message = "A data-set has been successfully delivered and retrieved by the DMS with identifier '"
+ dmsIdentifier + "' for project-identifier '" + projectIdentifier + "' with status code '" + code
+ "' in process '" + ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_SEND + "'";
String message = "A data-set has been successfully delivered and retrieved in process '"
+ ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_SEND + "' for Task with id '" + task.getId()
+ "' to/from DMS with identifier '" + dmsIdentifier + "' for project-identifier '" + projectIdentifier
+ "' with status code '" + code + "'";

api.getMailService().send(subject, message);
}

private void sendErrorMail(String startTaskId, String projectIdentifier, String dmsIdentifier, String code,
String error)
private void sendErrorMail(Task task, String projectIdentifier, String dmsIdentifier, String code, String error)
{
String subject = "Error in process '" + ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_SEND + "'";
String message = "DMS '" + dmsIdentifier
+ "' could not download, decrypt, validate or insert data-set for project-identifier '"
+ projectIdentifier + "' in process '" + ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_SEND
+ "' in Task with id '" + startTaskId + "':\n" + "- status code: " + code + "\n" + "- error: " + error;
String message = "Could not download, decrypt, validate or insert data-set in process '"
+ ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_SEND + "' for Task with id '" + task.getId()
+ "' at DMS with identifier '" + dmsIdentifier + "' for project-identifier '" + projectIdentifier
+ "':\n" + "- status code: " + code + "\n" + "- error: " + error;

api.getMailService().send(subject, message);
}
Expand Down

0 comments on commit d0a5a6e

Please sign in to comment.