package com.signavio.drools
declare Enums
status : Enum display : String
end
rule "enums_Rule_1" no-loop when $enums : Enums( ) then modify( $enums ){ setDisplay("Important Person") };end
rule "enums_Rule_2" no-loop when $enums : Enums( status != "VIP", status != "IP" ) then modify( $enums ){ setDisplay("Not an Important Person") };end
public void thatEnumsAreHandledCorrectly(String input, String expected) throws Exception {KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
knowledgeBuilder.add(ResourceFactory.newFileResource(drlFile), ResourceType.DRL);
KieBase knowledgeBase = knowledgeBuilder.newKnowledgeBase();
KieSession session = knowledgeBase.newKieSession();
FactType enums = knowledgeBase.getFactType("com.signavio.drools", "Enums");
Object enumObject = enums.newInstance();
enums.set(enumObject, "status", input);
session.insert(enumObject);
session.fireAllRules();
String result = (String) enums.get(enumObject, "display");
assertEquals(result, expected);
session.dispose();
}
Is there any way I can achieve this? I am also glad for pointers to the right documentation.
Thanks!
- Sascha
declare enum Status
VIP
IP
NIP
end
declare Enums
status : Status
display : String
endwhen
$enums : Enums(status == Status.VIP or status == Status.IP )
then
modify( $enums ){
setDisplay("Important Person")
};
end
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/aa33712a-3404-45cd-8f9f-eb1ef6664cb8%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
enums.set(enumObject, "status", "Status.VIP");
FactType status = knowledgeBase.getFactType("com.signavio.drools", "Status");
Object statusObject = status.newInstance();
Object VIPStatus = status.get(statusObject, "VIP");
....
enums.set(enumObject, "status", VIPStatus);
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/8bbf1fa4-ad47-4975-8eb0-284e45b7708c%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/eade9762-b147-4d50-8afb-fc725b85671d%40googlegroups.com.
On 2 Mar 2015, at 13:02, sascha.s...@signavio.com wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/eade9762-b147-4d50-8afb-fc725b85671d%40googlegroups.com.
@Test
public void enumDeclaration() {
PackageDescrBuilder packageBuilder = DescrFactory.newPackage();
packageBuilder.name("com.test");
packageBuilder.newDeclare()
.enumerative().name("Status")
.newEnumLiteral("VIP").end()
.newEnumLiteral("IP").end()
.newEnumLiteral("NIP").end()
.end();
packageBuilder.newRule().end();
DrlDumper dumper = new DrlDumper();
System.out.println(dumper.dump(packageBuilder.getDescr()));
}
package com.test
rule "null"whenthenendTo view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/4f41db79-b027-42a8-9d76-2a15b1da98fc%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/14d6261c-51e6-4d4a-8793-c4144f185be1%40googlegroups.com.
So I could use 6.2.0.CR4 to test it?Problem is that our client is working with 6.1, so I may have to work around.Thanks for the hint!
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/64bffc98-30df-44f8-ab1b-4025a92d766f%40googlegroups.com.
knowledgeBuilder.add(ResourceFactory.newFileResource(outputFile), ResourceType.DRL);
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/013214a5-93a5-4b1b-a540-0a84799ca3e5%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/8721b256-f844-4b98-8010-ab93920c6ee5%40googlegroups.com.