Sterling OMS Writing First Dynamic Condition

By | 08/13/2017

Sterling OMS Writing First Dynamic Condition

Sterling OMS Writing First Dynamic Condition

Sterling OMS Writing First Dynamic Condition

Before going to this session hope you had chance to read about Condition and Sterling OMS Static Condition. If not please click here and read about Sterling OMS Static Condition

Why do we need Dynamic Condition ?

Using Static Condition, we will be able to validate all the variables and why do we need dynamic condition ? Any luck getting answer for above question ? After bit thinking below is answer from our side (If some one has different thought feel free to comment)

Consider below example,

<Order OrderNo=”ABC”>
<OrderLine OrderNo=”XYZ” />
</Order>

In this below example, using static condition user want to compare line level OrderNo (/Order/OrderLine/@OrderNo) but when we use static condition we can not provide XPath. In static condition we will be able to provide attribute name (OrderNo) and compare with any value (XYZ). Static condition finds and return first occurrence of OrderNo (/Order/@OrderNo) value (ABC) . Hence we need java based more dynamic solution to resolve these kind of problems. Hence Dynamic condition required.

How to write Dynamic Condition ?

  1. Creating Java class which implements one of the interface (YCPDynamicCondition OR YCPDynamicConditionEx)
  2. Java class should override evaluateCondition() method with return type as boolean
  3. Use the Java class name along with package name in dynamic condition configuration (com.oms94.test.CustomDynamicCondition)

What is different in both interface YCPDynamicCondition Vs YCPDynamicConditionEx ?

YCPDynamicCondition YCPDynamicConditionEx
@Override

public boolean evaluateCondition(YFSEnvironment arg0, String name, Map dataMap, String xmlData) {

return false;

}

@Override

public boolean evaluateCondition(YFSEnvironment arg0, String name, Map dataMap, Document doc) {

return false;

}

 

@Override

public void setProperties(Map arg0) {

}

String — Name : Name of the condition

Map — dataMap : contains the name-value pair of strings. Keys are same as the variables available in condition builder.

String — XMLData: XML Data

String — Name : Name of the condition

Map — contains the name-value pair of strings. Keys are same as the variables available in condition builder.

Document — XML Data

Map Data attribute always null or empty Using set properties method Map Data attribute always populated (if available)

YCPDynamicCondition : Can be used when no need to compare input XML attribute value with any external configuration values.

YCPDynamicConditionEx : Can be used when we need to compare input XML attribute value with external configuration values.

Sample Implementation with YCPDynamicCondition Interface

package com.oms94.test;

import java.util.Map;


import com.yantra.ycp.japi.YCPDynamicCondition;
import com.yantra.yfc.dom.YFCDocument;
import com.yantra.yfs.japi.YFSEnvironment;

public class CustomDynamicCondition implements YCPDynamicCondition {

	
	/* 
	 *  name is the name of the condition configured in the database
	 *  mapData contains the name-value pair of strings. Keys are same as the variables available in condition builder.
	 *  xmlData : XML Data
	 */
	@Override
	public boolean evaluateCondition(YFSEnvironment env, String name, Map mapData, String xmlData) {		
		try {
            YFCDocument xml = YFCDocument.getDocumentFor(xmlData);
            // walk thru the xml and evaluate condition
            // Let us say, in this condition we are checking if value of the attribute "OrderNumber"
            // under the root node is empty or not  
            /*<Order OrderNumber="">*/
            String attrVal = xml.getDocumentElement().getAttribute("OrderNumber");
            if (attrVal == null || attrVal.trim().length() == 0)
            return false;
            else
            return true;
		}
		catch (Exception ex) {
		    throw new RuntimeException("CustomDynamicCondition failed due to ...");
		}
	}

}

Sample Implementation with YCPDynamicConditionEx Interface

package com.oms94.test;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import org.w3c.dom.Document;

