Skip to content

Commit

Permalink
feat: introduce clear cf for issuer if required
Browse files Browse the repository at this point in the history
  • Loading branch information
gb-cic committed Nov 29, 2023
1 parent 4608b17 commit 06334c7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static final class Fields {
public static final String TRACE_ID = "traceId";
public static final String WORKFLOW_INSTANCE_ID = "workflow_instance_id";
public static final String EVENT_DATE = "eventDate";
public static final String EVENT_ISSUER = "issuer";
public static final String EXPIRING_DATE = "expiring_date";

private Fields() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package it.finanze.sanita.fse2.ms.gtw.statusmanager.repository.mongo.impl;

import com.mongodb.MongoException;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.config.Constants;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.exceptions.BusinessException;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.exceptions.OperationException;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.repository.entity.FhirEvent;
Expand All @@ -34,7 +33,8 @@
import java.util.TimeZone;
import java.util.stream.Collectors;

import static it.finanze.sanita.fse2.ms.gtw.statusmanager.config.Constants.Logs.ERR_REP_FHIR_EVENTS;
import static it.finanze.sanita.fse2.ms.gtw.statusmanager.config.Constants.Fields.*;
import static it.finanze.sanita.fse2.ms.gtw.statusmanager.config.Constants.Logs.ERR_REP_FHIR_EVENTS;

@Slf4j
@Repository
Expand All @@ -54,21 +54,24 @@ public void saveEvent(String workflowInstanceId, String json) {
Document doc = Document.parse(json);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(PATTERN);
simpleDateFormat.setTimeZone(TimeZone.getDefault());
Date eventDate = simpleDateFormat.parse(doc.getString(Constants.Fields.EVENT_DATE));
doc.put(Constants.Fields.EVENT_DATE, eventDate);
doc.put(Constants.Fields.WORKFLOW_INSTANCE_ID, workflowInstanceId);
String eventType = doc.getString(Constants.Fields.EVENT_TYPE);
String eventStatus = doc.getString(Constants.Fields.EVENT_STATUS);
Date eventDate = simpleDateFormat.parse(doc.getString(EVENT_DATE));
doc.put(EVENT_DATE, eventDate);
doc.put(WORKFLOW_INSTANCE_ID, workflowInstanceId);
String eventType = doc.getString(EVENT_TYPE);
String eventStatus = doc.getString(EVENT_STATUS);
Query query = new Query();
if(!"UNKNOWN_WORKFLOW_ID".equals(workflowInstanceId)) {
query.addCriteria(Criteria.where(Constants.Fields.WORKFLOW_INSTANCE_ID).is(workflowInstanceId).
and(Constants.Fields.EVENT_TYPE).is(eventType).and(Constants.Fields.EVENT_STATUS).is(eventStatus));
query.addCriteria(Criteria.where(WORKFLOW_INSTANCE_ID).is(workflowInstanceId).
and(EVENT_TYPE).is(eventType).and(EVENT_STATUS).is(eventStatus));
} else {
query.addCriteria(Criteria.where(Constants.Fields.TRACE_ID).is(doc.getString(Constants.Fields.TRACE_ID)).
and(Constants.Fields.EVENT_TYPE).is(eventType).and(Constants.Fields.EVENT_STATUS).is(eventStatus));
query.addCriteria(Criteria.where(TRACE_ID).is(doc.getString(TRACE_ID)).
and(EVENT_TYPE).is(eventType).and(EVENT_STATUS).is(eventStatus));
}
Date expiringDate = DateUtility.addDay(new Date(), configSRV.getExpirationDate());
doc.put(Constants.Fields.EXPIRING_DATE, expiringDate);
doc.put(EXPIRING_DATE, expiringDate);
if(doc.containsKey(EVENT_ISSUER) && !configSRV.isCfOnIssuerAllowed()) {
doc.replace(EVENT_ISSUER, clearIssuer(doc.getString(EVENT_ISSUER)));
}
mongo.upsert(query, Update.fromDocument(doc, "_id"), FhirEvent.class);
} catch(Exception ex){
log.error("Error while save event : " , ex);
Expand Down Expand Up @@ -96,4 +99,8 @@ public int saveEventsFhir(List<String> wif, Date timestamp, Date expiration) thr
return insertions;
}

private String clearIssuer(String issuer) {
return issuer.contains("#") ? issuer.split("#")[0] : issuer;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import it.finanze.sanita.fse2.ms.gtw.statusmanager.client.IConfigClient;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.service.IConfigSRV;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
Expand All @@ -26,6 +27,7 @@
import static it.finanze.sanita.fse2.ms.gtw.statusmanager.client.routes.base.ClientRoutes.Config.PROPS_NAME_EXP_DAYS;
import static it.finanze.sanita.fse2.ms.gtw.statusmanager.client.routes.base.ClientRoutes.Config.PROPS_NAME_ISSUER_CF;

@Slf4j
@Service
public class ConfigSRV implements IConfigSRV {

Expand All @@ -44,6 +46,7 @@ public ConfigSRV() {
void initialize() {
refreshExpirationDate();
refreshIsCfOnIssuerAllowed();
runningConfiguration();
}

private void refreshExpirationDate() {
Expand All @@ -65,6 +68,7 @@ public Integer getExpirationDate() {
if (new Date().getTime() - pair.getKey() >= DELTA_MS) {
synchronized(PROPS_NAME_EXP_DAYS) {
refreshExpirationDate();
verifyExpirationDate(pair);
}
}
return (Integer) props.get(PROPS_NAME_EXP_DAYS).getValue();
Expand All @@ -79,8 +83,29 @@ public Boolean isCfOnIssuerAllowed() {
if (new Date().getTime() - pair.getKey() >= DELTA_MS) {
synchronized(PROPS_NAME_ISSUER_CF) {
refreshIsCfOnIssuerAllowed();
verifyIsCfOnIssuerAllowed(pair);
}
}
return (Boolean) props.get(PROPS_NAME_ISSUER_CF).getValue();
}

private void runningConfiguration() {
props.forEach((id, pair) -> log.info("[GTW-CONFIG] key: {} | value: {}", id, pair.getValue()));
}

private void verifyExpirationDate(Pair<Long, Object> pair) {
int previous = (int) pair.getValue();
int current = (int) props.get(PROPS_NAME_EXP_DAYS).getValue();
if(previous != current) {
log.info("[GTW-CONFIG][UPDATE] key: {} | value: {} (previous: {})", PROPS_NAME_EXP_DAYS, current, previous);
}
}

private void verifyIsCfOnIssuerAllowed(Pair<Long, Object> pair) {
Boolean previous = (Boolean) pair.getValue();
boolean current = (boolean) props.get(PROPS_NAME_ISSUER_CF).getValue();
if(previous != current) {
log.info("[GTW-CONFIG][UPDATE] key: {} | value: {} (previous: {})", PROPS_NAME_ISSUER_CF, current, previous);
}
}
}

0 comments on commit 06334c7

Please sign in to comment.