Skip to content

Commit

Permalink
Foxed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashi1993 committed Nov 6, 2024
1 parent edb9972 commit 1e13ec5
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<RequestRouter>org.wso2.financial.services.accelerator.gateway.executor.core.DefaultRequestRouter</RequestRouter>
{% endif %}
<FinancialServicesGatewayExecutors>
{% for type in financial_services.gateway.gateway_executors.type %}
<{{type.name}}>
{% for executor in type.executors %}
{% for executor in financial_services.gateway.executors %}
<{{executor.type}}>
{% for executor in executor.executor %}
<Executor class="{{executor.name}}" priority="{{executor.priority}}"/>
{% endfor %}
</{{type.name}}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ publisher_url="https://localhost:9443"
request_router="org.wso2.financial.services.accelerator.gateway.executor.core.DefaultRequestRouter"

#============executors=========================
[[financial_services.gateway.gateway_executors.type]]
name = "Default"
[[financial_services.gateway.gateway_executors.type.executors]]
[[financial_services.gateway.executors]]
type = "Default"
[[financial_services.gateway.executors.executor]]
name = "org.wso2.financial.services.accelerator.gateway.executor.impl.consent.ConsentEnforcementExecutor"
priority = 1
[[financial_services.gateway.gateway_executors.type.executors]]
[[financial_services.gateway.executors.executor]]
name = "org.wso2.financial.services.accelerator.gateway.executor.impl.error.handling.DefaultErrorHandlingExecutor"
priority = 1000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ public ConsentException(URI errorURI, AuthErrorCode error, String errorDescripti
}
}

public JSONObject createDefaultErrorObject(URI redirectURI, String errorCode, String errorMessage, String state) {
public JSONObject createDefaultErrorObject(URI redirectURI, String errorCode, String errorDescription,
String state) {

JSONObject error = new JSONObject();
error.put(ConsentExtensionConstants.ERROR_CODE, errorCode);
error.put(ConsentExtensionConstants.ERROR_MSG, "Consent Management Error");
error.put(ConsentExtensionConstants.ERROR_DESCRIPTION, errorMessage);
error.put(ConsentExtensionConstants.ERROR_DESCRIPTION, errorDescription);
if (state != null) {
error.put(ConsentExtensionConstants.STATE, state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public static String resolveUsernameFromUserId(String userID) {
username = OAuth2Util.resolveUsernameFromUserId(ConsentExtensionConstants.TENANT_DOMAIN, userID);
}
} catch (UserStoreException e) {
log.debug("Returning null since user ID is not found in the database");
return null;
}
return username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static boolean isTransactionFromToTimeValid(String fromDateVal, String to
// From date is equal or earlier than To date
return toDate.isEqual(fromDate) || toDate.isAfter(fromDate);
} catch (DateTimeParseException e) {
log.debug("Returning false since datetime cannot be parsed");
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void postProcessRequest(FSAPIRequestContext fsApiRequestContext) {
return;
}

boolean isValid = (boolean) jsonResponse.get(IS_VALID);
boolean isValid = jsonResponse.getBoolean(IS_VALID);
if (!isValid) {
String errorCode = jsonResponse.get(ERROR_CODE).toString();
String errorMessage = jsonResponse.get(ERROR_MESSAGE).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Default Executor to handle gateway errors.
Expand Down Expand Up @@ -99,7 +100,7 @@ private void handleRequestError(FSAPIRequestContext fsApiRequestContext) {
}

payload.put(ERRORS_TAG, errorList);
if (errorList.length() != 0) {
if (!errorList.isEmpty()) {
fsApiRequestContext.setModifiedPayload(payload.toString());
Map<String, String> addedHeaders = fsApiRequestContext.getAddedHeaders();
addedHeaders.put(GatewayConstants.CONTENT_TYPE_TAG, GatewayConstants.JSON_CONTENT_TYPE);
Expand Down Expand Up @@ -155,27 +156,22 @@ private JSONArray getErrorJSON(List<FSExecutorError> errors) {
JSONArray errorList = new JSONArray();
for (FSExecutorError error : errors) {
JSONObject errorObj = new JSONObject();
errorObj.put("code", error.getCode());
errorObj.put("message", error.getTitle());
errorObj.put("description", error.getMessage());
errorObj.put(GatewayConstants.CODE, error.getCode());
errorObj.put(GatewayConstants.MESSAGE, error.getTitle());
errorObj.put(GatewayConstants.DESCRIPTION, error.getMessage());
Map<String, String> links = error.getLinks();
if (links != null && links.size() > 0) {
if (links != null && !links.isEmpty()) {
JSONObject linksObj = new JSONObject();
links.forEach(linksObj::put);
errorObj.put("Links", linksObj);
errorObj.put(GatewayConstants.LINKS, linksObj);
}
errorList.put(errorObj);
}
return errorList;
}

private boolean isAnyClientErrors(HashSet<String> statusCodes) {
private boolean isAnyClientErrors(Set<String> statusCodes) {

for (String statusCode : statusCodes) {
if (statusCode.startsWith("4")) {
return true;
}
}
return false;
return statusCodes.stream().anyMatch(statusCode -> statusCode.startsWith("4"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ public class GatewayConstants {
public static final String ERROR_STATUS_PROP = "errorStatusCode";
public static final String IS_RETURN_RESPONSE = "isReturnResponse";
public static final String MODIFIED_STATUS = "ModifiedStatus";
public static final String CODE = "code";
public static final String MESSAGE = "message";
public static final String DESCRIPTION = "description";
public static final String LINKS = "links";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"consentInformation": {
"key": "value"
}
}
}

0 comments on commit 1e13ec5

Please sign in to comment.