Using Internal data (data in excel) along with passing data from Java to the openrules engine

76 views
Skip to first unread message

indranil nanda

unread,
Apr 17, 2017, 1:11:54 PM4/17/17
to OpenRules
Hi Team,

Is there any way to use internal data (data in excel) along with passing data from Java to the openrules engine.
Looks like in UserManual Page 34 there is a reference for this. But I am unable to locate standard example "DecisionLoan".

Please see the example below.
So my issue is, if business user next day want to add new "Eligibility Z" (in a new DT), I do not want to change in Java side as from Java side the concern is only with "Recommended Prevent Strategies" which is just a string (as of now).
And business user can add new item under PreventStrategy in glossary and Datatype and the java code should not be impacted.



DT DeciosnForRecommendation1

  If

If

Conclusion

Var1

Var2

Eligibility for X

A

B

Eligible for X1, X2

DT DeciosnForRecommendation2

If

If

Conclusion

Var3

Var4

Eligibility for Y

C

D

Eligible for Y1, Y2

DecisionTable CustomerPreventStrategyDecisionTable

 

Action

 

Recommended Prevent Strategies

 

::= ${Eligibility for X} + "__ "+$Eligibility for Y}

 

 

 

Glossary glossary

Variable

Business Concept

Attribute

Var1

Customer

var1

Var2

var2

Var3

var3

Var4

var4

Var5

var5

Var6

var6

Eligibility for X

PreventStrategy

eligibilityForX

Eligibility for Y

eligibilityForY

Recommended Prevent Strategies

Response

recommendedPreventStrategies

Datatype PreventStrategy

String

eligibilityForX

String

eligibilityForY

Data PreventStrategy preventStrategy

eligibilityForX

eligibilityForY

Eligibility for X

Eligibility for Y

?

?

 

DecisionObject decisionObjects

Business Concept

Business Object

Customer

:=  decision.get("Customer")

Response

:=  decision.get("PreventResponse")

PreventStrategy

:= preventStrategy[0]

 

 

 

 

 In Java side:

                Response preventResponse = new Response();

decision.put("Customer", customer);

decision.put("PreventResponse", preventResponse);

decision.execute();


It is deployed using springBoot.

Now the scenario is

1st call: Customer attributes does not satisfy any Decision Table  - it is returning-- ?__? which is correct.

2nd call: Customer attribute satisfy 1st DT, response: Eligible for X1, X2__? which is correct.

3rd call: Customer attributes does not satisfy any Decision Table  - it is returning-- Eligible for X1, X2__? which is wrong.

So for all consecutive calls it is returning same.


Another scenario:

1st call: Customer attribute satisfy 1st DT, response: Eligible for X1, X2__? which is correct.

2nd call: Customer attributes does not satisfy any Decision Table  - it is returning-- Eligible for X1, X2__? which is wrong.



I tried removing table  Data PreventStrategy and passing preventStrategy (instead of preventStrategy[0]) in BusinessObject table but then getting


Caused by: org.openl.syntax.SyntaxErrorException: Error: Field not found: preventStrategy

Invalid Code Fragment:

=========================================

 preventStrategy

 ^^^^^^^^^^^^^^^



It will be really helpful if you can point the mistake.


Regards

Indranil

OpenRules Support

unread,
Apr 17, 2017, 1:29:51 PM4/17/17
to OpenRules
The example was renamed to DecisionLoanPreQualification - see "openrules.dmn". 

Excel table of types Datatype and Data should be used only for testing purposes and never in a production environment. The life-cycle of Data objects defined in Excel should start and end with ONE decision's run. When you switch from a test-mode to a production, the Glossary table and all decision tables will stay the same, but you will change the table "decisionObjects" to feed your already tested model with real data coming as Java objects. You may read the chapter 3 of the new book  about an integration with IT. So, if you build a real-world application, you probably keep your actual data somewhere in a data warehouse and want to pass it to an OpenRules-based decision service as Java objects. The service will make changes in these objects in accordance with the business logic presented in Excel, and will save the results back to the objects. 

indranil nanda

