[rules-users] Steps for uploading model jar and decision table in guvnor

Esteban Aliverti esteban.aliverti at gmail.com
Sat Aug 21 11:38:14 EDT 2010


The kagent error is because you probably don't have the jar with your model
in kagent's classpath and you are using the DRL version of your package. The
agent will try to compile your DRL, but if you don't have your pojos in the
classpath, it will fail. You could use the compiled version of your package
instead of the DRL.

If your model are Java Pojos, then you only need to do this in order to
insert them to a ksession:

AmountPojo ap = new AmountPojo();

ksession.insert(ap);

And that's it. The kbase.getFactType() approach is used only when you
declare you model inside the drl (as far as i know).

Best,


XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


2010/8/21 Swapnil Sawant <Swapnil.Sawant at lntinfotech.com>

>
> Hi,
>
> PFA the model jar and decision table that I have created .
>
> myTest.jar contains my model class 'AmountPojo' and currently I have
> written only one PF rule using this 'AmountPojo' class
>
> I have done following things successfully on guvnor GUI :
>
>        - uploading of model jar in a package(named Test)
>        - uploading decision table xls in same package
>        - 'save and validate configuration' and 'building package'after
> above steps
>        - Creating test scenario for testing that my rule is working fine
>
>
> Now, I wish to utilize this package in my application through
> changeset.xml. For this, I wrote something like :
>
>      <change-set xmlns='http://drools.org/drools-5.0/change-set'
>                  xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
>                   xs:schemaLocation='
> http://drools.org/drools-5.0/change-set drools-change-set-5.0.xsd' >
>                      <add>
>            <resource source='
> https://ofbiz.apache.org:8443/drools-guvnor/org.drools.guvnor.Guvnor/package/Test/LATEST.drl'
>  type='DRL' />
>                      </add>
>      </change-set>
>
> Also, in my code I have created knowledge agent like dis :
>
>
>            kagent = KnowledgeAgentFactory.newKnowledgeAgent( "MyRuleAgent"
> );
>            String changesetUrl =
> "file:"+currentWorkingDirectory+"/framework/drools/config/changeset.xml";
>            kagent.applyChangeSet( ResourceFactory.newUrlResource(
> changesetUrl ) );
>
>
> Using this 'kagent' I have created knowledge base like dis :
>
>            if(kbase==null){
>                 kbase = kagent.getKnowledgeBase();
>            }
>
>
> When kagent.applychaneset line executes, it throws following error :
>
>
>            [Error: Failed to compile: 4 compilation error(s):
>  - (1,9) unqualified type in strict mode for: amtEntity
>  - (1,9) unqualified type in strict mode for: amtEntity
>  - (1,15) unqualified type in strict mode for: basic
>  - (1,40) unable to resolve method using strict-mode:
> java.lang.Object.setHra(java.lang.Object)]
> [Near : {... Unknown ....}]
>             ^
> [Line: 1, Column: 0]
>        at
> org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:78)
>        at
> org.drools.base.mvel.MVELCompilationUnit.compile(MVELCompilationUnit.java:365)
>        at
> org.drools.base.mvel.MVELCompilationUnit.getCompiledExpression(MVELCompilationUnit.java:288)
>        at
> org.drools.base.mvel.MVELConsequence.compile(MVELConsequence.java:49)
>        at
> org.drools.rule.builder.dialect.mvel.MVELConsequenceBuilder.build(MVELConsequenceBuilder.java:107)
>        at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:86)
>        at
> org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:1168)
>        at
> org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:654)
>        at
> org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:291)
>        at
> org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:489)
>        at
> org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:25)
>        at
> org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:387)
>        at
> org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:121)
>        at
> org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:110)
>        at
> org.ofbiz.drools.event.drool.RuleIntegrate.createKnowledgeBase(RuleIntegrate.java:46)
>        at
> org.ofbiz.drools.event.drool.RuleIntegrate.createWorkingMemory(RuleIntegrate.java:29)
>        at org.ofbiz.payroll.DroolsRule.callRuleJava(DroolsRule.java:42)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:597)
>        at
> org.ofbiz.service.engine.StandardJavaEngine.serviceInvoker(StandardJavaEngine.java:100)
>        at
> org.ofbiz.service.engine.StandardJavaEngine.runSync(StandardJavaEngine.java:57)
>        at
> org.ofbiz.service.ModelServiceReader$GenericInvokerImpl.runSync(ModelServiceReader.java:761)
>        at
> _$gen.file_58$.D_58$.Swapnil_95$Data.ofbiz_95$trunk_95$06_95$22.applications.payroll.servicedef.services_46$xml_3
>        at
> org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:399)
>        at
> org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:226)
>        at
> org.ofbiz.service.GenericDispatcher.runSync(GenericDispatcher.java:165)
>        at
> org.ofbiz.webapp.event.ServiceEventHandler.invoke(ServiceEventHandler.java:336)
>        at
> org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:633)
>        at
> org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:379)
>        at
> org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:224)
>        at
> org.ofbiz.webapp.control.ControlServlet.doPost(ControlServlet.java:87)
>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>        at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>        at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>        at
> org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:271)
>        at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>        at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>        at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
>        at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
>        at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
>        at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>        at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>        at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
>        at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
>        at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
>        at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
>        at
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
>        at java.lang.Thread.run(Thread.java:619)
> [2010:08:233 16:08:734:debug] KnowledgeAgent building resource=[UrlResource
> path='https://ofbiz.apache.org:8443/drools-guvno
> [2010:08:233 16:08:359:debug] KnowledgeAgent has KnowledgeBuilder errors
>  object=Unable to resolve ObjectType 'AmountPojo' :
> Unable to resolve ObjectType 'AmountPojo' : [Rule name='HRA rule']
> Unable to build expression for 'consequence': Failed to compile: 4
> compilation error(s):
>  - (1,9) unqualified type in strict mode for: amtEntity
>  - (1,9) unqualified type in strict mode for: amtEntity
>  - (1,15) unqualified type in strict mode for: basic
>  - (1,40) unable to resolve method using strict-mode:
> java.lang.Object.setHra(java.lang.Object) '       amtEntity.setHra( am
> ' : [Rule name='HRA rule']
> Error importing : 'com.sample.AmountPojo'Error importing :
> 'com.sample.PFRules'Error importing : 'com.sample.SpreadsheetComp
>        Test/Rule_PF_Rules_11_0.java (2:22) : Only a type can be imported.
> com.sample.SpreadsheetCompiler resolves to a pack
>        Test/Rule_PF_Rules_11_0.java (2:60) : Only a type can be imported.
> com.sample.AmountPojo resolves to a package
>        Test/Rule_PF_Rules_11_0.java (2:89) : Only a type can be imported.
> com.sample.PFRules resolves to a package
>        Test/Rule_PF_Rules_11_0.java (7:371) : a cannot be resolved
>        Test/Rule_PF_Rules_11_0.java (7:379) : a cannot be resolved
>        Test/Rule_PF_Rules_11_0.java (8:460) : a cannot be resolved
>
>
>
> It seems that it is not  able to recognize 'AmountPojo' class.thereby
> considering it as 'Object' type and applying setHra() on it.
>
> Any idea why this is occuring ? How to communicate about 'AmountPojo' Type
> in code ?
>
>
> Also,
>
> After this, I wanted to know the steps for 'inserting fact type object for
> AmountPojo' in the session created.
>
> For this I read in docs  that use following lines of code :
>
>
>                        // Retrieve the generated fact type
>                               FactType cheeseFact = ruleBase.getFactType(
> "org.drools.generatedbeans.Cheese" );
>
>                       // Create a new Fact instance
>                               Object cheese = cheeseFact.newInstance();
>
>                               cheeseFact.set( cheese,
>                                "type",
>                          "stilton" );
>
>
> But, I didnt find any method like KnowledgeBase.getFactType(String
> fullyQualifiedfactTypePath) . There is only one
> KnowledgeBase.getFactType(String pckname,String factTypeName) method in it
>
>
> Please let me the know the right way of achieving this .
>
>
>
> Thanks,
>
> Swapnil Sawant
>
>
>
>
>
>
>
> This Email may contain confidential or privileged information for the
> intended recipient (s) If you are not the intended recipient, please do not
> use or disseminate the information, notify the sender and delete it from
> your system.
>
> ______________________________________________________________________
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100821/a556bf59/attachment.html 


More information about the rules-users mailing list