diff --git a/fiul-core/src/main/java/io/finarkein/fiul/consent/ConsentState.java b/fiul-core/src/main/java/io/finarkein/fiul/consent/ConsentState.java index 12eb836c..039a1cf5 100644 --- a/fiul-core/src/main/java/io/finarkein/fiul/consent/ConsentState.java +++ b/fiul-core/src/main/java/io/finarkein/fiul/consent/ConsentState.java @@ -8,7 +8,6 @@ import java.util.Arrays; import java.util.Map; -import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -29,17 +28,6 @@ public enum ConsentState { .collect(Collectors.toMap(Enum::name, Function.identity())); } - public static final Set CONSENT_NEGATIVE_STATUS = Set.of(PAUSED, EXPIRED, REVOKED); - public static final Set CONSENT_CLEANUP_STATUS = Set.of(REJECTED, EXPIRED, REVOKED); - - public boolean isNegativeStatus() { - return CONSENT_NEGATIVE_STATUS.contains(this); - } - - public boolean isCleanupStatus() { - return CONSENT_CLEANUP_STATUS.contains(this); - } - public static ConsentState get(String stateValue) { final var consentState = lookup.get(stateValue); if (consentState != null) diff --git a/fiul-rest/fiul-rest-app/src/main/resources/application.properties b/fiul-rest/fiul-rest-app/src/main/resources/application.properties index 109933a3..fca22251 100644 --- a/fiul-rest/fiul-rest-app/src/main/resources/application.properties +++ b/fiul-rest/fiul-rest-app/src/main/resources/application.properties @@ -8,6 +8,8 @@ spring.cloud.config.enabled=false fiul.entity_id=fiu@id fiul.dataflow.data-life-tracker-fixed-delay=600000 fiul.dataflow.fi-data-crypto-service=${FI_DATA_CRYPTO_SERVICE:no-op} +# set of consent states for which data clean up required +fiul.dataflow.data-cleanup-consent-states=REVOKED ## Start: notification config ################################################# fiul.notification.jws-filter-qualifier=fiul fiul.notification-queue-type=in-mem diff --git a/fiul-service-dataflow/fiul-dataflow-core/src/main/java/io/finarkein/fiul/dataflow/impl/DataFlowNotificationHandlerImpl.java b/fiul-service-dataflow/fiul-dataflow-core/src/main/java/io/finarkein/fiul/dataflow/impl/DataFlowNotificationHandlerImpl.java index 898253be..8bc219e3 100644 --- a/fiul-service-dataflow/fiul-dataflow-core/src/main/java/io/finarkein/fiul/dataflow/impl/DataFlowNotificationHandlerImpl.java +++ b/fiul-service-dataflow/fiul-dataflow-core/src/main/java/io/finarkein/fiul/dataflow/impl/DataFlowNotificationHandlerImpl.java @@ -15,20 +15,26 @@ import io.finarkein.fiul.dataflow.store.FIRequestStore; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.util.Set; + @Service @Log4j2 public class DataFlowNotificationHandlerImpl implements DataFlowNotificationHandler { @Autowired - DataFlowService dataFlowService; + private DataFlowService dataFlowService; @Autowired - EasyDataFlowService easyDataFlowService; + private EasyDataFlowService easyDataFlowService; @Autowired - FIRequestStore fiRequestStore; + private FIRequestStore fiRequestStore; + + @Value("${fiul.dataflow.data-cleanup-consent-states}") + private Set dataCleanupConsentStates; @Override public void handleFINotification(FINotification fiNotification) { @@ -41,13 +47,16 @@ public void handleConsentNotification(ConsentNotification consentNotification) { final var consentStatus = statusNotification.getConsentStatus(); final var consentState = ConsentState.get(consentStatus.toUpperCase()); - if (!consentState.isCleanupStatus()) - return; - log.debug("Handling consentNotification:{}", consentNotification); - if (consentState == ConsentState.REVOKED || consentState == ConsentState.EXPIRED) { + if (isCleanupRequired(consentState)) { easyDataFlowService.deleteData(statusNotification.getConsentId()); dataFlowService.deleteDataByConsentId(statusNotification.getConsentId()); + log.debug("Data cleanup done for consentNotification:{}", consentNotification); } } + + private boolean isCleanupRequired(ConsentState forConsentState){ + return dataCleanupConsentStates.contains(forConsentState.name()) + || dataCleanupConsentStates.contains(forConsentState.name().toLowerCase()); + } }