import com.yantra.ycp.japi.YCPDynamicConditionEx;
import com.yantra.yfc.dom.YFCDocument;
import com.yantra.yfs.japi.YFSEnvironment;

public class CustomDynamicConditionEx implements YCPDynamicConditionEx {

	/* 
	 *  Input :  <Order EnterpriseCode="" />
	 *  name is the name of the condition configured in the database
	 *  mapData contains the name-value pair of strings. Keys are same as the variables available in condition builder.
	 *  xmlData : XML Data
	 */
	Map _properties = new HashMap();

	public boolean evaluateCondition(YFSEnvironment env, String name, Map mapData, Document doc) {
		try {
			mapData = _properties;
			System.out.println("CustomDynamicConditionEx:mapData:" + mapData);
			YFCDocument xml = YFCDocument.getDocumentFor(doc);
			// For example, let us say, in this condition we are checking if
			// value of the attribute "OrderNumber"
			// under the root node is empty or not
			String attrVal = xml.getDocumentElement().getAttribute("EnterpriseCode");

			if (attrVal == null || attrVal.trim().length() == 0) {
				return false;
			}
			// the keys of mapData are the same as the variables available in
			// condition builder
			String enterpriseCode = (String) mapData.get("EnterpriseCode");
			if (enterpriseCode != null && attrVal.contains(enterpriseCode)) {
				return true;
			}
			return false;
		} catch (Exception ex) {
			throw new RuntimeException("TestDynamicConditionEx failed due to ...");
		}
	}

	public void setProperties(Map map) {
		System.out.println("CustomDynamicConditionEx:setProperties:" + map);
		if (map != null && !map.isEmpty()) {
			_properties.putAll(map);
		}
	}
}

Where to Configure Condition in Application Manager ?

  • Login into OMS application
  • Go to application manager
  • Applications – Application Platform
  • Process Modelling
  • Click any tab (Example Order) and click on any one of Process Types (Example Order Fulfillment)
  • Create Condition – Right click on Conditions menu
  • Enter Condition Name / Description / Group Name details
  • Select Dynamic Condition radio button
  • Enter full Java Class path name (com.oms94.test.CustomDynamicCondition)
  • Click Save

Testing CustomDynamicCondition

  • Create condition as shown belowCustomDynamicCondition

Dynamic Condition Service

Input XML Result
<Order OrderNumber=”” /> No record inserted; because Order number attribute value is empty
<Order OrderNumber=”123″ /> Record inserted
<Order /> No record inserted; because Order number attribute missing
<Order EnterpriseCode=”” /> No record inserted; because Order number attribute missing

Testing CustomDynamicConditionEx

  • Create new condition as shown below

CustomDynamicConditionEx

Dynamic Condition Ex Service

Input XML Result
<Order EnterpriseCode=”Default” /> Record not inserted into DB because enterprise code Default not matched with MMM
<Order EnterpriseCode=”MMM”/> Record inserted into DB because enterprise code Default matched with MMM
<Order /> Record not inserted into DB because enterprise code attribute missing

Your feedback is important to us. Please share your feedback at support@activekite.com

Register with us to get more OMS learning updates

Sterling OMS Interview Questions

5 thoughts on “Sterling OMS Writing First Dynamic Condition

    1. admin Post author

      Thanks Ravi. Keep sharing your comments and feedback.

      Reply
  1. Mano Vignesh

    Another way to evaluate xpath condition in Sterling is by using the Default component. We can specify the xpath in Default Component’s ‘Element Path’ field and based on that, we can set up a flag with a default value. Later the flag can be evaluated using a condition component. Though it has some limitations, it will mainly help in adding a xpath condition in prod without doing code deployment.

    Reply
    1. admin Post author

      We agree with you. Default component is life save many times. Thanks for sharing. Keep share and learn !!!

      Reply
  2. HEMANANTH.P

    Hi,
    Very Good Explanation
    Easy to underStand
    Thanks for posting about this topic its too more helpful for me
    keep Posting more information about more topics

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *