This guide provides instructions on how to consume or use SAP BRMS in EJB.
Applies to:
This Document Holds good for all CE 7.3 SPXX. This method can also be used for Older version of CE (CE7.1 SP01 on-wards) with some difference in contend .
Summary:
This guide describes step-by-step how to return single value and multiple values from Decision Table.To Explain this we are using 2 Examples to explain how to read SAP BRMS in EJB.
Example 1 : Single set of values Returned.
Example 2 : Multiple List of values Returned.(How to consume or use SAP BRMS in EJB Part 2.)
We will be discussing following points in detail in this document -
Special Thanks to Samudra Gupta samudra.gupta for his guidance to Document the process.
Example : Based on Entered Plant & product code delivery plant is to be defined.
Step 1 : Create an DTO called "Plant" as shown below:
import java.io.Serializable;
public class Plant implements Serializable{
private static final long serialVersionUID = -3420223731187536617L;
private String plant ;
private String productCode ;
private String deliveryPlantList ;
public String getPlant() {
return plant;
}
public void setPlant(String plant) {
this.plant = plant;
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public String getDeliveryPlantList() {
return deliveryPlantList;
}
public void setDeliveryPlantList(String deliveryPlantList) {
this.deliveryPlantList = deliveryPlantList;
}
}
Step 2: Expose the Class file in public Parts as shown below:
Step 3 : Build the test/ejb/module and add it in "Dependencies" of "test/rules". Only "Design Time" is required.
Step 4 : Go to the rules project and add the dto class.
Step 5 : Now Right Click on "Rules Modeling" & Select "New Ruleset".
Setp 6 : On Selecting "New Ruleset" a pop up opens up as shown below. Enter the name to the rule set like "DeliveryPlantRuleset".
Step 7 : On Clicking on "OK" We get a new Rule Set created as shown below:
Step 8 : Creation of Rules & Decision Table.
Step 9 : Enter some dummy values in the Decision Table as shown below. Save it build and deploy "test/ejb/app" & "test/rules" in sequence.
Step 10 : Calling the Rule from "test/ejb/module".
Step 11 : Build the dc's "test/ejb/module" & "test/ejb/app". Deploy the dc "test/ejb/app".
Step 12 : Go to http://<Server>:<port>/wsnavigator and test the service be entering the "Plant" & "Product Code" you will get back the Plant DTO with the entered values along with "Delivery Plant".
Appendix 1 : EngineInvoker.java Class file code.
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import com.sap.brms.qrules.ejb.RuleEngineHome;
import com.sap.brms.qrules.engine.RuleEngine;
import com.sap.tc.logging.Location;
public class EngineInvoker {
static Location logger = Location.getLocation(EngineInvoker.class);
private static String jndiName = "com.sap.brms.RuleEngine";
public static RuleEngine getRuleEngine() throws Exception {
InitialContext context = new InitialContext();
Object obj = context.lookup(jndiName);
RuleEngineHome home = (RuleEngineHome) PortableRemoteObject.narrow(obj,RuleEngineHome.class);
return (RuleEngine) home.create();
}
@SuppressWarnings("unchecked")
public static List<String> invokeRuleset(String projectName, String rsName,List<Serializable> input) {
logger.debugT("start:invokeRuleset");
List output = new ArrayList();
RuleEngine ruleEngine;
if (projectName == null || rsName == null || input == null) {
output.add("Project Name or Ruleset Name or Payload should not be NULL");
}
try {
ruleEngine = getRuleEngine();
output = ruleEngine.invokeRuleset(projectName, rsName, input);
} catch (Exception e) {
logger.errorT("error occured:"+e.getMessage());
e.printStackTrace();
}
logger.debugT("start:invokeRuleset");
return output;
}
}
Appendix 2 : DeliveryPlantRules.java Class file code.
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import util.EngineInvoker;
import com.sap.tc.logging.Location;
import dto.Plant;
@Stateless
public class DeliveryPlantRules implements DeliveryPlantRulesLocal {
static Location logger = Location.getLocation(DeliveryPlantRules.class);
@SuppressWarnings("unchecked")
public Plant getDeliveringPlantForProductsRules(Plant plant){
logger.debugT("start:getRullesData");
List<Serializable> ilist = new ArrayList<Serializable>();
ilist.add(plant);
Object object = new Object();
if (ilist.size() != 0) {
List output = EngineInvoker.invokeRuleset("demo.sap.com~test~rules", "DeliveryPlantRuleset", ilist);
if (output.size() != 0) {
object = output.get(0);
}
} else {
object = "Input has not been set.";
}
logger.debugT("end:getRullesData");
if (object instanceof Plant) {
return (Plant) object;
}
return null;
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
46 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 |