Using DynaBean for java classes

76 views
Skip to first unread message

Anuj Bhatnagar

unread,
Jan 17, 2016, 11:53:07 AM1/17/16
to OpenRules
Is it possible to use DynaBean for request and response object?

For eg - 

Decision decision = new Decision(

"Main",

"file:/Users/anuj/Work/Worxogo/Workspace/BeatPlan/rules/main/DecisionFTRAvailability.xls");

// SCE sce = new SCE();

// sce.setFtrAvailability("Y");

DynaProperty ftrAvailability = new DynaProperty("ftrAvailability",

String.class);

DynaProperty sceCode = new DynaProperty("sceCode", Integer.class);


BasicDynaClass sceClass = new BasicDynaClass("SCE", null,

new DynaProperty[] { ftrAvailability, sceCode });

//Points points = new Points();

DynaBean db = sceClass.newInstance();

db.set("ftrAvailability", "Y");

decision.put("sce", db);


DynaProperty ftrAvailabilityPoints = new DynaProperty("ftrAvailabilityPoints", Double.class);


BasicDynaClass points = new BasicDynaClass("Points", null,

new DynaProperty[] { ftrAvailabilityPoints});


decision.put("points", points.newInstance());

decision.execute();


this code throws various error. I debugged the code but I dont think open rules takes care of dyna bean in assigning the values.

OpenRules Support

unread,
Jan 17, 2016, 2:17:40 PM1/17/16
to OpenRules

Anuj,

 

We will see how to add direct support for DynaBean. Meanwhile you may simply convert our DynaBean instances to our DynamicObjects instances before passing them to your Decision object. See the attached example that shows how it can be done.  

 

OpenRules Support

MainDynaClassConverted.java

Anuj Bhatnagar

unread,
Jan 19, 2016, 4:45:01 AM1/19/16
to OpenRules
Thanks for the prompt reply.

Anuj Bhatnagar

unread,
Jan 19, 2016, 4:56:10 AM1/19/16
to OpenRules
Is it possible to know the data types of fields before executing main decision?
I have observed that type field of GlossaryElement is not set hence I can not create the appropriate dyna property with a given type.

As soon as Decision object is initalized by providing the xls file path, and before providing the request object, is it possible to get access to data objects from decision?

OpenRules Support

unread,
Jan 19, 2016, 10:42:00 AM1/19/16
to OpenRules
OpenRules allows you to change attribute types between different runs of the same engine/decision. That's why we do not have "type" inside the glossary. Actual types become known during the engine runs.
This fact should not limit you as you know your DynaBean properties types before you run the engine unless we misunderstood your intentions.

Anuj Bhatnagar

unread,
Jan 20, 2016, 1:36:26 AM1/20/16
to OpenRules
Thanks for the reply and sorry for not putting my question appropriately.
Here is how we are trying to use OpenRules engine - 

1- BAs write decision files and provide it to us with the main function always being named "Main".
2- The framework I am trying to come up with accepts the request parameter  including the xls file name over http (hence param values are retrieved as String data type.).
3- Decision object is created by passing methodName and xlsFilePath and I get all the fields of respective Business Concepts through Glossary object.
4- I create DynaBean (Which eventually gets converted to DynamicObject) from Glossary and also try to set values to them which ever are passed from httpRequest to make a request/reponse object which can eventually be put into Decision object.. Here is where I need to know the datatype of the fields. If one field is defined as Date, Double or Int format in Datatype Table for the respective Business Concept, setting it to String would throw an exception at the decision execution.

Please refer the attached xls.
e.g. 

1- I create two dyna beans from Glossary representing SCE & Points. I get request param loginDayOfMonth="2" (httprequest)
and set it into SCE dynaBean. 
2- Convert the dyna beans to dynamic object and put it into decision object.
3- Execute the decision but it throws an exception - 

ERROR in Glossary trying to compare a value of <Login day of month> with <[1;9]> using oper Within: property=2 type=java.lang.String value=[1;9]


I hope I have provided a better explanation of the problem I am facing right now.


Workaround I have used - 


Looking for Datatype tables in xls and trying to find the data type of business concepts property. Which ideally is not the right way and I would like to avoid doing this.
DecisionWeekofmonth.xls

support

unread,
Jan 20, 2016, 12:29:10 PM1/20/16
to OpenRules
Hi Anuj,

You wrote: "I create DynaBean (Which eventually gets converted to DynamicObject) from Glossary and also try to set values to them which ever are passed from httpRequest to make a request/reponse object which can eventually be put into Decision object.. Here is where I need to know the datatype of the fields. If one field is defined as Date, Double or Int format in Datatype Table for the respective Business Concept, setting it to String would throw an exception at the decision execution."

We believe OpenRules provides a perfect solution for you avoiding the use of DynaBeans. Please take a look at the User Manual's section "Generating Java Interfaces for Excel-based Decision Models" page 132. We recommend you to use Business Maps described at the page 136. The complete examples is included as the sample project "DecisionPatientTherapyWithBusinessMaps".

Let us know if you still have issues.

Support

Anuj Bhatnagar

unread,
Jan 28, 2016, 7:45:36 AM1/28/16
to OpenRules
Thanks for the response. I have used the solution suggested by you. Generating java source and compiling it on the fly. 
Is there any workaround for - 

  1. Implementation Restriction. Make sure that the very first attribute in a Datatype table has type String or your own type but not a basic Java type like int. 

OpenRules Support

unread,
Jan 28, 2016, 1:06:15 PM1/28/16
to open...@googlegroups.com

Sorry, this is an implementation restriction but it never creates any issues – just add the first field “String id” to your datatype and yo do not have to use it.

 

OpenRules Support

 

From: open...@googlegroups.com [mailto:open...@googlegroups.com] On Behalf Of Anuj Bhatnagar
Sent: Thursday, January 28, 2016 7:46 AM
To: OpenRules
Subject: [openrules:418] Re: Using DynaBean for java classes

 

Thanks for the response. I have used the solution suggested by you. Generating java source and compiling it on the fly. 
Is there any workaround for - 

 

1.      Implementation Restriction. Make sure that the very first attribute in a Datatype table has type String or your own type but not a basic Java type like int. 

--
You received this message because you are subscribed to the Google Groups "OpenRules" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrules+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages