Debug JSON logic from Rest Connector

vinitamulchanda
New Contributor
New Contributor

UseCase

while performing remove access from user, we have requirement that we need to get the complete user payload from target. Iterate the payload and remove only few properties from payload I have from removeAccess task.

1. Get the user payload (say I have call1 to get the user payload and retrieve the payload in below form)
<Payload>

User :{

"id" : "10201",

"name" " "abc",

"globalProperties":

{

"partnerProperties":{

"fieldID1234":[

"filedProperty1",

"fieldProperty2",

],

"fieldID5678":[

"filedProperty1",

"fieldProperty2",

]

}

},

"clientAttributes":

[

{

"clientID:"  "client1"

"ClientProperties" : {

clientfieldID1234":[

"clientfieldProperty1",

"clientfieldProperty2",

]

}

},

 

{

"clientID:"  "client2"

"ClientProperties" : {

clientfieldID5678":[

"clientfiledProperty1",

"clientfieldProperty2",

]

}

}

}

</Payload>

So from the above payload while remove access, the use case suppose is I have to remove below values which would be part of my remove Access task:

1. globalProperties.partnerProperties.fileldID5678.fieldProperty1

Our remove access entitlement CP values will hold the corresponding data - Customproperty9 - filedID56790, custompropert10 - fieldProperty1.

 

2. clientProperties.clientFieldID5678.fieldProperty1

Customproperty7 - clientfiledID56790, custompropert8 - clientfieldProperty1.

 

Based on the above use case our remove Access Json we have planned below algorithm as follows:

<Alogorithm>

1. get the user payload from target.

2. iterate the JSON. 

3. get gloabalProperties as a hasMap(<String,List<String>).

HashMap(String,List<String>) hashMap = response.message.User.globalProperties.partnerProperties;

4. Find the respective filedID from HasMap and retrieve the list.

ArrayList<String> strList = hashMap.get(entitlementValue.customProperty9);

strList.remove(entitlementValue.customPropery10);

hasMap.set(entitlementValue.customProperty9,strList);

and then we set back the complete hashMap as an attribute back to our payload.

 

\"partnerProperties\" : \"${hashMap}\";

</Algorithm>

Could you please share your advice whether the analysed approach is correct, and since connector JSON does does not prints any logs unless JSON compiles successfully, would also like to have your inputs how do we test the JSON step by step, is there any better approach to step by step compile and validate the json as and when we proceed with our algorithm?

 

 

 

}

The below code we have tested in Java environment, could you please suggest this similar we can use in our JSON:

private HashMap returnHashMap(HashMap<String, List<String>> map) {
	Iterator iter = map.entrySet().iterator();
	while (iter.hasNext()) {
		Map.Entry entry = (Map.Entry) iter.next();
		if (entry.getKey().toString().equalsIgnoreCase("ee333334444sfsdfs_c")) {
			System.out.println("This means the property is found. Now need to check how big is the list in the key-value pair.");
		
			List<String> s = (List<String>) entry.getValue();
			if (s != null && s.size() == 0) {
				System.out.println("No roles assigned for this property <this shouldn't be the case ideally>");
			} else if (s != null && s.size() == 1) {
				System.out.println("This means the custom property is only having 1 role, hence the same should be removed.");
				map.remove("ee333334444sfsdfs_c", s);
				break;
			} else {
				System.out.println("This means the custom property is tagged with multiple roles. Hence need to traverse.");
				for (int i = 0; i < s.size(); i++) {
					if (s.get(i).equalsIgnoreCase("Global Admin - Sprinklr Admin5")) {
						System.out.println("Role against the property found. Remove it!!");
						s.remove(i);
					}
				}
			}
		} else {
			System.out.println("This means the property isn't found. This shouldn't be the case as the request is for role removal under the specific custom property and here the role isn't tagged. Data issue.");
		}
	}
	return map;
}

[This post has been edited by a Moderator to merge two posts.]

 

1 REPLY 1

SB
Saviynt Employee
Saviynt Employee

Based on the above, the approach looks doable. Since Saviynt uses groovy, I would suggest you to test and validate the function using an online groovy compiler and then incorporate it in your JSON. Though the logs currently do not print the information but Saviynt product team is already working on its improvement.


Regards,
Sahil