Skip to content

Commit

Permalink
do isEligible check for selectable accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
VimukthiRajapaksha committed Jan 7, 2025
1 parent 696eb10 commit 6923660
Showing 1 changed file with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,9 @@ public String getJSPPath() {
* @param data: data map
*/
private void updateIndividualPersonalAccountAttributes(JSONObject account, Map<String, Object> data) {
if ((account != null && account.getBoolean(CDSConsentExtensionConstants.IS_ELIGIBLE)) &&
(CDSConsentExtensionConstants.INDIVIDUAL_PROFILE_TYPE.equalsIgnoreCase(
if (CDSConsentExtensionConstants.INDIVIDUAL_PROFILE_TYPE.equalsIgnoreCase(
account.getString(CDSConsentExtensionConstants.CUSTOMER_ACCOUNT_TYPE))
&& !account.getBoolean(CDSConsentExtensionConstants.IS_JOINT_ACCOUNT_RESPONSE))) {
&& !account.getBoolean(CDSConsentExtensionConstants.IS_JOINT_ACCOUNT_RESPONSE)) {
data.put(CDSConsentExtensionConstants.IS_SELECTABLE, true);
}
}
Expand All @@ -240,9 +239,8 @@ private void updateIndividualPersonalAccountAttributes(JSONObject account, Map<S
* @param data: data map
*/
private void updateBusinessAccountAttributes(JSONObject account, Map<String, Object> data) {
if ((account != null && account.getBoolean(CDSConsentExtensionConstants.IS_ELIGIBLE)) &&
(CDSConsentExtensionConstants.BUSINESS_PROFILE_TYPE.equalsIgnoreCase(
account.getString(CDSConsentExtensionConstants.CUSTOMER_ACCOUNT_TYPE)))) {
if (CDSConsentExtensionConstants.BUSINESS_PROFILE_TYPE.equalsIgnoreCase(
account.getString(CDSConsentExtensionConstants.CUSTOMER_ACCOUNT_TYPE))) {
boolean isSelectable = true;
if (isConsentAmendment) {
try {
Expand All @@ -269,7 +267,7 @@ private void updateBusinessAccountAttributes(JSONObject account, Map<String, Obj
}

private void updateJointAccountAttributes(JSONObject account, Map<String, Object> data) {
if (account != null && (account.getBoolean(CDSConsentExtensionConstants.IS_JOINT_ACCOUNT_RESPONSE))
if (account.getBoolean(CDSConsentExtensionConstants.IS_JOINT_ACCOUNT_RESPONSE)
&& !account.getBoolean(CDSConsentExtensionConstants.IS_SECONDARY_ACCOUNT_RESPONSE)) {

// Check the eligibility of the joint account for data sharing
Expand Down Expand Up @@ -312,7 +310,7 @@ private void updateJointAccountAttributes(JSONObject account, Map<String, Object
* @param data: data map
*/
private void updateSecondaryAccountAttributes(JSONObject account, Map<String, Object> data) {
if (account != null && account.getBoolean(CDSConsentExtensionConstants.IS_SECONDARY_ACCOUNT_RESPONSE)) {
if (account.getBoolean(CDSConsentExtensionConstants.IS_SECONDARY_ACCOUNT_RESPONSE)) {
data.put(CDSConsentExtensionConstants.IS_SECONDARY_ACCOUNT, true);

// secondaryAccountPrivilegeStatus depicts whether the user has granted permission to share data from
Expand Down Expand Up @@ -381,27 +379,31 @@ private Map<String, List<String>> getRequestedDataMap(JSONArray dataRequestedJso

private List<Map<String, Object>> getAccountsDataMap(JSONArray accountsArray) {

List<Map<String, Object>> accountsData = new ArrayList<>();
final List<Map<String, Object>> accountsData = new ArrayList<>();
for (int accountIndex = 0; accountIndex < accountsArray.length(); accountIndex++) {
Map<String, Object> data = new HashMap<>();
JSONObject account = accountsArray.getJSONObject(accountIndex);
String accountId = account.getString(CDSConsentExtensionConstants.ACCOUNT_ID);
String accountIdToDisplay = account.has(CDSConsentExtensionConstants.ACCOUNT_ID_DISPLAYABLE)
? account.getString(CDSConsentExtensionConstants.ACCOUNT_ID_DISPLAYABLE) : accountId;
String displayName = account.getString(CDSConsentExtensionConstants.DISPLAY_NAME);
String isPreSelectedAccount = "false";
updateIndividualPersonalAccountAttributes(account, data);
updateBusinessAccountAttributes(account, data);
updateJointAccountAttributes(account, data);
updateSecondaryAccountAttributes(account, data);

if (account.has(CDSConsentExtensionConstants.IS_PRE_SELECTED_ACCOUNT)) {
isPreSelectedAccount = account.getString(CDSConsentExtensionConstants.IS_PRE_SELECTED_ACCOUNT);
final JSONObject account = accountsArray.getJSONObject(accountIndex);
final Map<String, Object> data = new HashMap<>();

if (this.isEligibleAccount(account)) {
updateIndividualPersonalAccountAttributes(account, data);
updateBusinessAccountAttributes(account, data);
updateJointAccountAttributes(account, data);
updateSecondaryAccountAttributes(account, data);
}

final String accountId = account.getString(CDSConsentExtensionConstants.ACCOUNT_ID);
data.put(CDSConsentExtensionConstants.ACCOUNT_ID, accountId);

final String accountIdToDisplay = account.has(CDSConsentExtensionConstants.ACCOUNT_ID_DISPLAYABLE)
? account.getString(CDSConsentExtensionConstants.ACCOUNT_ID_DISPLAYABLE) : accountId;
data.put(CDSConsentExtensionConstants.ACCOUNT_ID_DISPLAYABLE, accountIdToDisplay);
data.put(CDSConsentExtensionConstants.DISPLAY_NAME, displayName);
data.put(CDSConsentExtensionConstants.IS_PRE_SELECTED_ACCOUNT, isPreSelectedAccount);

data.put(CDSConsentExtensionConstants.DISPLAY_NAME,
account.getString(CDSConsentExtensionConstants.DISPLAY_NAME));

data.put(CDSConsentExtensionConstants.IS_PRE_SELECTED_ACCOUNT,
account.optString(CDSConsentExtensionConstants.IS_PRE_SELECTED_ACCOUNT, "false"));

accountsData.add(data);
}
return accountsData;
Expand Down Expand Up @@ -438,4 +440,8 @@ private List<Map<String, Object>> getCustomerProfileDataList(JSONArray customerP
return profileDataList;
}

private boolean isEligibleAccount(JSONObject account) {

return account != null && account.getBoolean(CDSConsentExtensionConstants.IS_ELIGIBLE);
}
}

0 comments on commit 6923660

Please sign in to comment.