|
1 | 1 | package de.netzwerk_universitaetsmedizin.codex.processes.data_transfer.logging; |
2 | 2 |
|
| 3 | +import java.util.Objects; |
| 4 | + |
| 5 | +import org.highmed.dsf.bpe.service.MailService; |
3 | 6 | import org.hl7.fhir.r4.model.IdType; |
4 | 7 | import org.slf4j.Logger; |
5 | 8 | import org.slf4j.LoggerFactory; |
| 9 | +import org.springframework.beans.factory.InitializingBean; |
6 | 10 |
|
7 | | -public class ErrorLogger |
| 11 | +public class ErrorLogger implements InitializingBean |
8 | 12 | { |
9 | 13 | private static final Logger validationLogger = LoggerFactory.getLogger("validation-error-logger"); |
10 | 14 | private static final Logger errorLogger = LoggerFactory.getLogger("error-logger"); |
11 | 15 |
|
| 16 | + private final MailService mailService; |
| 17 | + |
| 18 | + private final boolean sendValidationFailedMail; |
| 19 | + private final boolean sendProcessFailedMail; |
| 20 | + |
| 21 | + public ErrorLogger(MailService mailService, boolean sendValidationFailedMail, boolean sendProcessFailedMail) |
| 22 | + { |
| 23 | + this.mailService = mailService; |
| 24 | + |
| 25 | + this.sendValidationFailedMail = sendValidationFailedMail; |
| 26 | + this.sendProcessFailedMail = sendProcessFailedMail; |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public void afterPropertiesSet() throws Exception |
| 31 | + { |
| 32 | + Objects.requireNonNull(mailService, "mailService"); |
| 33 | + } |
| 34 | + |
12 | 35 | public void logValidationFailed(IdType taskId) |
13 | 36 | { |
14 | | - validationLogger.debug("Validation of FHIR resources failed, started by Task {}", taskId.getValue()); |
| 37 | + validationLogger.debug("Validation of FHIR resources failed in process started by {}", |
| 38 | + taskId.toVersionless().getValue()); |
| 39 | + |
| 40 | + if (sendValidationFailedMail) |
| 41 | + mailService.send("Validation Error", |
| 42 | + "Validation of FHIR resources failed in process started by " + taskId.toVersionless().getValue()); |
15 | 43 | } |
16 | 44 |
|
17 | 45 | public void logValidationFailedLocal(IdType taskId) |
18 | 46 | { |
19 | | - validationLogger.debug("Local validation of FHIR resources failed, started by Task {}", taskId.getValue()); |
| 47 | + validationLogger.debug("Local validation of FHIR resources failed in process started by {}", |
| 48 | + taskId.toVersionless().getValue()); |
| 49 | + |
| 50 | + if (sendValidationFailedMail) |
| 51 | + mailService.send("Validation Error", "Local validation of FHIR resources failed in process started by " |
| 52 | + + taskId.toVersionless().getValue()); |
20 | 53 | } |
21 | 54 |
|
22 | 55 | public void logValidationFailedRemote(IdType taskId) |
23 | 56 | { |
24 | | - validationLogger.debug("Remote validation of FHIR resources failed, started by Task {}", taskId.getValue()); |
| 57 | + validationLogger.debug("Remote validation of FHIR resources failed in process started by {}", |
| 58 | + taskId.toVersionless().getValue()); |
| 59 | + |
| 60 | + if (sendValidationFailedMail) |
| 61 | + mailService.send("Validation Error", "Remote validation of FHIR resources failed in process started by " |
| 62 | + + taskId.toVersionless().getValue()); |
25 | 63 | } |
26 | 64 |
|
27 | 65 | public void logDataSendFailed(IdType taskId) |
28 | 66 | { |
29 | | - errorLogger.debug("Send process failed, started by Task {}", taskId.getValue()); |
| 67 | + errorLogger.debug("Send process failed started by {}", taskId.toVersionless().getValue()); |
| 68 | + |
| 69 | + if (sendProcessFailedMail) |
| 70 | + mailService.send("Proccess Failed", "Send process failed started by " + taskId.toVersionless().getValue()); |
30 | 71 | } |
31 | 72 |
|
32 | 73 | public void logDataTranslateFailed(IdType taskId) |
33 | 74 | { |
34 | | - errorLogger.debug("Translate process failed, started by Task {}", taskId.getValue()); |
| 75 | + errorLogger.debug("Translate process failed started by {}", taskId.toVersionless().getValue()); |
| 76 | + |
| 77 | + if (sendProcessFailedMail) |
| 78 | + mailService.send("Proccess Failed", |
| 79 | + "Translate process failed started by " + taskId.toVersionless().getValue()); |
35 | 80 | } |
36 | 81 |
|
37 | 82 | public void logDataReceiveFailed(IdType taskId) |
38 | 83 | { |
39 | | - errorLogger.debug("Receive process failed, started by Task {}", taskId.getValue()); |
| 84 | + errorLogger.debug("Receive process failed started by {}", taskId.toVersionless().getValue()); |
| 85 | + |
| 86 | + if (sendProcessFailedMail) |
| 87 | + mailService.send("Proccess Failed", |
| 88 | + "Receive process failed started by " + taskId.toVersionless().getValue()); |
40 | 89 | } |
41 | 90 | } |
0 commit comments