From 651d44753e3999b08b3d8b02f860c705f6654d86 Mon Sep 17 00:00:00 2001 From: Vincenzo Ingenito Date: Wed, 13 Sep 2023 15:21:29 +0200 Subject: [PATCH] feat: Aggiunta strategia eds e condizionate loggate strutturate --- .../dispatcher/client/impl/ConfigClient.java | 4 +- .../controller/impl/PublicationCTL.java | 19 +- .../controller/impl/ValidationCTL.java | 29 +- .../gtw/dispatcher/enums/EdsStrategyEnum.java | 3 +- .../gtw/dispatcher/logging/LoggerHelper.java | 323 +++++++++--------- .../ms/gtw/dispatcher/service/IConfigSRV.java | 2 + .../dispatcher/service/impl/ConfigSRV.java | 89 ++--- 7 files changed, 245 insertions(+), 224 deletions(-) diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/ConfigClient.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/ConfigClient.java index 6f154a91..e06d767f 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/ConfigClient.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/ConfigClient.java @@ -16,6 +16,7 @@ import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.response.WhoIsResponseDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.MicroservicesURLCFG; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EdsStrategyEnum; import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.ProfileUtility; import lombok.extern.slf4j.Slf4j; @@ -83,8 +84,7 @@ public String getGatewayName() { @Override public String getEDSStrategy() { - String output = ""; //TODO - Set with default strategy - + String output = EdsStrategyEnum.NO_EDS.name(); if(isReachable()) { String endpoint = msUrlCFG.getConfigHost() + "/v1/config-items/props?type=GENERIC&props=eds-strategy"; output = restTemplate.getForObject(endpoint,String.class); diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java index e6286e11..b7d3538d 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java @@ -416,7 +416,6 @@ private ValidationCreationInputDTO publicationAndReplaceValidation(final Multipa validation.setKafkaKey(key); } catch (final ValidationException | NoRecordFoundException ve) { cdaSRV.consumeHash(validationInfo.getHash()); -// validation.setValidationError(ve); throw ve; } @@ -502,11 +501,7 @@ public ResponseWifDTO delete(String idDoc, HttpServletRequest request) { kafkaSRV.sendDeleteStatus(info.getTraceID(), workflowInstanceId, idDoc, "Riferimenti trovati: " +iniReference.getUuid(), SUCCESS, jwtPayloadToken, RIFERIMENTI_INI); } - EdsResponseDTO edsResponse = new EdsResponseDTO( - true, - "EDS Mock", - "EDS Mock" - ); + EdsResponseDTO edsResponse = new EdsResponseDTO(true,"EDS Mock","EDS Mock"); if(edsStrategy.isNoFhirEds()) { // ============================== @@ -554,8 +549,7 @@ public ResponseWifDTO delete(String idDoc, HttpServletRequest request) { kafkaSRV.sendDeleteStatus(info.getTraceID(), workflowInstanceId, idDoc, "Delete effettuata su ini", SUCCESS, jwtPayloadToken, INI_DELETE); } - logger.info(Constants.App.LOG_TYPE_CONTROL,workflowInstanceId,String.format("Deletion of CDA completed for document with identifier %s", idDoc), OperationLogEnum.DELETE_CDA2, ResultLogEnum.OK, startOperation, MISSING_DOC_TYPE_PLACEHOLDER, - jwtPayloadToken,null); + logger.info(Constants.App.LOG_TYPE_CONTROL,workflowInstanceId,String.format("Deletion of CDA completed for document with identifier %s", idDoc), OperationLogEnum.DELETE_CDA2, ResultLogEnum.OK, startOperation, MISSING_DOC_TYPE_PLACEHOLDER, jwtPayloadToken,null); } catch(MockEnabledException me) { throw me; } catch(IniException inEx) { @@ -574,14 +568,7 @@ public ResponseWifDTO delete(String idDoc, HttpServletRequest request) { throw e; } - log.info("[EXIT] {}() with arguments {}={}, {}={}, {}={}", - "delete", - "traceId", info.getTraceID(), - "wif", workflowInstanceId, - "idDoc", idDoc - ); - - + log.info("[EXIT] {}() with arguments {}={}, {}={}, {}={}", "delete", "traceId", info.getTraceID(), "wif", workflowInstanceId, "idDoc", idDoc); return new ResponseWifDTO(workflowInstanceId, info, warning); } diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/ValidationCTL.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/ValidationCTL.java index 1caafe30..5cacfd18 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/ValidationCTL.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/ValidationCTL.java @@ -11,32 +11,37 @@ */ package it.finanze.sanita.fse2.ms.gtw.dispatcher.controller.impl; +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants; import it.finanze.sanita.fse2.ms.gtw.dispatcher.controller.IValidationCTL; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.JWTPayloadDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.ValidationCDAReqDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.LogTraceInfoDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.ValidationResDTO; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.*; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ActivityEnum; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventStatusEnum; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventTypeEnum; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.OperationLogEnum; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ResultLogEnum; import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.ValidationException; import it.finanze.sanita.fse2.ms.gtw.dispatcher.logging.LoggerHelper; import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IErrorHandlerSRV; import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IKafkaSRV; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.CdaUtility; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.PDFUtility; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.SignerUtility; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; import lombok.extern.slf4j.Slf4j; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; - -import javax.servlet.http.HttpServletRequest; -import java.util.Date; /** * Validation controller. diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/enums/EdsStrategyEnum.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/enums/EdsStrategyEnum.java index fd85344f..ab3306c5 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/enums/EdsStrategyEnum.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/enums/EdsStrategyEnum.java @@ -2,5 +2,6 @@ public enum EdsStrategyEnum { NO_EDS, - NO_FHIR_EDS + NO_FHIR_EDS, + NO_EDS_WITH_LOG } diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/logging/LoggerHelper.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/logging/LoggerHelper.java index e62634a5..5297589d 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/logging/LoggerHelper.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/logging/LoggerHelper.java @@ -26,195 +26,212 @@ import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.LogDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ILogEnum; import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ResultLogEnum; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IConfigSRV; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.CfUtility; import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; import lombok.extern.slf4j.Slf4j; - + @Service @Slf4j public class LoggerHelper { - + Logger kafkaLog = LoggerFactory.getLogger("kafka-logger"); - - @Autowired + + @Autowired private IConfigClient configClient; - + private String gatewayName; - + @Value("${log.kafka-log.enable}") private boolean kafkaLogEnable; @Value("${spring.application.name}") private String msName; - + + @Autowired + private IConfigSRV configSRV; + /* * Specify here the format for the dates */ private DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS"); - + + /* * Implements structured logs, at all logging levels */ public void trace(String logType,String workflowInstanceId, String message, ILogEnum operation, ResultLogEnum result, Date startDateOperation, JWTPayloadDTO jwtPayloadDTO) { - if(jwtPayloadDTO==null) { - jwtPayloadDTO = new JWTPayloadDTO(); - } - LogDTO logDTO = LogDTO.builder(). - op_issuer(jwtPayloadDTO.getIss()). - op_locality(jwtPayloadDTO.getLocality()). - message(message). - operation(operation.getCode()). - op_result(result.getCode()). - op_timestamp_start(dateFormat.format(startDateOperation)). - op_timestamp_end(dateFormat.format(new Date())). - op_role(jwtPayloadDTO.getSubject_role()). - op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub())). - gateway_name(getGatewayName()). - microservice_name(msName). - op_application_id(jwtPayloadDTO.getSubject_application_id()). - op_application_vendor(jwtPayloadDTO.getSubject_application_vendor()). - op_application_version(jwtPayloadDTO.getSubject_application_version()). - log_type(logType). - workflow_instance_id(workflowInstanceId). - build(); - - final String logMessage = StringUtility.toJSON(logDTO); - log.trace(logMessage); - - if (Boolean.TRUE.equals(kafkaLogEnable)) { - kafkaLog.trace(logMessage); + if(!configSRV.isNoEds()){ + if(jwtPayloadDTO==null) { + jwtPayloadDTO = new JWTPayloadDTO(); + } + LogDTO logDTO = LogDTO.builder(). + op_issuer(jwtPayloadDTO.getIss()). + op_locality(jwtPayloadDTO.getLocality()). + message(message). + operation(operation.getCode()). + op_result(result.getCode()). + op_timestamp_start(dateFormat.format(startDateOperation)). + op_timestamp_end(dateFormat.format(new Date())). + op_role(jwtPayloadDTO.getSubject_role()). + op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub())). + gateway_name(getGatewayName()). + microservice_name(msName). + op_application_id(jwtPayloadDTO.getSubject_application_id()). + op_application_vendor(jwtPayloadDTO.getSubject_application_vendor()). + op_application_version(jwtPayloadDTO.getSubject_application_version()). + log_type(logType). + workflow_instance_id(workflowInstanceId). + build(); + + final String logMessage = StringUtility.toJSON(logDTO); + log.trace(logMessage); + + if (Boolean.TRUE.equals(kafkaLogEnable)) { + kafkaLog.trace(logMessage); + } } } public void debug(String logType,String workflowInstanceId, String message, ILogEnum operation, ResultLogEnum result, Date startDateOperation,JWTPayloadDTO jwtPayloadDTO) { - if(jwtPayloadDTO==null) { - jwtPayloadDTO = new JWTPayloadDTO(); - } - LogDTO logDTO = LogDTO.builder(). - op_issuer(jwtPayloadDTO.getIss()). - op_locality(jwtPayloadDTO.getLocality()). - message(message). - operation(operation.getCode()). - op_result(result.getCode()). - op_timestamp_start(dateFormat.format(startDateOperation)). - op_timestamp_end(dateFormat.format(new Date())). - op_role(jwtPayloadDTO.getSubject_role()). - op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub())). - gateway_name(getGatewayName()). - microservice_name(msName). - op_application_id(jwtPayloadDTO.getSubject_application_id()). - op_application_vendor(jwtPayloadDTO.getSubject_application_vendor()). - op_application_version(jwtPayloadDTO.getSubject_application_version()). - log_type(logType). - workflow_instance_id(workflowInstanceId). - build(); - - final String logMessage = StringUtility.toJSON(logDTO); - log.debug(logMessage); - if (Boolean.TRUE.equals(kafkaLogEnable)) { - kafkaLog.debug(logMessage); + if(!configSRV.isNoEds()){ + if(jwtPayloadDTO==null) { + jwtPayloadDTO = new JWTPayloadDTO(); + } + LogDTO logDTO = LogDTO.builder(). + op_issuer(jwtPayloadDTO.getIss()). + op_locality(jwtPayloadDTO.getLocality()). + message(message). + operation(operation.getCode()). + op_result(result.getCode()). + op_timestamp_start(dateFormat.format(startDateOperation)). + op_timestamp_end(dateFormat.format(new Date())). + op_role(jwtPayloadDTO.getSubject_role()). + op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub())). + gateway_name(getGatewayName()). + microservice_name(msName). + op_application_id(jwtPayloadDTO.getSubject_application_id()). + op_application_vendor(jwtPayloadDTO.getSubject_application_vendor()). + op_application_version(jwtPayloadDTO.getSubject_application_version()). + log_type(logType). + workflow_instance_id(workflowInstanceId). + build(); + + final String logMessage = StringUtility.toJSON(logDTO); + log.debug(logMessage); + if (Boolean.TRUE.equals(kafkaLogEnable)) { + kafkaLog.debug(logMessage); + } } } - + public void info(String logType,String workflowInstanceId, String message, ILogEnum operation, ResultLogEnum result, Date startDateOperation, String documentType, JWTPayloadDTO jwtPayloadDTO, String typeIdExtension) { - if(jwtPayloadDTO==null) { - jwtPayloadDTO = new JWTPayloadDTO(); - } - LogDTO logDTO = LogDTO.builder(). - op_issuer(jwtPayloadDTO.getIss()). - op_locality(jwtPayloadDTO.getLocality()). - message(message). - operation(operation.getCode()). - op_result(result.getCode()). - op_timestamp_start(dateFormat.format(startDateOperation)). - op_timestamp_end(dateFormat.format(new Date())). - op_document_type(documentType). - op_role(jwtPayloadDTO.getSubject_role()). - op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub())). - gateway_name(getGatewayName()). - microservice_name(msName). - op_application_id(jwtPayloadDTO.getSubject_application_id()). - op_application_vendor(jwtPayloadDTO.getSubject_application_vendor()). - op_application_version(jwtPayloadDTO.getSubject_application_version()). - log_type(logType). - workflow_instance_id(workflowInstanceId). - typeIdExtension(typeIdExtension). - build(); - - final String logMessage = StringUtility.toJSON(logDTO); - log.info(logMessage); - - if (Boolean.TRUE.equals(kafkaLogEnable)) { - kafkaLog.info(logMessage); + if(!configSRV.isNoEds()){ + if(jwtPayloadDTO==null) { + jwtPayloadDTO = new JWTPayloadDTO(); + } + LogDTO logDTO = LogDTO.builder(). + op_issuer(jwtPayloadDTO.getIss()). + op_locality(jwtPayloadDTO.getLocality()). + message(message). + operation(operation.getCode()). + op_result(result.getCode()). + op_timestamp_start(dateFormat.format(startDateOperation)). + op_timestamp_end(dateFormat.format(new Date())). + op_document_type(documentType). + op_role(jwtPayloadDTO.getSubject_role()). + op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadDTO.getSub())). + gateway_name(getGatewayName()). + microservice_name(msName). + op_application_id(jwtPayloadDTO.getSubject_application_id()). + op_application_vendor(jwtPayloadDTO.getSubject_application_vendor()). + op_application_version(jwtPayloadDTO.getSubject_application_version()). + log_type(logType). + workflow_instance_id(workflowInstanceId). + typeIdExtension(typeIdExtension). + build(); + + final String logMessage = StringUtility.toJSON(logDTO); + log.info(logMessage); + + if (Boolean.TRUE.equals(kafkaLogEnable)) { + kafkaLog.info(logMessage); + } } + } - + public void warn(String logType,String workflowInstanceId, String message, ILogEnum operation, ResultLogEnum result, Date startDateOperation,JWTPayloadDTO jwtPayloadToken) { - if(jwtPayloadToken==null) { - jwtPayloadToken = new JWTPayloadDTO(); - } - LogDTO logDTO = LogDTO.builder(). - op_issuer(jwtPayloadToken.getIss()). - op_locality(jwtPayloadToken.getLocality()). - message(message). - operation(operation.getCode()). - op_result(result.getCode()). - op_timestamp_start(dateFormat.format(startDateOperation)). - op_timestamp_end(dateFormat.format(new Date())). - op_role(jwtPayloadToken.getSubject_role()). - op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadToken.getSub())). - gateway_name(getGatewayName()). - microservice_name(msName). - op_application_id(jwtPayloadToken.getSubject_application_id()). - op_application_vendor(jwtPayloadToken.getSubject_application_vendor()). - op_application_version(jwtPayloadToken.getSubject_application_version()). - log_type(logType). - workflow_instance_id(workflowInstanceId). - build(); - - final String logMessage = StringUtility.toJSON(logDTO); - log.warn(logMessage); - if (Boolean.TRUE.equals(kafkaLogEnable)) { - kafkaLog.warn(logMessage); + if(!configSRV.isNoEds()){ + if(jwtPayloadToken==null) { + jwtPayloadToken = new JWTPayloadDTO(); + } + LogDTO logDTO = LogDTO.builder(). + op_issuer(jwtPayloadToken.getIss()). + op_locality(jwtPayloadToken.getLocality()). + message(message). + operation(operation.getCode()). + op_result(result.getCode()). + op_timestamp_start(dateFormat.format(startDateOperation)). + op_timestamp_end(dateFormat.format(new Date())). + op_role(jwtPayloadToken.getSubject_role()). + op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadToken.getSub())). + gateway_name(getGatewayName()). + microservice_name(msName). + op_application_id(jwtPayloadToken.getSubject_application_id()). + op_application_vendor(jwtPayloadToken.getSubject_application_vendor()). + op_application_version(jwtPayloadToken.getSubject_application_version()). + log_type(logType). + workflow_instance_id(workflowInstanceId). + build(); + + final String logMessage = StringUtility.toJSON(logDTO); + log.warn(logMessage); + if (Boolean.TRUE.equals(kafkaLogEnable)) { + kafkaLog.warn(logMessage); + } + } - + } - + public void error(String logType,String workflowInstanceId, String message, ILogEnum operation, ResultLogEnum result, Date startDateOperation, - ILogEnum error, String documentType, JWTPayloadDTO jwtPayloadToken) { - - if(jwtPayloadToken==null) { - jwtPayloadToken = new JWTPayloadDTO(); - } - LogDTO logDTO = LogDTO.builder(). - op_issuer(jwtPayloadToken.getIss()). - op_locality(jwtPayloadToken.getLocality()). - message(message). - operation(operation.getCode()). - op_result(result.getCode()). - op_timestamp_start(dateFormat.format(startDateOperation)). - op_timestamp_end(dateFormat.format(new Date())). - op_error(error.getCode()). - op_error_description(error.getDescription()). - op_document_type(documentType). - op_role(jwtPayloadToken.getSubject_role()). - op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadToken.getSub())). - gateway_name(getGatewayName()). - microservice_name(msName). - op_application_id(jwtPayloadToken.getSubject_application_id()). - op_application_vendor(jwtPayloadToken.getSubject_application_vendor()). - op_application_version(jwtPayloadToken.getSubject_application_version()). - log_type(logType). - workflow_instance_id(workflowInstanceId). - build(); - - final String logMessage = StringUtility.toJSON(logDTO); - log.error(logMessage); - if (Boolean.TRUE.equals(kafkaLogEnable)) { - kafkaLog.error(logMessage); + ILogEnum error, String documentType, JWTPayloadDTO jwtPayloadToken) { + if(!configSRV.isNoEds()){ + if(jwtPayloadToken==null) { + jwtPayloadToken = new JWTPayloadDTO(); + } + LogDTO logDTO = LogDTO.builder(). + op_issuer(jwtPayloadToken.getIss()). + op_locality(jwtPayloadToken.getLocality()). + message(message). + operation(operation.getCode()). + op_result(result.getCode()). + op_timestamp_start(dateFormat.format(startDateOperation)). + op_timestamp_end(dateFormat.format(new Date())). + op_error(error.getCode()). + op_error_description(error.getDescription()). + op_document_type(documentType). + op_role(jwtPayloadToken.getSubject_role()). + op_fiscal_code(CfUtility.extractFiscalCodeFromJwtSub(jwtPayloadToken.getSub())). + gateway_name(getGatewayName()). + microservice_name(msName). + op_application_id(jwtPayloadToken.getSubject_application_id()). + op_application_vendor(jwtPayloadToken.getSubject_application_vendor()). + op_application_version(jwtPayloadToken.getSubject_application_version()). + log_type(logType). + workflow_instance_id(workflowInstanceId). + build(); + + final String logMessage = StringUtility.toJSON(logDTO); + log.error(logMessage); + if (Boolean.TRUE.equals(kafkaLogEnable)) { + kafkaLog.error(logMessage); + } } - + + } /** @@ -228,5 +245,5 @@ private String getGatewayName() { } return gatewayName; } - + } diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/IConfigSRV.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/IConfigSRV.java index 3d3d009b..54c56754 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/IConfigSRV.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/IConfigSRV.java @@ -4,5 +4,7 @@ public interface IConfigSRV { String getEdsStrategy(); + boolean isNoEds(); + boolean isNoFhirEds(); } diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/ConfigSRV.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/ConfigSRV.java index c2ffa7dd..19fb16e0 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/ConfigSRV.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/ConfigSRV.java @@ -3,6 +3,8 @@ import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IConfigClient; import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EdsStrategyEnum; import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IConfigSRV; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; + import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.event.ApplicationStartedEvent; @@ -15,44 +17,51 @@ @Service public class ConfigSRV implements IConfigSRV { - private static final Long DELTA_MS = 300000L; - - @Autowired - private IConfigClient configClient; - - private String edsStrategy; - - private long lastUpdate; - - @Async - @EventListener(ApplicationStartedEvent.class) - void initialize() { - refreshEdsStrategy(); - } - - private void refreshEdsStrategy() { - synchronized (this) { - edsStrategy = configClient.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); - } + private static final Long DELTA_MS = 300000L; + + @Autowired + private IConfigClient configClient; + + private String edsStrategy; + + private long lastUpdate; + + @Async + @EventListener(ApplicationStartedEvent.class) + void initialize() { + refreshEdsStrategy(); + } + + private void refreshEdsStrategy() { + synchronized (this) { + edsStrategy = configClient.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 StringUtility.isNullOrEmpty(out) || EdsStrategyEnum.NO_EDS.name().equalsIgnoreCase(out); + } }