Search in sources :

Example 1 with DMNAllTypesIndex

use of org.kie.dmn.typesafe.DMNAllTypesIndex in project drools by kiegroup.

the class VariantTest method createTypeSafeInput.

private void createTypeSafeInput(DMNRuntime runtime) {
    String prefix = String.format("%s%s", testName, testConfig.name());
    factory = new DMNTypeSafePackageName.ModelFactory(prefix);
    DMNAllTypesIndex index = new DMNAllTypesIndex(factory, runtime.getModels().toArray(new DMNModel[] {}));
    allSources = new HashMap<>();
    for (DMNModel m : runtime.getModels()) {
        Map<String, String> allTypesSourceCode = new DMNTypeSafeTypeGenerator(m, index, factory).withJacksonAnnotation().withMPAnnotation().withIOSwaggerOASv3().processTypes().generateSourceCodeOfAllTypes();
        allSources.putAll(allTypesSourceCode);
    }
    if (!allSources.isEmpty()) {
        allCompiledClasses = KieMemoryCompiler.compile(allSources, this.getClass().getClassLoader());
    }
}
Also used : DMNAllTypesIndex(org.kie.dmn.typesafe.DMNAllTypesIndex) DMNTypeSafeTypeGenerator(org.kie.dmn.typesafe.DMNTypeSafeTypeGenerator) DMNTypeSafePackageName(org.kie.dmn.typesafe.DMNTypeSafePackageName) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 2 with DMNAllTypesIndex

use of org.kie.dmn.typesafe.DMNAllTypesIndex in project drools by kiegroup.

the class DMNTypeSafeTest method generateSourceCodeAndCreateInput.

public static Map<String, Class<?>> generateSourceCodeAndCreateInput(DMNModel dmnModel, DMNTypeSafePackageName.ModelFactory packageName, ClassLoader classLoader) {
    DMNAllTypesIndex index = new DMNAllTypesIndex(packageName, dmnModel);
    Map<String, String> allTypesSourceCode = new DMNTypeSafeTypeGenerator(dmnModel, index, packageName).processTypes().generateSourceCodeOfAllTypes();
    return KieMemoryCompiler.compile(allTypesSourceCode, classLoader);
}
Also used : DMNAllTypesIndex(org.kie.dmn.typesafe.DMNAllTypesIndex) DMNTypeSafeTypeGenerator(org.kie.dmn.typesafe.DMNTypeSafeTypeGenerator)

Example 3 with DMNAllTypesIndex

use of org.kie.dmn.typesafe.DMNAllTypesIndex in project drools by kiegroup.

the class DMNTypeSafeTest method test.

@Test
public void test() throws Exception {
    assertValidDmnModel(dmnModel);
    DMNAllTypesIndex index = new DMNAllTypesIndex(new DMNTypeSafePackageName.ModelFactory(), dmnModel);
    Map<String, String> allTypesSourceCode = new DMNTypeSafeTypeGenerator(dmnModel, index, modelFactory).processTypes().generateSourceCodeOfAllTypes();
    ClassLoader thisDMNClassLoader = this.getClass().getClassLoader();
    Map<String, Class<?>> compiledClasses = KieMemoryCompiler.compile(allTypesSourceCode, thisDMNClassLoader);
    FEELPropertyAccessible street1 = tAddress(compiledClasses, "Street1", 1);
    FEELPropertyAccessible street2 = tAddress(compiledClasses, "Street2", 2);
    FEELPropertyAccessible tPersonInstance = tPerson(compiledClasses, asList(street1, street2));
    FEELPropertyAccessible context = outputSet(compiledClasses, tPersonInstance);
    DMNResult evaluateAll = evaluateTyped(context, runtime, dmnModel);
    convertContext(evaluateAll, createInstanceFromCompiledClasses(compiledClasses, packageName, "OutputSet"));
    DMNContext result = evaluateAll.getContext();
    Map<String, Object> d = (Map<String, Object>) result.get("d");
    assertThat(d.get("Hello"), is("Hello Mr. x"));
    FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) result).getFpa();
    assertThat(outputSet.getFEELProperty("p").toOptional().get(), equalTo(tPersonInstance));
    Map<String, Object> dContext = (Map<String, Object>) outputSet.getFEELProperty("d").toOptional().get();
    assertThat(dContext.get("Hello"), is("Hello Mr. x"));
    assertThat(dContext.get("the person"), equalTo(tPersonInstance));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContextFPAImpl(org.kie.dmn.core.impl.DMNContextFPAImpl) FEELPropertyAccessible(org.kie.dmn.api.core.FEELPropertyAccessible) DMNTypeSafeTypeGenerator(org.kie.dmn.typesafe.DMNTypeSafeTypeGenerator) DMNContext(org.kie.dmn.api.core.DMNContext) DMNAllTypesIndex(org.kie.dmn.typesafe.DMNAllTypesIndex) DMNTypeSafePackageName(org.kie.dmn.typesafe.DMNTypeSafePackageName) HashMap(java.util.HashMap) Map(java.util.Map) BaseVariantTest(org.kie.dmn.core.BaseVariantTest) Test(org.junit.Test)

Aggregations

DMNAllTypesIndex (org.kie.dmn.typesafe.DMNAllTypesIndex)3 DMNTypeSafeTypeGenerator (org.kie.dmn.typesafe.DMNTypeSafeTypeGenerator)3 DMNTypeSafePackageName (org.kie.dmn.typesafe.DMNTypeSafePackageName)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 DMNContext (org.kie.dmn.api.core.DMNContext)1 DMNModel (org.kie.dmn.api.core.DMNModel)1 DMNResult (org.kie.dmn.api.core.DMNResult)1 FEELPropertyAccessible (org.kie.dmn.api.core.FEELPropertyAccessible)1 BaseVariantTest (org.kie.dmn.core.BaseVariantTest)1 DMNContextFPAImpl (org.kie.dmn.core.impl.DMNContextFPAImpl)1