From 534210c9b02aa38905cac90de37a9f9acbe9e435 Mon Sep 17 00:00:00 2001 From: Vincenzo Ingenito Date: Wed, 2 Oct 2024 17:49:59 +0200 Subject: [PATCH] feat: Search by wii --- .../ms/gtw/dispatcher/client/IIniClient.java | 3 +- .../gtw/dispatcher/client/impl/IniClient.java | 8 +++--- .../client/routes/base/ClientRoutes.java | 1 + .../controller/impl/AbstractCTL.java | 1 - .../ms/gtw/dispatcher/dto/IniAuditsDto.java | 15 ++++++++++ .../ms/gtw/dispatcher/dto/StatusCheckDTO.java | 4 +-- .../ms/gtw/dispatcher/service/IConfigSRV.java | 2 ++ .../dispatcher/service/impl/ConfigSRV.java | 16 +++++++++++ .../service/impl/TransactionInspectSRV.java | 28 ++++++------------- 9 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/dto/IniAuditsDto.java diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/IIniClient.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/IIniClient.java index 59dc7415..6c73c16e 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/IIniClient.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/IIniClient.java @@ -12,6 +12,7 @@ package it.finanze.sanita.fse2.ms.gtw.dispatcher.client; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.IniAuditDto; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.IniAuditsDto; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.DeleteRequestDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.IniMetadataUpdateReqDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.IniReferenceRequestDTO; @@ -30,6 +31,6 @@ public interface IIniClient { GetMergedMetadatiDTO metadata(MergedMetadatiRequestDTO iniReq); - IniAuditDto callSearchEventByWorkflowInstanceId(String workflowInstanceId); + IniAuditsDto callSearchEventByWorkflowInstanceId(String workflowInstanceId); } diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/IniClient.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/IniClient.java index 4e2e7371..40faf96f 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/IniClient.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/impl/IniClient.java @@ -34,7 +34,7 @@ import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.impl.base.AbstractClient; import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.routes.IniClientRoutes; import it.finanze.sanita.fse2.ms.gtw.dispatcher.config.MicroservicesURLCFG; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.IniAuditDto; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.IniAuditsDto; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.DeleteRequestDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.IniMetadataUpdateReqDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.request.IniReferenceRequestDTO; @@ -144,12 +144,12 @@ public GetMergedMetadatiDTO metadata(final MergedMetadatiRequestDTO request) { } @Override - public IniAuditDto callSearchEventByWorkflowInstanceId(final String workflowInstanceId) { + public IniAuditsDto callSearchEventByWorkflowInstanceId(final String workflowInstanceId) { String url = msUrlCfg.getIniClientHost() + "/v1/" + workflowInstanceId; - IniAuditDto out = null; + IniAuditsDto out = null; try { - out = restTemplateIni.getForObject(url, IniAuditDto.class); + out = restTemplateIni.getForObject(url, IniAuditsDto.class); } catch (ResourceAccessException rax) { throw new BusinessException("Timeout error while call search event by worflow instance id"); } diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/routes/base/ClientRoutes.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/routes/base/ClientRoutes.java index aa8858b1..fc5921ae 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/routes/base/ClientRoutes.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/routes/base/ClientRoutes.java @@ -49,6 +49,7 @@ public static final class Config { public static final String PROPS_NAME_AUDIT_ENABLED = "audit-enabled"; public static final String PROPS_NAME_CONTROL_LOG_ENABLED = "control-log-persistence-enabled"; public static final String PROPS_NAME_ISSUER_CF = "issuer-cf-cleaning"; + public static final String PROPS_NAME_AUDIT_INI_ENABLED = "audit-ini-enabled"; public static final String PROPS_NAME_SUBJECT = "subject-cleaning"; public static final String PROPS_NAME_REMOVE_EDS_ENABLE = "remove-eds-enabled"; diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/AbstractCTL.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/AbstractCTL.java index 88421a8f..a4e4e789 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/AbstractCTL.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/AbstractCTL.java @@ -16,7 +16,6 @@ import java.util.Base64; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/dto/IniAuditsDto.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/dto/IniAuditsDto.java new file mode 100644 index 00000000..d79f2aee --- /dev/null +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/dto/IniAuditsDto.java @@ -0,0 +1,15 @@ +package it.finanze.sanita.fse2.ms.gtw.dispatcher.dto; + +import java.util.List; + +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@NoArgsConstructor +public class IniAuditsDto { + + private List audit; + +} diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/dto/StatusCheckDTO.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/dto/StatusCheckDTO.java index defe6767..3bfc711a 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/dto/StatusCheckDTO.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/dto/StatusCheckDTO.java @@ -11,11 +11,11 @@ */ package it.finanze.sanita.fse2.ms.gtw.dispatcher.dto; +import javax.validation.constraints.Size; + import lombok.Data; import lombok.NoArgsConstructor; -import javax.validation.constraints.Size; - @Data @NoArgsConstructor public class StatusCheckDTO { 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 a7b5558b..10af2f22 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 @@ -14,4 +14,6 @@ public interface IConfigSRV { long getRefreshRate(); + Boolean isAuditIniEnable(); + } 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 633f5ccb..2518af2f 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 @@ -18,6 +18,7 @@ import static it.finanze.sanita.fse2.ms.gtw.dispatcher.client.routes.base.ClientRoutes.Config.*; import static it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ConfigItemTypeEnum.DISPATCHER; +import static it.finanze.sanita.fse2.ms.gtw.dispatcher.client.routes.base.ClientRoutes.Config.PROPS_NAME_AUDIT_INI_ENABLED; import static it.finanze.sanita.fse2.ms.gtw.dispatcher.client.routes.base.ClientRoutes.Config.PROPS_NAME_REMOVE_EDS_ENABLE; @Slf4j @@ -26,6 +27,7 @@ public class ConfigSRV implements IConfigSRV { @Autowired private IConfigClient client; + @Autowired private ProfileUtility profiles; @@ -118,6 +120,19 @@ public Boolean isCfOnIssuerNotAllowed() { props.get(PROPS_NAME_ISSUER_CF).getValue() ); } + + @Override + public Boolean isAuditIniEnable() { + long lastUpdate = props.get(PROPS_NAME_AUDIT_INI_ENABLED).getKey(); + if (new Date().getTime() - lastUpdate >= getRefreshRate()) { + synchronized(Locks.AUDIT_INI_ENABLED) { + if (new Date().getTime() - lastUpdate >= getRefreshRate()) { + refresh(PROPS_NAME_AUDIT_INI_ENABLED); + } + } + } + return Boolean.parseBoolean(props.get(PROPS_NAME_AUDIT_INI_ENABLED).getValue()); + } private void refresh(String name) { String previous = props.getOrDefault(name, Pair.of(0L, null)).getValue(); @@ -166,6 +181,7 @@ private static final class Locks { public static final Object AUDIT_ENABLED = new Object(); public static final Object ISSUER_CF_CLEANING = new Object(); public static final Object SUBJECT_CLEANING = new Object(); + public static final Object AUDIT_INI_ENABLED = new Object(); } } diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/TransactionInspectSRV.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/TransactionInspectSRV.java index 1e0b89bc..8e5176d9 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/TransactionInspectSRV.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/TransactionInspectSRV.java @@ -11,21 +11,15 @@ */ package it.finanze.sanita.fse2.ms.gtw.dispatcher.service.impl; -import java.util.HashMap; -import java.util.Map; - -import org.bson.Document; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IConfigClient; import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IIniClient; import it.finanze.sanita.fse2.ms.gtw.dispatcher.client.IStatusCheckClient; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.IniAuditDto; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.StatusCheckDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.IniAuditsDto; import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.TransactionInspectResDTO; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IConfigSRV; import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.ITransactionInspectSRV; -import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility; @Service public class TransactionInspectSRV implements ITransactionInspectSRV { @@ -37,25 +31,19 @@ public class TransactionInspectSRV implements ITransactionInspectSRV { private IIniClient iniClient; @Autowired - private IConfigClient configClient; + private IConfigSRV configSRV; @Override public TransactionInspectResDTO callSearchEventByWorkflowInstanceId(final String workflowInstanceId) { TransactionInspectResDTO out = statusCheckClient.callSearchEventByWorkflowInstanceId(workflowInstanceId); - if(true) { - IniAuditDto auditIniDto = iniClient.callSearchEventByWorkflowInstanceId(workflowInstanceId); - StatusCheckDTO status = new StatusCheckDTO(); - status.setEventDate(""+auditIniDto.getEventDate()); - Map requestAndResponse = new HashMap<>(); - requestAndResponse.put("soapResponse", auditIniDto.getSoapResponse()); - requestAndResponse.put("soapRequest", auditIniDto.getSoapRequest()); - status.setMessage(StringUtility.toJSONJackson(requestAndResponse)); - status.setWorkflowInstanceId(workflowInstanceId); - out.getTransactionData().add(status); + if(configSRV.isAuditIniEnable()) { + IniAuditsDto auditsIniDto = iniClient.callSearchEventByWorkflowInstanceId(workflowInstanceId); + if(auditsIniDto!=null && !auditsIniDto.getAudit().isEmpty()) { + out.getTransactionData().addAll(auditsIniDto.getAudit()); + } } return out; - } @Override