-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/release/0.7.0' into main
- Loading branch information
Showing
87 changed files
with
924 additions
and
621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
...k_universitaetsmedizin/codex/processes/data_transfer/listener/AfterDryRunEndListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package de.netzwerk_universitaetsmedizin.codex.processes.data_transfer.listener; | ||
|
||
import static de.netzwerk_universitaetsmedizin.codex.processes.data_transfer.ConstantsDataTransfer.CODESYSTEM_NUM_CODEX_DATA_TRANSFER; | ||
import static de.netzwerk_universitaetsmedizin.codex.processes.data_transfer.ConstantsDataTransfer.CODESYSTEM_NUM_CODEX_DATA_TRANSFER_VALUE_LOCAL_VALIDATION_SUCCESSFUL; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Objects; | ||
|
||
import javax.activation.DataHandler; | ||
import javax.mail.internet.MimeBodyPart; | ||
import javax.mail.internet.MimeMultipart; | ||
import javax.mail.util.ByteArrayDataSource; | ||
|
||
import org.camunda.bpm.engine.delegate.DelegateExecution; | ||
import org.camunda.bpm.engine.delegate.ExecutionListener; | ||
import org.highmed.dsf.bpe.service.MailService; | ||
import org.highmed.dsf.fhir.client.FhirWebserviceClientProvider; | ||
import org.highmed.dsf.fhir.task.TaskHelper; | ||
import org.hl7.fhir.r4.model.BooleanType; | ||
import org.hl7.fhir.r4.model.Task; | ||
import org.hl7.fhir.r4.model.Task.TaskOutputComponent; | ||
import org.hl7.fhir.r4.model.Task.TaskStatus; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.InitializingBean; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import de.netzwerk_universitaetsmedizin.codex.processes.data_transfer.DataTransferProcessPluginDefinition; | ||
|
||
public class AfterDryRunEndListener implements ExecutionListener, InitializingBean | ||
{ | ||
private static final Logger logger = LoggerFactory.getLogger(AfterDryRunEndListener.class); | ||
|
||
private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
|
||
private final TaskHelper taskHelper; | ||
private final FhirWebserviceClientProvider clientProvider; | ||
private final FhirContext fhirContext; | ||
private final MailService mailService; | ||
|
||
private final String localOrganizationIdentifierValue; | ||
private final boolean sendDryRunSuccessMail; | ||
|
||
public AfterDryRunEndListener(TaskHelper taskHelper, FhirWebserviceClientProvider clientProvider, | ||
FhirContext fhirContext, MailService mailService, String localOrganizationIdentifierValue, | ||
boolean sendDryRunSuccessMail) | ||
{ | ||
this.taskHelper = taskHelper; | ||
this.clientProvider = clientProvider; | ||
this.fhirContext = fhirContext; | ||
this.mailService = mailService; | ||
|
||
this.localOrganizationIdentifierValue = localOrganizationIdentifierValue; | ||
this.sendDryRunSuccessMail = sendDryRunSuccessMail; | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() throws Exception | ||
{ | ||
Objects.requireNonNull(taskHelper, "taskHelper"); | ||
Objects.requireNonNull(clientProvider, "clientProvider"); | ||
Objects.requireNonNull(fhirContext, "fhirContext"); | ||
Objects.requireNonNull(mailService, "mailService"); | ||
|
||
Objects.requireNonNull(localOrganizationIdentifierValue, "localOrganizationIdentifierValue"); | ||
} | ||
|
||
@Override | ||
public void notify(DelegateExecution execution) throws Exception | ||
{ | ||
if (!sendDryRunSuccessMail) | ||
return; | ||
|
||
Task task = taskHelper.getLeadingTaskFromExecutionVariables(execution); | ||
Task finalTask = clientProvider.getLocalWebserviceClient().read(Task.class, task.getIdElement().getIdPart()); | ||
|
||
if (!TaskStatus.COMPLETED.equals(finalTask.getStatus())) | ||
{ | ||
logger.warn("Final Task from DSF FHIR server not in status {} but {}, not sending dry-run success mail", | ||
TaskStatus.COMPLETED, finalTask.getStatus()); | ||
return; | ||
} | ||
|
||
if (!isLocalValidationSuccessful(finalTask)) | ||
{ | ||
logger.warn( | ||
"Final Task from DSF FHIR server missing '{}' output parameter with value 'true', not sending dry-run success mail", | ||
CODESYSTEM_NUM_CODEX_DATA_TRANSFER_VALUE_LOCAL_VALIDATION_SUCCESSFUL); | ||
return; | ||
} | ||
|
||
String finalTaskAsXml = fhirContext.newXmlParser().setPrettyPrint(true).encodeResourceToString(finalTask); | ||
String attachmentFilename = finalTask.getIdElement().getIdPart() + ".xml"; | ||
|
||
MimeBodyPart text = new MimeBodyPart(); | ||
text.setText(createMesssage(finalTask, attachmentFilename)); | ||
|
||
MimeBodyPart attachment = new MimeBodyPart(); | ||
attachment.setFileName(attachmentFilename); | ||
attachment.setDataHandler(new DataHandler( | ||
new ByteArrayDataSource(finalTaskAsXml.getBytes(StandardCharsets.UTF_8), "application/xml"))); | ||
|
||
MimeMultipart body = new MimeMultipart(); | ||
body.addBodyPart(text); | ||
body.addBodyPart(attachment); | ||
|
||
MimeBodyPart message = new MimeBodyPart(); | ||
message.setContent(body); | ||
|
||
mailService.send("Dry-Run Success: " + localOrganizationIdentifierValue, message); | ||
} | ||
|
||
private boolean isLocalValidationSuccessful(Task task) | ||
{ | ||
return task.getOutput().stream().filter(TaskOutputComponent::hasType).filter(o -> o.getType().hasCoding()) | ||
.filter(o -> o.getType().getCoding().stream() | ||
.anyMatch(c -> CODESYSTEM_NUM_CODEX_DATA_TRANSFER.equals(c.getSystem()) | ||
&& CODESYSTEM_NUM_CODEX_DATA_TRANSFER_VALUE_LOCAL_VALIDATION_SUCCESSFUL | ||
.equals(c.getCode()))) | ||
.filter(TaskOutputComponent::hasValue).filter(o -> o.getValue() instanceof BooleanType) | ||
.map(o -> (BooleanType) o.getValue()).anyMatch(b -> Boolean.TRUE.equals(b.getValue())); | ||
} | ||
|
||
private String createMesssage(Task finalTask, String attachmentFileName) | ||
{ | ||
StringBuilder b = new StringBuilder(); | ||
|
||
b.append("Send process version "); | ||
b.append(DataTransferProcessPluginDefinition.VERSION); | ||
b.append(" dry-run at organization with identifier '"); | ||
b.append(localOrganizationIdentifierValue); | ||
b.append("' successfully completed on "); | ||
b.append(DATE_FORMAT.format(finalTask.getMeta().getLastUpdated())); | ||
b.append(".\n\nTask resource is attached as '"); | ||
b.append(attachmentFileName); | ||
b.append("'"); | ||
|
||
return b.toString(); | ||
} | ||
} |
63 changes: 56 additions & 7 deletions
63
...a/de/netzwerk_universitaetsmedizin/codex/processes/data_transfer/logging/ErrorLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,90 @@ | ||
package de.netzwerk_universitaetsmedizin.codex.processes.data_transfer.logging; | ||
|
||
import java.util.Objects; | ||
|
||
import org.highmed.dsf.bpe.service.MailService; | ||
import org.hl7.fhir.r4.model.IdType; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.InitializingBean; | ||
|
||
public class ErrorLogger | ||
public class ErrorLogger implements InitializingBean | ||
{ | ||
private static final Logger validationLogger = LoggerFactory.getLogger("validation-error-logger"); | ||
private static final Logger errorLogger = LoggerFactory.getLogger("error-logger"); | ||
|
||
private final MailService mailService; | ||
|
||
private final boolean sendValidationFailedMail; | ||
private final boolean sendProcessFailedMail; | ||
|
||
public ErrorLogger(MailService mailService, boolean sendValidationFailedMail, boolean sendProcessFailedMail) | ||
{ | ||
this.mailService = mailService; | ||
|
||
this.sendValidationFailedMail = sendValidationFailedMail; | ||
this.sendProcessFailedMail = sendProcessFailedMail; | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() throws Exception | ||
{ | ||
Objects.requireNonNull(mailService, "mailService"); | ||
} | ||
|
||
public void logValidationFailed(IdType taskId) | ||
{ | ||
validationLogger.debug("Validation of FHIR resources failed, started by Task {}", taskId.getValue()); | ||
validationLogger.debug("Validation of FHIR resources failed in process started by {}", | ||
taskId.toVersionless().getValue()); | ||
|
||
if (sendValidationFailedMail) | ||
mailService.send("Validation Error", | ||
"Validation of FHIR resources failed in process started by " + taskId.toVersionless().getValue()); | ||
} | ||
|
||
public void logValidationFailedLocal(IdType taskId) | ||
{ | ||
validationLogger.debug("Local validation of FHIR resources failed, started by Task {}", taskId.getValue()); | ||
validationLogger.debug("Local validation of FHIR resources failed in process started by {}", | ||
taskId.toVersionless().getValue()); | ||
|
||
if (sendValidationFailedMail) | ||
mailService.send("Validation Error", "Local validation of FHIR resources failed in process started by " | ||
+ taskId.toVersionless().getValue()); | ||
} | ||
|
||
public void logValidationFailedRemote(IdType taskId) | ||
{ | ||
validationLogger.debug("Remote validation of FHIR resources failed, started by Task {}", taskId.getValue()); | ||
validationLogger.debug("Remote validation of FHIR resources failed in process started by {}", | ||
taskId.toVersionless().getValue()); | ||
|
||
if (sendValidationFailedMail) | ||
mailService.send("Validation Error", "Remote validation of FHIR resources failed in process started by " | ||
+ taskId.toVersionless().getValue()); | ||
} | ||
|
||
public void logDataSendFailed(IdType taskId) | ||
{ | ||
errorLogger.debug("Send process failed, started by Task {}", taskId.getValue()); | ||
errorLogger.debug("Send process failed started by {}", taskId.toVersionless().getValue()); | ||
|
||
if (sendProcessFailedMail) | ||
mailService.send("Proccess Failed", "Send process failed started by " + taskId.toVersionless().getValue()); | ||
} | ||
|
||
public void logDataTranslateFailed(IdType taskId) | ||
{ | ||
errorLogger.debug("Translate process failed, started by Task {}", taskId.getValue()); | ||
errorLogger.debug("Translate process failed started by {}", taskId.toVersionless().getValue()); | ||
|
||
if (sendProcessFailedMail) | ||
mailService.send("Proccess Failed", | ||
"Translate process failed started by " + taskId.toVersionless().getValue()); | ||
} | ||
|
||
public void logDataReceiveFailed(IdType taskId) | ||
{ | ||
errorLogger.debug("Receive process failed, started by Task {}", taskId.getValue()); | ||
errorLogger.debug("Receive process failed started by {}", taskId.toVersionless().getValue()); | ||
|
||
if (sendProcessFailedMail) | ||
mailService.send("Proccess Failed", | ||
"Receive process failed started by " + taskId.toVersionless().getValue()); | ||
} | ||
} |
Oops, something went wrong.