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 30, 2023
1 parent 7ba6d45 commit 35d0627
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public interface IConfigClient {

Integer getExpirationDate();
Boolean isCfOnIssuerAllowed();
Boolean isSubjectPersistenceEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;

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;
import static it.finanze.sanita.fse2.ms.gtw.statusmanager.client.routes.base.ClientRoutes.Config.*;

@Slf4j
@Component
Expand Down Expand Up @@ -49,10 +48,23 @@ public Integer getExpirationDate() {
}

@Override
public Boolean isCfOnIssuerAllowed() {
public Boolean isSubjectPersistenceEnabled() {
boolean output = false;
String endpoint = routes.getStatusManagerConfig(PROPS_NAME_SUBJECT);
log.debug("{} - Executing request: {}", routes.identifier(), endpoint);

if (isReachable()){
ResponseEntity<String> response = client.getForEntity(endpoint, String.class);
if (response.getBody() != null) output = Boolean.parseBoolean(response.getBody());
}

String endpoint = routes.getGenericProps(PROPS_NAME_ISSUER_CF);
return output;
}

@Override
public Boolean isCfOnIssuerAllowed() {
boolean output = false;
String endpoint = routes.getStatusManagerConfig(PROPS_NAME_ISSUER_CF);
log.debug("{} - Executing request: {}", routes.identifier(), endpoint);

if(isReachable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public static final class Config {
public static final String QP_TYPE_STATUS_MANAGER = "STATUS_MANAGER";
// VALUES
public static final String PROPS_NAME_EXP_DAYS = "expiring_date_day";
public static final String PROPS_NAME_ISSUER_CF = "issuer_cf_cleaning";
public static final String PROPS_NAME_ISSUER_CF = "issuer-cf-cleaning";
public static final String PROPS_NAME_SUBJECT = "subject-persistence";

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static final class Fields {
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 EVENT_SUBJECT = "subject";
public static final String EXPIRING_DATE = "expiring_date";

private Fields() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void saveEvent(String workflowInstanceId, String json) {
Date expiringDate = DateUtility.addDay(new Date(), configSRV.getExpirationDate());
doc.put(EXPIRING_DATE, expiringDate);
clearIssuerObject(doc);
clearSubjectObject(doc);
mongo.upsert(query, Update.fromDocument(doc, "_id"), FhirEvent.class);
} catch(Exception ex){
log.error("Error while save event : " , ex);
Expand Down Expand Up @@ -98,6 +99,12 @@ public int saveEventsFhir(List<String> wif, Date timestamp, Date expiration) thr
}


private void clearSubjectObject(Document doc) {
if (doc.containsKey(EVENT_SUBJECT) && !configSRV.isSubjectPersistenceEnabled()) {
doc.remove(EVENT_SUBJECT);
}
}

private void clearIssuerObject(Document doc) {
if(doc.containsKey(EVENT_ISSUER) && configSRV.isCfOnIssuerNotAllowed()) {
doc.replace(EVENT_ISSUER, clearIssuer(doc.getString(EVENT_ISSUER)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
public interface IConfigSRV {
Integer getExpirationDate();
Boolean isCfOnIssuerNotAllowed();

Boolean isSubjectPersistenceEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import java.util.HashMap;
import java.util.Map;

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;
import static it.finanze.sanita.fse2.ms.gtw.statusmanager.client.routes.base.ClientRoutes.Config.*;

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

Expand All @@ -54,6 +54,11 @@ private void refreshExpirationDate() {
props.put(PROPS_NAME_EXP_DAYS, Pair.of(new Date().getTime(), days));
}

private void refreshIsSubjectPersistenceEnabled(){
boolean out = client.isSubjectPersistenceEnabled();
props.put(PROPS_NAME_SUBJECT, Pair.of(new Date().getTime(), out));
}

private void refreshIsCfOnIssuerAllowed() {
boolean out = client.isCfOnIssuerAllowed();
props.put(PROPS_NAME_ISSUER_CF, Pair.of(new Date().getTime(), out));
Expand All @@ -74,6 +79,21 @@ public Integer getExpirationDate() {
return (Integer) props.get(PROPS_NAME_EXP_DAYS).getValue();
}

@Override
public Boolean isSubjectPersistenceEnabled() {
Pair<Long, Object> pair = props.getOrDefault(
PROPS_NAME_SUBJECT,
Pair.of(0L, null)
);
if (new Date().getTime() - pair.getKey() >= DELTA_MS) {
synchronized (PROPS_NAME_SUBJECT) {
refreshIsSubjectPersistenceEnabled();
verifyIsSubjectPersistenceEnabled(pair);
}
}
return (Boolean) props.get(PROPS_NAME_SUBJECT).getValue();
}

@Override
public Boolean isCfOnIssuerNotAllowed() {
Pair<Long, Object> pair = props.getOrDefault(
Expand Down Expand Up @@ -101,6 +121,14 @@ private void verifyExpirationDate(Pair<Long, Object> pair) {
}
}

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

private void verifyIsCfOnIssuerAllowed(Pair<Long, Object> pair) {
Boolean previous = (Boolean) pair.getValue();
boolean current = (boolean) props.get(PROPS_NAME_ISSUER_CF).getValue();
Expand Down

0 comments on commit 35d0627

Please sign in to comment.