Search in sources :

Example 6 with PackageDescrBuilder

use of org.drools.drl.ast.dsl.PackageDescrBuilder in project drools by kiegroup.

the class DescrBuilderTest method testQueryParameters.

@Test
public void testQueryParameters() {
    // DROOLS-4604
    PackageDescrBuilder packBuilder = DescrFactory.newPackage().name("org.test.rules").newImport().target("org.test.event.TemporalEvent").end().newQuery().name("getTemporalEventById").parameter("String", "eventId").lhs().pattern("TemporalEvent").constraint("id == eventId").from().entryPoint("EventStream").end().end().end().end();
    String drl = new DrlDumper().dump(packBuilder.getDescr());
    assertTrue(drl.contains("query \"getTemporalEventById\" ( String eventId ) "));
}
Also used : PackageDescrBuilder(org.drools.drl.ast.dsl.PackageDescrBuilder) DrlDumper(org.drools.mvel.DrlDumper) Test(org.junit.Test)

Example 7 with PackageDescrBuilder

use of org.drools.drl.ast.dsl.PackageDescrBuilder in project drools by kiegroup.

the class PackageDescrTest method createPackageDescrWithTypeDeclarationDescr.

@Test
public void createPackageDescrWithTypeDeclarationDescr() throws IOException {
    PackageDescrBuilder builder = PackageDescrBuilderImpl.newPackage();
    builder.newDeclare().type().name("java.lang.String");
    PackageDescr descr = builder.getDescr();
    OutputStream os = new ByteArrayOutputStream();
    ObjectOutput oo = new ObjectOutputStream(os);
    descr.writeExternal(oo);
    assertNotNull(os.toString());
}
Also used : PackageDescrBuilder(org.drools.drl.ast.dsl.PackageDescrBuilder) ObjectOutput(java.io.ObjectOutput) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PackageDescr(org.drools.drl.ast.descr.PackageDescr) ObjectOutputStream(java.io.ObjectOutputStream) Test(org.junit.Test)

Example 8 with PackageDescrBuilder

use of org.drools.drl.ast.dsl.PackageDescrBuilder in project drools by kiegroup.

the class ExtendsTest method testExtendsDump.

@Test
public void testExtendsDump() {
    PackageDescrBuilder pkgd = DescrFactory.newPackage();
    pkgd.name("org.test").newDeclare().type().name("Foo").newField("id").type("int").end().end().newDeclare().type().name("Bar").superType("Foo").newField("val").type("int").initialValue("42").end().end();
    String drl = new DrlDumper().dump(pkgd.getDescr());
    KieBase kb = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
    FactType bar = kb.getFactType("org.test", "Bar");
    try {
        Object x = bar.newInstance();
        assertEquals(42, bar.get(x, "val"));
        bar.set(x, "id", 1);
        assertEquals(1, bar.get(x, "id"));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : PackageDescrBuilder(org.drools.drl.ast.dsl.PackageDescrBuilder) KieBase(org.kie.api.KieBase) DrlDumper(org.drools.mvel.DrlDumper) FactType(org.kie.api.definition.type.FactType) Test(org.junit.Test)

Example 9 with PackageDescrBuilder

use of org.drools.drl.ast.dsl.PackageDescrBuilder in project drools by kiegroup.

the class KiePMMLDescrFactory method getBaseDescr.

/**
 * Returns the <code>PackageDescr</code> built out of the given <code>KiePMMLDroolsAST</code>.
 * @param kiePMMLDroolsAST
 * @param packageName
 * @return
 */
public static PackageDescr getBaseDescr(final KiePMMLDroolsAST kiePMMLDroolsAST, String packageName) {
    logger.trace("getBaseDescr {} {}", kiePMMLDroolsAST, packageName);
    PackageDescrBuilder builder = DescrFactory.newPackage().name(packageName);
    builder.newImport().target(KiePMMLStatusHolder.class.getName());
    builder.newImport().target(SimplePredicate.class.getName());
    builder.newImport().target(PMML4Result.class.getName());
    builder.newImport().target(Map.class.getName());
    builder.newGlobal().identifier(PMML4_RESULT_IDENTIFIER).type(PMML4_RESULT);
    builder.newGlobal().identifier(OUTPUTFIELDS_MAP_IDENTIFIER).type(OUTPUTFIELDS_MAP);
    KiePMMLDescrTypesFactory.factory(builder).declareTypes(kiePMMLDroolsAST.getTypes());
    KiePMMLDescrRulesFactory.factory(builder).declareRules(kiePMMLDroolsAST.getRules());
    return builder.getDescr();
}
Also used : PackageDescrBuilder(org.drools.drl.ast.dsl.PackageDescrBuilder) PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLStatusHolder(org.kie.pmml.models.drools.executor.KiePMMLStatusHolder) Map(java.util.Map) SimplePredicate(org.dmg.pmml.SimplePredicate)

Example 10 with PackageDescrBuilder

use of org.drools.drl.ast.dsl.PackageDescrBuilder in project drools by kiegroup.

the class KiePMMLDescrLhsFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    PackageDescrBuilder builder = DescrFactory.newPackage().name(PACKAGE_NAME);
    RuleDescrBuilder ruleBuilder = builder.newRule().name(CURRENT_RULE);
    lhsBuilder = ruleBuilder.lhs();
}
Also used : PackageDescrBuilder(org.drools.drl.ast.dsl.PackageDescrBuilder) RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder) Before(org.junit.Before)

Aggregations

PackageDescrBuilder (org.drools.drl.ast.dsl.PackageDescrBuilder)11 Test (org.junit.Test)7 PackageDescr (org.drools.drl.ast.descr.PackageDescr)4 DrlDumper (org.drools.mvel.DrlDumper)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ObjectOutput (java.io.ObjectOutput)3 ObjectOutputStream (java.io.ObjectOutputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 ObjectInput (java.io.ObjectInput)2 ObjectInputStream (java.io.ObjectInputStream)2 RuleDescrBuilder (org.drools.drl.ast.dsl.RuleDescrBuilder)2 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)2 Before (org.junit.Before)2 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 SimplePredicate (org.dmg.pmml.SimplePredicate)1