diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/client/IConfigClient.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/client/IConfigClient.java index b4f00af..4994562 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/client/IConfigClient.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/client/IConfigClient.java @@ -17,5 +17,5 @@ public interface IConfigClient { String getGatewayName(); - + String getEDSStrategy(); } diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/client/impl/ConfigClient.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/client/impl/ConfigClient.java index 249ec45..b8e986e 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/client/impl/ConfigClient.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/client/impl/ConfigClient.java @@ -14,6 +14,7 @@ import it.finanze.sanita.fse2.ms.gtw.rulesmanager.client.IConfigClient; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.config.Constants; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.dto.WhoIsResponseDTO; +import it.finanze.sanita.fse2.ms.gtw.rulesmanager.enums.EdsStrategyEnum; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.exceptions.BusinessException; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.utility.ProfileUtility; import lombok.extern.slf4j.Slf4j; @@ -35,22 +36,22 @@ public class ConfigClient implements IConfigClient { * Config host. */ @Value("${ms.url.gtw-config}") - private String configHost; + private String host; @Autowired - private RestTemplate restTemplate; + private RestTemplate rest; @Autowired - private ProfileUtility profileUtility; + private ProfileUtility profile; @Override public String getGatewayName() { String gatewayName; try { log.debug("Config Client - Calling Config Client to get Gateway Name"); - final String endpoint = configHost + "/v1/whois"; + final String endpoint = host + "/v1/whois"; - final boolean isTestEnvironment = profileUtility.isDevOrDockerProfile() || profileUtility.isTestProfile(); + final boolean isTestEnvironment = profile.isDevOrDockerProfile() || profile.isTestProfile(); // Check if the endpoint is reachable if (isTestEnvironment && !isReachable()) { @@ -58,7 +59,7 @@ public String getGatewayName() { return Constants.AppConstants.MOCKED_GATEWAY_NAME; } - final ResponseEntity response = restTemplate.getForEntity(endpoint, WhoIsResponseDTO.class); + final ResponseEntity response = rest.getForEntity(endpoint, WhoIsResponseDTO.class); if (response.getStatusCode().is2xxSuccessful() && response.hasBody()) { WhoIsResponseDTO body = response.getBody(); @@ -73,10 +74,20 @@ public String getGatewayName() { return gatewayName; } + @Override + public String getEDSStrategy() { + String output = EdsStrategyEnum.NO_EDS.name(); + if(isReachable()) { + String endpoint = host + "/v1/config-items/props?type=GENERIC&props=eds-strategy"; + output = rest.getForObject(endpoint,String.class); + } + return output; + } + private boolean isReachable() { try { - final String endpoint = configHost + "/status"; - restTemplate.getForEntity(endpoint, String.class); + final String endpoint = host + "/status"; + rest.getForEntity(endpoint, String.class); return true; } catch (ResourceAccessException clientException) { return false; diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/enums/EdsStrategyEnum.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/enums/EdsStrategyEnum.java new file mode 100644 index 0000000..352cdac --- /dev/null +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/enums/EdsStrategyEnum.java @@ -0,0 +1,7 @@ +package it.finanze.sanita.fse2.ms.gtw.rulesmanager.enums; + +public enum EdsStrategyEnum { + NO_EDS, + NO_FHIR_EDS, + NO_EDS_WITH_LOG +} diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/scheduler/executors/BridgeEDS.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/scheduler/executors/BridgeEDS.java index ee7b8d6..068816b 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/scheduler/executors/BridgeEDS.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/scheduler/executors/BridgeEDS.java @@ -14,6 +14,7 @@ import it.finanze.sanita.fse2.ms.gtw.rulesmanager.client.IEDSClient; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.logging.LoggerHelper; import it.finanze.sanita.fse2.ms.gtw.rulesmanager.repository.IExecutorRepo; +import it.finanze.sanita.fse2.ms.gtw.rulesmanager.service.IConfigSRV; import lombok.Getter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -27,4 +28,6 @@ public final class BridgeEDS { private IEDSClient client; @Autowired private LoggerHelper logger; + @Autowired + private IConfigSRV config; } diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/scheduler/executors/base/ExecutorEDS.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/scheduler/executors/base/ExecutorEDS.java index 71c5e92..8da7f68 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/scheduler/executors/base/ExecutorEDS.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/scheduler/executors/base/ExecutorEDS.java @@ -137,14 +137,14 @@ protected ActionRes startup(String[] steps) { // === LISTENERS === protected OnStepListener onStepFailure(Date timestamp) { return (name, status) -> { - if (status == ActionRes.KO) { + if (bridge.getConfig().isNoFhirEds() && status == ActionRes.KO) { bridge.getLogger().error(LOG_TYPE_CONTROL, "Error while updating GTW configuration items", config.getTitle() + " - " + name, ResultLogEnum.KO, timestamp); } }; } protected OnPlanListener onPlanSuccess(Date timestamp) { return (status) -> { - if (status == ActionRes.OK) { + if (bridge.getConfig().isNoFhirEds() && status == ActionRes.OK) { bridge.getLogger().info(LOG_TYPE_CONTROL, "Successfully updated configuration items", "Update" + " - " + config.getTitle(), ResultLogEnum.OK, timestamp); } }; diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/IConfigSRV.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/IConfigSRV.java new file mode 100644 index 0000000..cf4062e --- /dev/null +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/IConfigSRV.java @@ -0,0 +1,10 @@ +package it.finanze.sanita.fse2.ms.gtw.rulesmanager.service; + +public interface IConfigSRV { + + String getEdsStrategy(); + + boolean isNoEds(); + + boolean isNoFhirEds(); +} diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/impl/ConfigSRV.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/impl/ConfigSRV.java new file mode 100644 index 0000000..08c5264 --- /dev/null +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/service/impl/ConfigSRV.java @@ -0,0 +1,66 @@ +package it.finanze.sanita.fse2.ms.gtw.rulesmanager.service.impl; + + +import it.finanze.sanita.fse2.ms.gtw.rulesmanager.client.IConfigClient; +import it.finanze.sanita.fse2.ms.gtw.rulesmanager.enums.EdsStrategyEnum; +import it.finanze.sanita.fse2.ms.gtw.rulesmanager.service.IConfigSRV; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationStartedEvent; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.util.Date; + +@Service +public class ConfigSRV implements IConfigSRV { + + private static final Long DELTA_MS = 300000L; + + @Autowired + private IConfigClient client; + + private String edsStrategy; + + private long lastUpdate; + + @Async + @EventListener(ApplicationStartedEvent.class) + void initialize() { + refreshEdsStrategy(); + } + + private void refreshEdsStrategy() { + synchronized (this) { + edsStrategy = client.getEDSStrategy(); + lastUpdate = new Date().getTime(); + } + } + + @Override + public String getEdsStrategy() { + long passedTime = new Date().getTime() - lastUpdate; + if (passedTime >= DELTA_MS) { + synchronized (this) { + refreshEdsStrategy(); + } + } + return edsStrategy; + } + + @Override + public boolean isNoFhirEds() { + // Trigger refresh if necessary + String out = getEdsStrategy(); + // Evaluate + return StringUtils.isNotBlank(out) && EdsStrategyEnum.NO_FHIR_EDS.name().equalsIgnoreCase(out); + } + + //Se la strategy รจ null si setta come default no_eds (quindi non verranno emesse loggate) + @Override + public boolean isNoEds() { + String out = getEdsStrategy(); + return StringUtils.isBlank(out) || EdsStrategyEnum.NO_EDS.name().equalsIgnoreCase(out); + } +}