Help jump start parameter passing with decision tables

已查看 69 次
跳至第一个未读帖子

Sandy

未读,
2014年11月13日 00:56:042014/11/13
收件人 open...@googlegroups.com
Hello, 

I need some help with modeling a use case where I need to pass and receive back parameters to methods in a java application.

I am a newbie to this and this is use case I came up with based on my 1 hour of reading. Apologizing for my ignorance. Appreciate the help. 

Also attached the below in a word document for reference.

All my (rule) methods are in java util class (refer to Util class below)

From the decision table – DefinePromotionStatus, DefineTopLevelRecommendation – I need to pass an attribute of customer object – customer.getJobAttrs() and DefineResult – I need to pass customer and response object 

How do I specify this in my decision table.

Also, please glance thro my entire test case and let me know if you see any obvious mistakes. 


Below is my sample use case:

Class Customer {

            String name;

            String id;

            String dept;

            Map<String, String> jobAttrs;

}

 Class Response {

            Boolean isEligible;

            String result;

}

 Class Controller{

Customer c = new Customer();

c.setName(“RJ Drobick”);

c.setId(86182618);

c.setDept(“Executive”);

Map<String, String> attrs = new HashMap<String, String>();

attrs.put(“Business_awards”, “B102,B6772”);

attrs.put(“Papers_submitted”, “P898,P6151”);

attrs.put(“Recommendations”, “3”);

c.setJobsAttrs(attrs);

 

Response resp = new Response();


String filename = “file:rules/main/CustomerRules.xls”;

Decision decision = new Decision(“DetermineCustomerPromotionEligibility”, filename);

decision.put(“Customer”, c);

decision.put(“Response”, resp); 

decision.execute();

System.out.println(decision.getOutput());

}

Class Utils {

     static boolean isEligibleForPromotion(Map<String, String> attrs){

if (...)

              return true;

}

return false;

}

static Map<String, String> addJobAttribute(Map<String, String> attrMap, String attrName, String attrValue){

      attrMap.put(attrName, attrValue);

return attrMap;

}

static String getCongratulatoryMessage(Response resp, Cutomer customer){

if (resp.isEligible()) {

return “Congratulations ” +  customer.getName() + “!! You are promoted.”;

} else {

      return “Sorry ” + customer.getName() + “ Better luck next year”;

}

}

}

 

DecisionObject decisionObjects

Business Concept

Business Object

Customer

:= decision.get(“c”);

Response

:= decision.get(“resp”);


Decision DetermineCustomerPromotionEligibility

Decisions

Execute Decision Tables

Define Promotion Eligibility

DefinePromotionStatus

Define Special Recommendation

DefineTopLevelRecommendation

Define Result

DefineResult

Define Decision Output

:= decision.setOutput(${Congratulatory Message});


Decision Tables

DecisionTable DefinePromotionStatus

Conclusion

Eligible for Promotion

Is

::=Utils.isEligibleForPromotion(customer.getJobAttrs())


 

DecisionTable DefineTopLevelRecommendation

Condition

Conclusion

Name

Job Attributes

‘==’

“RJ Drobick”

::=Utils.addJobAttribute(customer.getJobAttrs(), “isSpecialRecommendation”, “true”)


 

DecisionTable DefineResult

Conclusion

Congratulatory Message

Is

::=Utils. getCongratulatoryMessage(response, customer)

 

Glossary

Variable

Business Concept

Attribute

Name

 

Customer

 

Name

Id

Id

Department

Dept

Job Attributes

jobAttrs

Eligible for Promotion

 

Response

isEligible

Congratulatory Message

Result

 

 

Use case.docx

OpenRules Support

未读,
2014年11月13日 09:14:122014/11/13
收件人 open...@googlegroups.com
Sandy,

One thing from your request is obvious: instead of hiding your promotion eligibility logic in the Java class Utils your need to move it directly to the decision tables. As you provided a lot of ready to go pieces, we intend to convert them to a working OpenRules project that will address your questions. We will send it to you ASAP.

Support

<w:LsdException Locked="false" Priority="65" SemiHidden="false"

...

OpenRules Support

未读,
2014年11月13日 18:09:252014/11/13
收件人 open...@googlegroups.com
Hi Sandy,

We've prepared a working decision project based on your data unzip it into a folder on the same level where you keep "openrules.config". Double-click on run.bat.
See rules at the attached xls-files. Here are the execution results:

Decision Run has been initialized
Decision DetermineCustomerPromotionEligibility: Define Promotion Status
Conclusion: Eligible for Promotion Is false
Conclusion: Eligible for Promotion Is true
Conclusion: Eligible for Promotion Is true
Conclusion: Eligible for Promotion Is true
Decision DetermineCustomerPromotionEligibility: Define Top Level Recommendation
Conclusion: Congratulatory Message Is Congratulations RJ Drobick!! You are promoted.
Decision DetermineCustomerPromotionEligibility: Define Decision Output
Decision has been finalized
Decision: Congratulations RJ Drobick!! You are promoted.

Hope it is a good beginning for your actual project.
Good luck,

Support
DecisionPromotionEligibility.zip
Decision.xls
Rules.xls
Glossary.xls

Sandy

未读,
2014年11月13日 19:11:092014/11/13
收件人 open...@googlegroups.com

Thank you for the quick response.

But our real world use case cannot have business logic embedded in excel.  I need them to be in java.
Please let me know if there is a way to pass parameters from decision tables to java methods and also I am seeing that I cannot use only String return type. In case we cannot pass parameters then it may be a show stopper for us.

Thanks,
Sandy

OpenRules Support

未读,
2014年11月14日 12:03:182014/11/14
收件人 open...@googlegroups.com
It is really your choice how to distribute business logic between Excel-based decision tables and your Java code. OpenRules allows you to pass any types of objects/parameters by putting them into the decision, e.g.

    decision.put("Customer",customer);

The glossary maps all attributes of your Java objects with decision variables used in the decision tables. When your decision table modifies the variables the proper attributes in your Java objects will be modified as well. So, you are not limited to any return type. You always may call in the Excel snippet

    := decision.setOutput($O{Response}) 

or any other object. Normally our user prefer to modify attributes within objects they pas as parameters.

Support

Sandy

未读,
2014年11月14日 13:16:302014/11/14
收件人 open...@googlegroups.com
 Thank you for the quick response again. I will try this out.

-Sandy
回复全部
回复作者
转发
0 个新帖子