Skip to content

Commit

Permalink
Removing conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashi1993 committed Oct 27, 2024
1 parent 867c2d6 commit 358e98b
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 2,767 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
* under the License.
*/

package com.wso2.openbanking.accelerator.consent.extensions.common.idempotency;
package org.wso2.financial.services.accelerator.consent.mgt.extensions.common.idempotency;

import com.wso2.openbanking.accelerator.common.exception.OpenBankingException;
import org.wso2.financial.services.accelerator.common.exception.ConsentManagementException;

/**
* Used for handling exceptions in Idempotency Validation.
*/
public class IdempotencyValidationException extends OpenBankingException {
public class IdempotencyValidationException extends ConsentManagementException {

public IdempotencyValidationException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@
* under the License.
*/

package com.wso2.openbanking.accelerator.consent.extensions.common.idempotency;
package org.wso2.financial.services.accelerator.consent.mgt.extensions.common.idempotency;

import com.wso2.openbanking.accelerator.common.config.OpenBankingConfigParser;
import com.wso2.openbanking.accelerator.common.exception.ConsentManagementException;
import com.wso2.openbanking.accelerator.consent.extensions.internal.ConsentExtensionsDataHolder;
import com.wso2.openbanking.accelerator.consent.mgt.service.ConsentCoreService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigParser;
import org.wso2.financial.services.accelerator.common.exception.ConsentManagementException;
import org.wso2.financial.services.accelerator.consent.mgt.extensions.internal.ConsentExtensionsDataHolder;
import org.wso2.financial.services.accelerator.consent.mgt.service.ConsentCoreService;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Class to hold idempotency validation utils.
Expand All @@ -49,8 +52,8 @@ public class IdempotencyValidationUtils {
* @param idempotencyKeyValue Idempotency Key Value
* @return List of consent ids if available, else an empty list will be returned
*/
static ArrayList<String> getConsentIdsFromIdempotencyKey(String idempotencyKeyName,
String idempotencyKeyValue) {
static List<String> getConsentIdsFromIdempotencyKey(String idempotencyKeyName,
String idempotencyKeyValue) {
try {
return consentCoreService.getConsentIdByConsentAttributeNameAndValue(
idempotencyKeyName, idempotencyKeyValue);
Expand All @@ -60,6 +63,21 @@ static ArrayList<String> getConsentIdsFromIdempotencyKey(String idempotencyKeyNa
}
}

/**
* Method to retrieve the consent ids and idempotency key value using the idempotency key.
*
* @param idempotencyKeyName Idempotency Key Name
* @return Map of consent ids and idempotency key vallue if available, else an empty map will be returned
*/
static Map<String, String> getAttributesFromIdempotencyKey(String idempotencyKeyName) {
try {
return consentCoreService.getConsentAttributesByName(idempotencyKeyName);
} catch (ConsentManagementException e) {
log.debug("No consent ids found for the idempotency key value");
return new HashMap<>();
}
}

/**
* Method to compare the client ID sent in the request and client id retrieved from the database.
*
Expand All @@ -86,13 +104,13 @@ static boolean isRequestReceivedWithinAllowedTime(long createdTime) {
log.debug("Created time is of the previous request is not correctly set. Hence returning false");
return false;
}
String allowedTimeDuration = OpenBankingConfigParser.getInstance().getIdempotencyAllowedTime();
String allowedTimeDuration = FinancialServicesConfigParser.getInstance().getIdempotencyAllowedTime();
if (StringUtils.isNotBlank(allowedTimeDuration)) {
OffsetDateTime createdDate = OffsetDateTime.parse(toISO8601DateTime(createdTime));
OffsetDateTime currDate = OffsetDateTime.now(createdDate.getOffset());

long diffInMinutes = Duration.between(createdDate, currDate).toMinutes();
return diffInMinutes <= Long.parseLong(allowedTimeDuration);
long diffInHours = Duration.between(createdDate, currDate).toHours();
return diffInHours <= Long.parseLong(allowedTimeDuration);
} else {
log.error("Idempotency allowed duration is not configured in the system. Hence returning false");
return false;
Expand Down
Loading

0 comments on commit 358e98b

Please sign in to comment.