-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTYGFV-16796: Implementation of email notification enabled for deep …
…integrated users. (#1100) Co-authored-by: mhornfeldt <[email protected]> Co-authored-by: cigerhed <[email protected]>
- Loading branch information
1 parent
baab40b
commit ba65e8b
Showing
23 changed files
with
789 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"region": "Beta Regionen", | ||
"configuration": [ | ||
{ | ||
"datetime": "2024-08-01T08:00", | ||
"careProviders" : ["TSTNMT2321000156-BETA"], | ||
"issuedOnUnit" : [] | ||
} | ||
] | ||
} | ||
] |
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
65 changes: 65 additions & 0 deletions
65
.../java/se/inera/intyg/webcert/web/csintegration/certificate/GetUnitNotificationConfig.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,65 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package se.inera.intyg.webcert.web.csintegration.certificate; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class GetUnitNotificationConfig { | ||
|
||
|
||
@Value("${unit.notification.config.path:}") | ||
private String unitNotificationConfigPath; | ||
private List<RegionNotificationConfig> integratedUnitNotificationConfig; | ||
|
||
public List<RegionNotificationConfig> get() { | ||
if (integratedUnitNotificationConfig == null) { | ||
integratedUnitNotificationConfig = new ArrayList<>(); | ||
final var objectMapper = new ObjectMapper(); | ||
objectMapper.registerModule(new JavaTimeModule()); | ||
try (final var resourceAsStream = new FileInputStream(unitNotificationConfigPath)) { | ||
integratedUnitNotificationConfig = objectMapper.readValue( | ||
resourceAsStream, | ||
new TypeReference<>() { | ||
}); | ||
log.info("Integrated Unit Notification was loaded with configuration: {}", integratedUnitNotificationConfig); | ||
} catch (FileNotFoundException e) { | ||
log.warn("File not found: {}. Returning empty configuration.", unitNotificationConfigPath); | ||
} catch (Exception e) { | ||
log.error( | ||
String.format("Failed to load Integrated Unit Notification configuration. Reason: %s", e.getMessage()), e | ||
); | ||
} | ||
} | ||
return integratedUnitNotificationConfig; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...e/inera/intyg/webcert/web/csintegration/certificate/IntegratedUnitNotificationConfig.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,49 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package se.inera.intyg.webcert.web.csintegration.certificate; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Value; | ||
import se.inera.intyg.webcert.web.csintegration.certificate.IntegratedUnitNotificationConfig.IntegratedUnitNotificationConfigBuilder; | ||
|
||
@JsonInclude | ||
@JsonDeserialize(builder = IntegratedUnitNotificationConfigBuilder.class) | ||
@Builder | ||
@Value | ||
public class IntegratedUnitNotificationConfig { | ||
|
||
@JsonProperty("careProviders") | ||
List<String> careProviders; | ||
@JsonProperty("issuedOnUnit") | ||
List<String> issuedOnUnit; | ||
@JsonProperty("datetime") | ||
LocalDateTime datetime; | ||
|
||
@JsonPOJOBuilder(withPrefix = "") | ||
public static class IntegratedUnitNotificationConfigBuilder { | ||
|
||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...nera/intyg/webcert/web/csintegration/certificate/IntegratedUnitNotificationEvaluator.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,79 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package se.inera.intyg.webcert.web.csintegration.certificate; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class IntegratedUnitNotificationEvaluator { | ||
|
||
private final GetUnitNotificationConfig getUnitNotificationConfig; | ||
|
||
public boolean mailNotification(String careProviderId, String issuedOnUnitId, String certificateId, LocalDateTime issuingDate) { | ||
final var regionNotificationConfigs = getUnitNotificationConfig.get(); | ||
if (regionNotificationConfigs.isEmpty()) { | ||
return false; | ||
} | ||
|
||
if (evaluateMailNotification(careProviderId, issuedOnUnitId, regionNotificationConfigs, issuingDate)) { | ||
log.info( | ||
"Certificate with id '{}' has been evaluated and should receive mail notification. CareProviderId: '{}'," | ||
+ " IssuedOnUnitId: '{}', IssuingDate: '{}'", certificateId, careProviderId, issuedOnUnitId, issuingDate); | ||
return true; | ||
} | ||
|
||
log.info( | ||
"Certificate with id '{}' has been evaluated and should not receive mail notification. CareProviderId: '{}'," | ||
+ " IssuedOnUnitId: '{}', IssuingDate: '{}'", certificateId, careProviderId, issuedOnUnitId, issuingDate); | ||
return false; | ||
} | ||
|
||
private boolean evaluateMailNotification(String careProviderId, String issuedOnUnitId, | ||
List<RegionNotificationConfig> regionNotificationConfigs, LocalDateTime issuingDate) { | ||
return regionNotificationConfigs.stream() | ||
.map(RegionNotificationConfig::getConfiguration) | ||
.flatMap(List::stream) | ||
.anyMatch(config -> | ||
evaluateMailNotification( | ||
config.getIssuedOnUnit(), | ||
config.getCareProviders(), | ||
config.getDatetime(), | ||
issuedOnUnitId, | ||
careProviderId, | ||
issuingDate | ||
) | ||
); | ||
} | ||
|
||
private boolean evaluateMailNotification(List<String> unitIds, List<String> careProviderIds, LocalDateTime activateFrom, String unitId, | ||
String careProviderId, LocalDateTime issuingDate) { | ||
if ((careProviderIds != null && !careProviderIds.contains(careProviderId)) && (unitIds != null && !unitIds.contains(unitId))) { | ||
return false; | ||
} | ||
|
||
return activateFrom.isBefore(issuingDate); | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
...n/java/se/inera/intyg/webcert/web/csintegration/certificate/RegionNotificationConfig.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,46 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package se.inera.intyg.webcert.web.csintegration.certificate; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Value; | ||
import se.inera.intyg.webcert.web.csintegration.certificate.RegionNotificationConfig.RegionNotificationConfigBuilder; | ||
|
||
@JsonInclude | ||
@JsonDeserialize(builder = RegionNotificationConfigBuilder.class) | ||
@Builder | ||
@Value | ||
public class RegionNotificationConfig { | ||
|
||
@JsonProperty("region") | ||
String region; | ||
@JsonProperty("configuration") | ||
List<IntegratedUnitNotificationConfig> configuration; | ||
|
||
@JsonPOJOBuilder(withPrefix = "") | ||
public static class RegionNotificationConfigBuilder { | ||
|
||
} | ||
} |
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
Oops, something went wrong.