Skip to content

Commit

Permalink
MOSIP-35390
Browse files Browse the repository at this point in the history
Signed-off-by: Sohan Kumar Dey <[email protected]>
  • Loading branch information
Sohandey committed Sep 11, 2024
1 parent 2ef7976 commit c9b63e2
Showing 1 changed file with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5166,7 +5166,7 @@ else if (eachRequiredProp.equals("password")) {
}
}
}
if (selectedHandles != null && selectedHandles.size()>=1) {
if (selectedHandles != null) {
setfoundHandlesInIdSchema(true);
identityJson.put("selectedHandles", selectedHandles);
}
Expand Down Expand Up @@ -7915,7 +7915,11 @@ else if (testCaseName.contains("_withselectedhandlephone")) {

// Update the identity with the modified selectedHandles array
identity.put("selectedHandles", updatedHandles);
} else {
}else if (testCaseName.contains("_removealltagshandles")) {
removeTagsHandles(jsonObj);


} else {
// If "selectedHandles" doesn't exist, create it with "phone"
JSONArray newSelectedHandles = new JSONArray();
newSelectedHandles.put("phone");
Expand All @@ -7938,7 +7942,29 @@ else if (testCaseName.contains("_withselectedhandlephone")) {

return jsonObj.toString();
}

private void removeTagsHandles(JSONObject jsonObj) {
for (String key : jsonObj.keySet()) {
Object value = jsonObj.get(key);
if (value instanceof JSONObject) {
JSONObject nestedObject = (JSONObject) value;
if (nestedObject.has("tags")) {
JSONArray tagsArray = nestedObject.getJSONArray("tags");
if (tagsArray.length() == 1 && "handles".equals(tagsArray.getString(0))) {
nestedObject.remove("tags");
}
}
removeTagsHandles(nestedObject); // Recursively call for deeper levels
} else if (value instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) value;
for (int i = 0; i < jsonArray.length(); i++) {
Object arrayElement = jsonArray.get(i);
if (arrayElement instanceof JSONObject) {
removeTagsHandles((JSONObject) arrayElement); // Recursively handle each element
}
}
}
}
}

public String replaceArrayHandleValuesForUpdateIdentity(String inputJson, String testCaseName) {
JSONObject jsonObj = new JSONObject(inputJson);
Expand Down Expand Up @@ -8243,6 +8269,14 @@ else if (testCaseName.contains("_withphonevalue")) {
identity.put(result, "$ID:AddIdentity_array_handle_value_smoke_Pos_withselectedhandlephone_PHONE$" );
}
}
else if (testCaseName.contains("_removeselectedhandlesandupdateemail")) {
if (identity.has("selectedHandles")) {
identity.remove("selectedHandles");
}
if (identity.has(emailResult)) {
identity.put(emailResult, "$ID:AddIdentity_array_handle_value_update_smoke_Pos_withselectedhandlephone_EMAIL$" );
}
}

identity.put(handle, handleArray);
}
Expand Down

0 comments on commit c9b63e2

Please sign in to comment.