So essentially the API endpoint on this application (which app btw?) for setting entitlements cannot support a ‘PATCH’ where you only add / remove what you want, but it will replace entirely the entitlement(s) that were there. This causes the 1st entitlement that was added to be removed on the operation for the 2nd entitlement.
I would indeed use a before operation rule that gets ALL current entitlements and then ‘rebuilds’ the body for the new operation, including the newly added entitlement.
Your operations will look like this:
- Operation 1: Add entitlement. This should call the API to GET the current entitlements
a) ensure you have mapped the result properly, otherwise you cannot use it in the next operation - Operation 2: Get Object, with operation 1 as the parent operation. This operation should have the below rule as the beforeOperation rule
Please see an example rule below, where I do the same:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import connector.common.JsonUtil;
import connector.common.Util;
import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AccountRequest;
log.debug(application.getName() + " Combine Capabilities: oldResponseMap: "+oldResponseMap);
Map body = requestEndPoint.getBody();
log.debug(application.getName() + " Combine Capabilities: body: "+body);
String jsonBody = (String) body.get("jsonBody");
log.debug(application.getName() + " Combine Capabilities: jsonBody: "+jsonBody);
List capabilities = new ArrayList();
List currentCapabilities = oldResponseMap.get("capabilities");
log.debug(application.getName() + " Combine Capabilities: currentCapabilities: "+currentCapabilities);
if (jsonBody != null){
log.debug(application.getName() + " Combine Capabilities: jsonBody: "+jsonBody);
if (jsonBody.toString().startsWith("[")) {
List jsonBodyList = JsonUtil.toList(jsonBody);
log.debug(application.getName() + " Combine Capabilities: jsonBody2: "+jsonBodyList);
for(String jsonBodyStr: jsonBodyList) {
capabilities.add(jsonBodyStr);
}
} else {
capabilities.add(jsonBody);
}
}
log.debug(application.getName() + " Combine Capabilities: capabilities: "+capabilities);
if (currentCapabilities != null) {
for (i = 0; i<currentCapabilities.size();i++) {
capabilities.add(currentCapabilities.get(i));
}
}
log.debug(application.getName() + " Combine Capabilities: capabilities after: "+capabilities);
Map authUserMap = new HashMap();
authUserMap.put("op", "replace");
authUserMap.put("path","/capabilities");
authUserMap.put("value",capabilities);
List authUserList = new ArrayList();
authUserList.add(authUserMap);
String finalBody = JsonUtil.render(authUserList);
body.put("jsonBody", finalBody);
requestEndPoint.setBody(body);
Map body = requestEndPoint.getBody();
log.debug(application.getName() + " Combine Capabilities: new body: "+body);