unread,
Apr 19, 2017, 2:11:12 PM4/19/17
to OpenRules
Hi,

I understand the data we will get in real time. But that is for "deciding" variable. In this case Customer data.
But my question was what about the interim data that decision engine might use.
Cause Prevent Strategy should be used in Excel only.
From Java side we will get only the concatenated string.
From Java side I am not concerned about if business user add one new strategy or remove one.

OpenRules Support

unread,
Apr 19, 2017, 2:32:00 PM4/19/17
to OpenRules
Indranil,

You are making a valid point, and you actually can define and use intermediate variables in Excel. It will work fine in a single user environment. However, if you want to deploy your rule service at a server and give allow multiple concurrent users to access this service, you will have two choices:

1) use the same instance of OpenRulesEngine to serve multiple concurrent requests
2) use different instances of OpenRulesEngine for different concurrent requests.

In the first mode you cannot use the intermediate decision variables defined in Excel Data tables as they all will be shared by concurrent requests and it could lead to a mess in your production environment. But you can use them in the second mode. Obviously, the first mode will work much faster to compare with the second one. So, it is your decision where to keep your intermediate variables: in Java or in Excel. Usually, Excel is sufficient for a test mode. However, we recommend our customers after a decision model is tested to move all intermediate variables into a simple Java bean. This solution will always be thread-safe even if today you don't plan to use your service in a multi-threaded environment.

Support 

indranil nanda

unread,
Apr 19, 2017, 3:25:50 PM4/19/17
to OpenRules
Great. I understand now.
However I have one doubt regarding different instances of OpenRulesEngine.
My understanding is when we are instantiating Decision 

Decision decision = new Decision(decisionName,fileName);

It will always return same instance unless main Decision.xls file is changed (last saved timestamp changed).
So to implement your next point
               "2) use different instances of OpenRulesEngine for different concurrent requests."
I have to do decision.clear() after decision.execute()

Please correct me if I am wrong.

Thanks.

OpenRules Support

unread,
Apr 19, 2017, 3:38:45 PM4/19/17
to OpenRules
To implement 2) you may re-create a new decision for each http-request by using 

Decision decision = new Decision(decisionName,fileName);
...
decision.execute();

But keep in mind the this is an expensive operation as all related rules will be downloaded from excel and interpreted again.

Contrary, to implement 1) you create an instance"engine" of OpenRulesEngine only once when you start your server:

OpenRulesEngine engine = new OpenRulesEngine(fileName);

Then for every http-request you may call a very quick Decision's constructor 

Decision decision = new Decision(decisionName,engine);

Hope it helps to clarify your questions and available options.

Support

indranil nanda

unread,
Apr 19, 2017, 3:55:14 PM4/19/17
to OpenRules
Thanks again.
But in this case will I loose the functionality of changing decisions on the fly, (without restarting the server)

I understand it may not be a good idea to change decisions on the fly in Prod environment.

Regards
Indranil

indranil nanda

unread,
Apr 19, 2017, 3:58:14 PM4/19/17
to OpenRules
Also as per:
only one Decision instance is created (Singleton pattern)
Not one for each request.
Got little confused here.

Thanks
Indranil

OpenRules Support

unread,
Apr 19, 2017, 4:48:17 PM4/19/17
to OpenRules
If you choose the mode 2), you will create a new instance of OpenRulesEngine and download the latest rules for every request, so you will get "hot deployment" automatically. But if you have too many rules, the mode 2) can become too expensive. So, we strongly recommend using the first mode.

indranil nanda

unread,
Apr 20, 2017, 4:21:50 PM4/20/17
to OpenRules
Thanks for your help. Really appreciate this.

Just to iterate to make my understanding clear:

In PROD env where we do not need "hot deployment" of rules we can use one Decision instance (singleton) in the lifetime of the application as mentioned in 

And for each web service request just pass the new Request(Customer) and new Response object to the Decision instance. Page-9
And the Decision engine will take care for concurrent requuets.

OpenRules Support

unread,
Apr 20, 2017, 4:25:38 PM4/20/17
to OpenRules
Correct!
Reply all
Reply to author
Forward
0 new messages