Skip to content

Commit

Permalink
feat: Search by wii
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzo-ingenito committed Oct 2, 2024
1 parent fbd7f15 commit 534210c
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,6 @@ public interface IIniClient {

GetMergedMetadatiDTO metadata(MergedMetadatiRequestDTO iniReq);

IniAuditDto callSearchEventByWorkflowInstanceId(String workflowInstanceId);
IniAuditsDto callSearchEventByWorkflowInstanceId(String workflowInstanceId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<StatusCheckDTO> audit;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface IConfigSRV {

long getRefreshRate();

Boolean isAuditIniEnable();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +27,7 @@ public class ConfigSRV implements IConfigSRV {

@Autowired
private IConfigClient client;

@Autowired
private ProfileUtility profiles;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<String,String> 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
Expand Down

0 comments on commit 534210c

Please sign in to comment.