Skip to content

Commit

Permalink
Merge pull request #26 from imesh94/fix/revoke-metrics-issue
Browse files Browse the repository at this point in the history
Fix consent revocation data not getting published
  • Loading branch information
aka4rKO authored Oct 28, 2024
2 parents 41255c1 + c55b48c commit ef576f1
Showing 1 changed file with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class CDSConsentEventExecutor implements OBEventExecutor {
private static final String USER_ID_KEY = "userId";
private static final String STATUS_KEY = "status";
private static final String EXPIRY_TIME_KEY = "expiryTime";
private static final ConcurrentLinkedDeque<String> publishedRequestUriKeyQueue = new ConcurrentLinkedDeque<>();
private static final ConcurrentLinkedDeque<String> publishedEventIdentifierQueue = new ConcurrentLinkedDeque<>();

@Override
public void processEvent(OBEvent obEvent) {
Expand Down Expand Up @@ -160,12 +160,13 @@ public void processEvent(OBEvent obEvent) {

log.debug("Publishing consent data for authorisation metrics.");
String consentId = (String) eventData.get(CONSENT_ID);
ConsentStatusEnum consentStatus = getConsentStatusForEventType(obEvent.getEventType());
AuthorisationFlowTypeEnum authFlowType = getAuthFlowTypeForEventType(obEvent.getEventType());
String requestUriKey = getRequestUriKeyFromConsentResource(consentResource, detailedConsentResource);
if (requestUriKey != null && publishedRequestUriKeyQueue.contains(requestUriKey)) {
String eventType = obEvent.getEventType();
ConsentStatusEnum consentStatus = getConsentStatusForEventType(eventType);
AuthorisationFlowTypeEnum authFlowType = getAuthFlowTypeForEventType(eventType);
String eventIdentifier = getEventIdentifier(consentResource, detailedConsentResource, eventType);
if (eventIdentifier != null && publishedEventIdentifierQueue.contains(eventIdentifier)) {
if (log.isDebugEnabled()) {
log.debug("Skipping authorisation data publishing for requestUriKey: " + requestUriKey +
log.debug("Skipping authorisation data publishing for event identifier: " + eventIdentifier +
" as it has already been published.");
}
return;
Expand All @@ -190,7 +191,7 @@ public void processEvent(OBEvent obEvent) {
consentStatus, authFlowType, customerProfile, consentDurationType);

dataPublishingService.publishAuthorisationData(authorisationData);
addToPublishedRequestUriKeyQueue(requestUriKey);
addToPublishedEventIdentifierQueue(eventIdentifier);
}

}
Expand Down Expand Up @@ -390,32 +391,32 @@ private AuthorisationFlowTypeEnum getAuthFlowTypeForEventType(String eventType)
}

/**
* Add the request uri key to the published data queue.
* Add the event identifier to the published data queue.
* If the queue is full, oldest key is removed.
* 20 keys are maintained in the queue to handle simultaneous consent state change events.
*
* @param requestUriKey request uri key coming as a consent attribute
* @param eventIdentifier request uri key coming as a consent attribute + event type to identify a unique event.
*/
private void addToPublishedRequestUriKeyQueue(String requestUriKey) {
private void addToPublishedEventIdentifierQueue(String eventIdentifier) {

if (StringUtils.isBlank(requestUriKey)) {
if (StringUtils.isBlank(eventIdentifier)) {
return;
}
if (publishedRequestUriKeyQueue.size() >= 20) {
publishedRequestUriKeyQueue.pollFirst();
if (publishedEventIdentifierQueue.size() >= 20) {
publishedEventIdentifierQueue.pollFirst();
}
publishedRequestUriKeyQueue.addLast(requestUriKey);
publishedEventIdentifierQueue.addLast(eventIdentifier);
}

private String getRequestUriKeyFromConsentResource(ConsentResource consentResource,
DetailedConsentResource detailedConsentResource) {
private String getEventIdentifier(ConsentResource consentResource, DetailedConsentResource detailedConsentResource,
String eventType) {

Map<String, String> consentAttributes = null;
if (consentResource != null) {
consentAttributes = consentResource.getConsentAttributes();
} else if (detailedConsentResource != null) {
consentAttributes = detailedConsentResource.getConsentAttributes();
}
return consentAttributes != null ? consentAttributes.get(REQUEST_URI_KEY) : null;
return consentAttributes != null ? (consentAttributes.get(REQUEST_URI_KEY) + ":" + eventType) : null;
}
}

0 comments on commit ef576f1

Please sign in to comment.