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 .
Prerequisite:
This Document is a continuation of "How to consume or use SAP BRMS in EJB Part 1.". Kindly Read this document fist to understand this document.
Summary:
This guide describes step-by-step how to return single value and multiple values from Decision Table.To Explain this we are using an Examples to explain how to read SAP BRMS in EJB.
Example : Multiple List of values Returned.
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 list of delivery plant with Start Date & End Date is to be defined.
Step 1 : Create an DTO called "DeliveryPlant" as shown below:
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class DeliveryPlant implements Serializable{
private static final long serialVersionUID = -623563864537413057L;
private String entered_Plant ;
private String entered_ProductCode ;
private int identifier ;
private ArrayList<String> deliveryPlantList ;
private ArrayList<Date> startDateList ;
private ArrayList<Date> endDateList ;
// Added Code.
public DeliveryPlant (){
deliveryPlantList = new ArrayList<String>();
startDateList = new ArrayList<Date>();
endDateList = new ArrayList<Date>();
}
// Generated Code
public String getEntered_Plant() {
return entered_Plant;
}
public void setEntered_Plant(String enteredPlant) {
entered_Plant = enteredPlant;
}
public String getEntered_ProductCode() {
return entered_ProductCode;
}
public void setEntered_ProductCode(String enteredProductCode) {
entered_ProductCode = enteredProductCode;
}
public int getIdentifier() {
return identifier;
}
public void setIdentifier(int identifier) {
this.identifier = identifier;
}
public ArrayList<String> getDeliveryPlantList() {
return deliveryPlantList;
}
public void setDeliveryPlantList(ArrayList<String> deliveryPlantList) {
this.deliveryPlantList = deliveryPlantList;
}
public ArrayList<Date> getStartDateList() {
return startDateList;
}
public void setStartDateList(ArrayList<Date> startDateList) {
this.startDateList = startDateList;
}
public ArrayList<Date> getEndDateList() {
return endDateList;
}
public void setEndDateList(ArrayList<Date> endDateList) {
this.endDateList = endDateList;
}
// Added Code.
public void addDeliveryPlantList(String deliveryPlant) {
deliveryPlantList.add(deliveryPlant);
}
public void addStartDateList(String startDate) {
startDateList.add(getDate(startDate));
}
public void addEndDateList(String endDate) {
endDateList.add(getDate(endDate));
}
private Date getDate (String ipDate){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = dateFormat.parse(ipDate);
} catch (ParseException e) {
}
return date;
}
}
Step 2 : Create an DTO called "ResponceDTO" as shown below:
import java.io.Serializable;
import java.util.Date;
public class ResponceDTO implements Serializable{
private static final long serialVersionUID = 1L;
private String deliveryPlant ;
private Date startDate ;
private Date endDate ;
// Generated Code
public String getDeliveryPlant() {
return deliveryPlant;
}
public void setDeliveryPlant(String deliveryPlant) {
this.deliveryPlant = deliveryPlant;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
}
Step 3 : Create an DTO called "DeliveryPlantResponce" as shown below:
import java.io.Serializable;
import java.util.ArrayList;
public class DeliveryPlantResponce implements Serializable{
private static final long serialVersionUID = 1L;
private String entered_Plant ;
private String entered_ProductCode ;
private ArrayList<ResponceDTO> ResponceList ;
// Generated Code
public String getEntered_Plant() {
return entered_Plant;
}
public void setEntered_Plant(String enteredPlant) {
entered_Plant = enteredPlant;
}
public String getEntered_ProductCode() {
return entered_ProductCode;
}
public void setEntered_ProductCode(String enteredProductCode) {
entered_ProductCode = enteredProductCode;
}
public ArrayList<ResponceDTO> getResponceList() {
return ResponceList;
}
public void setResponceList(ArrayList<ResponceDTO> responceList) {
ResponceList = responceList;
}
// Added Code
public void addResponceList(ResponceDTO responceDto) {
ResponceList.add(responceDto);
}
}
Step 4 : Expose the "DeliveryPlant" Class file in Public Parts as shown before in Previous Document.
Step 5 : Build the test/ejb/module .
Optional : Add "test/ejb/module" in "Dependencies" of "test/rules". Only "Design Time" is required (Need to be done if not done before).
Step 6 : Go to the rules project and add the dto class.
Step 7 : Now Right Click on "Rules Modeling" & Select "New Ruleset".
Setp 8 : On Selecting "New Ruleset" a pop up opens up as shown below. Enter the name to the rule set like "DeliveryPlantsRuleset".
Step 9 : On Clicking on "OK" We get a new Rule Set created as shown below:
Step 10 : Creation of Rules & Decision Table.
Step 11 : Save it build and deploy "test/ejb/app" & "test/rules" in sequence.
Step 12 : Calling the Rule from "test/ejb/module".
Step 13 : Build the dc's "test/ejb/module" & "test/ejb/app". Deploy the dc "test/ejb/app".
Step 14 : Go to http://<Server>:<port>/wsnavigator and test the service be entering the "entered_Plant" & "entered_ProductCode" you will get back the "DeliveryPlantResponce" DTO with the entered values along with "ResponceDTO" List.
Appendix 1 : DeliveryPlantsRules.java Class file code.
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import util.EngineInvoker;
import com.sap.tc.logging.Location;
import dto.DeliveryPlant;
import dto.DeliveryPlantResponce;
import dto.ResponceDTO;
public class DeliveryPlantsRules implements DeliveryPlantsRulesLocal {
static Location logger = Location.getLocation(DeliveryPlantsRules.class);
@SuppressWarnings("unchecked")
public DeliveryPlantResponce getDeliveringPlantForProductsRules(DeliveryPlant plant){
logger.debugT("start:getRullesData");
List<Serializable> ilist = new ArrayList<Serializable>();
plant.setIdentifier(Integer.MAX_VALUE);
ilist.add(plant);
Object object = new Object();
if (ilist.size() != 0) {
List output = EngineInvoker.invokeRuleset("demo.sap.com~test~rules", "DeliveryPlantsRuleset", ilist);
if (output.size() != 0) {
object = output.get(0);
}
} else {
object = "Input has not been set.";
}
logger.debugT("end:getRullesData");
if (object instanceof DeliveryPlant) {
plant = (DeliveryPlant) object;
DeliveryPlantResponce deliveryPlantResponce = new DeliveryPlantResponce();
ResponceDTO responceDTO = null ;
deliveryPlantResponce.setEntered_Plant(plant.getEntered_Plant());
deliveryPlantResponce.setEntered_ProductCode(plant.getEntered_ProductCode());
for (int i = 0; i < plant.getDeliveryPlantList().size(); i++) {
responceDTO = new ResponceDTO();
responceDTO.setDeliveryPlant(plant.getDeliveryPlantList().get(i));
responceDTO.setStartDate(plant.getStartDateList().get(i));
responceDTO.setEndDate(plant.getEndDateList().get(i));
deliveryPlantResponce.addResponceList(responceDTO);
}
return deliveryPlantResponce ;
}
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 |
---|---|
7 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |