RoyZeng / red-piranha

Automatically exported from code.google.com/p/red-piranha
GNU General Public License v2.0
0 stars 0 forks source link

How do I get the excel generated model/POJO into Guvnor so I can write guided rools? #51

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Guvnor wants a Model to use as dependency before it lets me write rules in the 
Guided Editor. As red piranha generates the model pojo at runtime based on 
Ranges and Cells I don't have access. Using the declarative model seems like 
double handling.

Is there some way of getting access to the generated model for use in Guvnor?

Thanks

Mark

Original issue reported on code.google.com by mhemb...@googlemail.com on 14 Apr 2011 at 12:48

GoogleCodeExporter commented 9 years ago
Mark,

Red Piranha Ranges and Cells *are* available at compile time - just look at the 
code in 
http://code.google.com/p/red-piranha/source/browse/trunk/src/net/firstpartners/s
preadsheet/ . You should be able to import this model into Guvnor 
(net.firstpartners.spreadsheet.*) and write rules against it using the guided 
editor.

I've 2 questions / comments about what you are trying to do;

- Guvnor supports guided decision tables; This where the rules (many of them 
similar) are written in a grid like layout. This is a very different scenario 
from holding your data in Excel and applying rules to it (which is what 
Red-Piranha aims to do). Which one do you need?

- Is your question more; 'How do I write the rules in Guvnor, combine them with 
data from excel at runtime, in my own Java Project?' This part of Red-Piranha 
project is a work in progress, but I can give you some tips on how to make it 
work.

Does this help?

Paul

Original comment by paul.m.browne on 16 Apr 2011 at 9:51

GoogleCodeExporter commented 9 years ago
Hi Paul,

In answer to your question it is number 2, 'How do I write the rules in Guvnor, 
combine them with data from excel at runtime, in my own Java Project?' 

Essentially I want to use Guvnor to write the rules against data held in excel 
as well as using excel for the rules. The full round trip. I figured that you 
were still working on the Guvnor integration as you added 
http://code.google.com/p/red-piranha/issues/detail?id=19 to the issues.

I still don't get how I can gain access to the compile time model. I have 
attached the eclipse/jboss developer studio project. Would it be 
CBSExcelData.class that I am looking for to upload to Guvnor? Any tips would be 
most appreciated. 

Thanks for your help Paul

Mark

Original comment by mhemb...@googlemail.com on 18 Apr 2011 at 1:30

Attachments:

GoogleCodeExporter commented 9 years ago
Mark

Thanks for your questions; I'm not sure if what you want is how to load the 
packaged Red-Piranha code into Guvnor, or how to use the rules package as 
created by Guvnor in Red-Piranha code (against the data from excel) - so I will 
answer both questions.

- If the problem is loading the red-piranha model into Guvnor, then create the 
jar using the instructions at 
http://code.google.com/p/red-piranha/wiki/DeveloperGettingStarted , then load 
into Guvnor using the instructions from the Drools site (section 1.4.4 'The 
fact model (object model)') - 
http://downloads.jboss.com/drools/docs/5.1.1.34858.FINAL/drools-guvnor/html/ch01
.html#d0e73

- If the problem is how do I use the output of Guvnor as my rules in 
Red-Piranha, the then the answer is that you will need to modify the 
Red-Piranha source. Start with the Developer Getting started section of the 
wiki to setup your project 
(http://code.google.com/p/red-piranha/wiki/DeveloperGettingStarted), then 
modify the Red-Piranha source code to pull the rules from Guvnor instead of any 
pre-compiled rules held online - see Drools Documentation 1.4.8.1 ' The 
Knowledge Agent' for the code you need to implement this.

For the 2nd item, the best place to modify is likely to be RuleRunner.java, but 
work your way through the code from the service() method in the Servlet so that 
you understand what is going on. 
http://code.google.com/p/red-piranha/source/browse/trunk/src/net/firstpartners/u
i/Rp2Servlet.java

For your example , you may want to add a main() method to run Rp2Servlet 
locally - I tend to write Junit tests for this purpose (as it also helps code 
quality).

Either way, I would be very interested in any comments on the documentation / 
additional doc/ changes you need to make to the source code to achieve what you 
want!

Paul

Original comment by paul.m.browne on 18 Apr 2011 at 8:31

GoogleCodeExporter commented 9 years ago
Hi Paul,

I am using the book code and built the jar in "eclipse/jboss developer studio" 
then deployed via the model pojo upload into guvnor on the JBoss BRMS Server. 
This works but I don't get access to the individual field names only 
range_cellNumber. It would be nice to somehow get the pojo to include the excel 
column headings as the getters and setters in the pojo like I would get hand 
coding the pojo.

When I use the guided rule editor in Guvnor and run the rule in eclipse I get 
the below error. Does red-prianha support .brl files?

Generated DRL from BRL file
rule "test04"
    dialect "mvel"
    when
        Cell( cellName == "_13003964480709038595371_37" )
    then
        Cell fact0 = new Cell();
        fact0.setModified( true );
        insert(fact0 );
end

_13013179038300093148245_26: cellName:_13013179038300093148245_26 value:Crossan 
comment:null modified:false
_13013179038300093148245_56: cellName:_13013179038300093148245_56 value:N/A 
comment:null modified:false
_13013179038300093148245_49: cellName:_13013179038300093148245_49 value:N/A 
comment:null modified:false
_13013179038300093148245_6: cellName:_13013179038300093148245_6 value:SU 
comment:null modified:false
_13013179038300093148245_29: cellName:_13013179038300093148245_29 
value:Meadowbank Avenue comment:null modified:false
_13013179038300093148245_28: cellName:_13013179038300093148245_28 value:24 
comment:null modified:false
_13013179038300093148245_55: cellName:_13013179038300093148245_55 value:N/A 
comment:null modified:false

765  [main] INFO  com.bskyb.srsnorth.drools.RuleRunner  - Loading file: 
test04.brl
765  [main] INFO  com.bskyb.srsnorth.drools.RuleRunner  - found rule 
file:test04.brl
Exception in thread "main" java.lang.NullPointerException
    at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:483)
    at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:446)
    at org.drools.reteoo.ReteooRuleBase.addPackage(ReteooRuleBase.java:453)
    at com.bskyb.srsnorth.drools.RuleRunner.loadRules(RuleRunner.java:60)
    at com.bskyb.srsnorth.drools.RuleRunner.runStatelessRules(RuleRunner.java:169)
    at com.bskyb.srsnorth.cha8.CBSExcelData.main(CBSExcelData.java:83)

Original comment by mhemb...@googlemail.com on 20 Apr 2011 at 10:31