Skip to content

Commit

Permalink
Merge pull request #69 from finarkein/feature/consent-noti-data-flow-…
Browse files Browse the repository at this point in the history
…handling

feat: configuration introduced to decide data cleanup on consent noti…
  • Loading branch information
dheerajkhardwal authored Apr 19, 2022
2 parents 858ed3b + 5f00af4 commit 6e47f6c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,17 +28,6 @@ public enum ConsentState {
.collect(Collectors.toMap(Enum::name, Function.identity()));
}

public static final Set<ConsentState> CONSENT_NEGATIVE_STATUS = Set.of(PAUSED, EXPIRED, REVOKED);
public static final Set<ConsentState> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> dataCleanupConsentStates;

@Override
public void handleFINotification(FINotification fiNotification) {
Expand All @@ -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());
}
}

0 comments on commit 6e47f6c

Please sign in to comment.