[rules-users] Issue with From Clause - Class Cast Error
Hi All, I am having a very strange issue with my knowledge base... I have the following Rule: ... rule root_host no-loop true ruleflow-group 'initialize-appliance-definitions' when $app:ApplianceType ( type == ApplianceTypeIdentifier.APPLIANCE_ROOT ); not( ApplianceTypeObject() from $app.getObjectTypes()); then //Do something end; ... And the ApplianceType class is defined as: ... public class ApplianceType { private ApplianceTypeIdentifier type; private ListApplianceTypeObject objectTypes; public ApplianceType(ApplianceTypeIdentifier type, ListApplianceTypeObject initialObjectTypes) { this.type = type; if(initialObjectTypes == null) this.objectTypes = new ArrayListApplianceTypeObject(); else this.objectTypes = initialObjectTypes; } public ApplianceType(ApplianceTypeIdentifier type) { this(type, null); } public ApplianceTypeIdentifier getType() { return type; } public ListApplianceTypeObject getObjectTypes() { return objectTypes; } } When attempting to fireAllRules() I receive the following error: ... Caused by: java.lang.ClassCastException: org.drools.reteoo.FromNode incompatible with org.drools.reteoo.BetaNode at org.drools.reteoo.ReteooBuilder.resetMasks(ReteooBuilder.java:303) at org.drools.reteoo.ReteooBuilder.removeRule(ReteooBuilder.java:267) at org.drools.reteoo.ReteooRuleBase.removeRule(ReteooRuleBase.java:459) at org.drools.common.AbstractRuleBase.removeRule(AbstractRuleBase.java:1107) at org.drools.common.AbstractRuleBase.mergePackage(AbstractRuleBase.java:851) at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:610) at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:472) at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:150) at com.q1labs.frameworks.drools.DroolsEngine.getKnowledgeBase(DroolsEngine.java:139) at com.q1labs.frameworks.drools.DroolsEngine.onInit(DroolsEngine.java:50) at com.q1labs.frameworks.naming.FrameworksNaming.initializeNewComponent(FrameworksNaming.java:951) ... 3 more Any thoughts? I have been using from clauses just like this throughout my project, and have had no issues with it to this point (even those which did not use generics). -- View this message in context: http://drools.46999.n3.nabble.com/Issue-with-From-Clause-Class-Cast-Error-tp4019846.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Issue with From Clause - Class Cast Error
Thanks for the fast response! I'll attempt to post as much as I can, splicing out any case specific info. The Java code surrounding my invocation is as follows: = //Get a list of all knowledgebase resources ListFile kbList = config.getCompleteKBList(); //Note that this is a simply a collection of absolute file paths containing DRL and RF files if(kbList == null) throw new FrameworksException(Failed to get list of knowledgebase resources. Configuration returned null); //Add all of the resources we found for(File file : kbList) { if(file == null) continue; if(log.isDebugEnabled()) log.debug(Adding resource file: + file.getAbsolutePath()); if(file.getName().endsWith(KB_FILE_EXT)) kbBuilder.add(ResourceFactory.newFileResource(file), ResourceType.DRL); else if(file.getName().endsWith(RF_FILE_EXT)) kbBuilder.add(ResourceFactory.newFileResource(file), ResourceType.DRF); else throw new FrameworksException(Found invalid file in our knowledgebase list! It was: \ + file.getAbsolutePath() + \. This extension is not supported); // Check the builder for errors if (kbBuilder.hasErrors()) { throw new FrameworksException( + file.getAbsolutePath() + : Unable to compile knowledge base: + kbBuilder.getErrors().toString()); } } KnowledgeBase kb = kbBuilder.newKnowledgeBase(); kb.addKnowledgePackages(kbBuilder.getKnowledgePackages()); = The above line is the point at which the error occurs. I am using several other rule files, but I have removed them while I am debugging this issue. I am left with simply this rule file: = package removed.kb.appliances import removed.ApplianceType; import removed.ApplianceTypeObject; import removed.ApplianceTypeObjectHost; import removed.ApplianceTypeIdentifier; import java.util.List; dialect java; rule root_appliance ruleflow-group 'initialize-appliance-definitions' when not ( ApplianceType ( type == ApplianceTypeIdentifier.APPLIANCE_ROOT ); ); then ApplianceType appliance = new ApplianceType(ApplianceTypeIdentifier.APPLIANCE_ROOT, null); insert(appliance); end; rule root_host no-loop true ruleflow-group 'initialize-appliance-definitions' when $app:ApplianceType ( type == ApplianceTypeIdentifier.APPLIANCE_ROOT ); not( ApplianceTypeObject() from $app.getObjectTypes()); then //Do something end; == If there is any more information I can provide please let me know. I believe that is everything. -- View this message in context: http://drools.46999.n3.nabble.com/Issue-with-From-Clause-Class-Cast-Error-tp4019846p4019848.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Issue with From Clause - Class Cast Error
I am using 5.4.0 Final Downloaded about a month ago. From drools-core-5.4.0.Final.jar: Specification-Title: Drools :: Core Specification-Version: 5.4.0.Final -- View this message in context: http://drools.46999.n3.nabble.com/Issue-with-From-Clause-Class-Cast-Error-tp4019846p4019850.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Issue with From Clause - Class Cast Error
Great! Thanks so much Davide (and laune). Cheers, Taylor -- View this message in context: http://drools.46999.n3.nabble.com/Issue-with-From-Clause-Class-Cast-Error-tp4019846p4019854.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to read ruleflow file?
Hi there, This is likely irrelevant to you, but I run things using the Drools framework (not Guvnor). In case it is helpful, here is my simple setup: KnowledgeBuilder kbBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); File file = new File(/test/myFile.rf); kbBuilder.add(ResourceFactory.newFileResource(file), ResourceType.DRF); //Insert your KB files here as ResourceType.DRL if (kbBuilder.hasErrors()) e.printStackTrace(); KnowledgeBase kb = kbBuilder.newKnowledgeBase(); kb.addKnowledgePackages(kbBuilder.getKnowledgePackages()); StatefulKnowledgeSession session = kb.newStatefulKnowledgeSession(); session.startProcess(myFlow); session.fireAllRules(); Where of course myFlow is the name of my flow, and the file is the full path to your ruleflow. -- View this message in context: http://drools.46999.n3.nabble.com/How-to-read-ruleflow-file-tp4019812p4019833.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Eclipse - Drools Plugin - Compilation Errors
More details... The error is as you would expect: Description ResourcePathLocationType The method getDeploymentTemplate() is undefined for the type Rule_init_282bd9bb0e30465c8efc3f0b1b9e23f2 init.drl/path to file removed intentionally line 11 Drools Error Eclipse simply cannot resolve the function when it is referenced by another file in the same package; however, the engine can at runtime. -- View this message in context: http://drools.46999.n3.nabble.com/Eclipse-Drools-Plugin-Compilation-Errors-tp4019781p4019782.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Eclipse - Drools Plugin - Compilation Errors
Resolved the issue. I found Allow cross references in DRL files. However, this did not work immediately. I needed to clean my workspace, and ensure that my files were also placed in the correct directory structure to match my package name(s). -- View this message in context: http://drools.46999.n3.nabble.com/Eclipse-Drools-Plugin-Compilation-Errors-tp4019781p4019785.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users