Generic after rule for account status in webservice source

If you have multiple statuses on end source for active or inactive status then current webservice source lacks the capability to configure this. You can only specify one value as active status.

To reduce the repetitive effort of doing the same task I developed generic rule which is very basic and you do not need to change anything to use it for your environment.



		
		//These are 3 attributes which needs to be added in connectorAttributes on source json so rule can read them. enablelist and disablelist would be json list
		String statusAttribute=(String) application.getAttributeValue("statusAttribute");
		List enableList=(List) application.getAttributeValue("enableValues");
		List disableList=(List) application.getAttributeValue("disableValues");
		
		for(Object object: processedResponseObject) {
		
			Map userMap=(Map)object;
			if(userMap.containsKey(statusAttribute)) {
				
				String statusValue=((String) userMap.get(statusAttribute)).toLowerCase(); 
			
				if(enableList != null) {
					
					for(String str: enableList) {
					    if(str.toLowerCase().equalsIgnoreCase(statusValue)) {
					       userMap.put("IIQDisabled", false);
					    	break;
					    	//if we get one value compared from the enable list then no need to check for rest of them
					    }
					}
				}
				
				if(disableList != null) {
					
					for(String str: disableList) {
					    if(str.toLowerCase().equalsIgnoreCase(statusValue)) {
					       userMap.put("IIQDisabled", true);
					    	break;
					    	//if we get one value compared from the disable list then no need to check for rest of them
					    }
					}
				}
			}
		}
		
	

You need to add 3 attributes under source json using patch api. The attributes which need to be added are.

  1. statusAttribute: The value of this attribute is the one which you have defined in your response mapping on left side and not the attribute name from end source json response.

  2. enableList : if your end system has 3 different status for active account then enter it as json list.
    e.g. body for json patch:

[
    {
        "op": "add",
        "path": "/connectorAttributes/enableValues",
        "value": ["active","activationSent","Pending"]
    }
]
  1. disableList: list of statuses which define if account is disabled.

All comparison is case insensitive.

Do let me know if anyone faces any issue in using the rule snippet.

4 Likes

Hi @chirag_patel

Just a question about this sniplet. What is the reason you are using a contains to compare string values and not a equals? using contains could lead to false positives as for example “active” is contained in “inactive” but they are not equal.

Cheers.
Vincent

Thanks @vkoldenh for looking into it. The rule I am using in my environment had equalignorecase and updated that here also. This seems like I copied some other version by mistake.