Search in sources :

Example 16 with TemplateRegistry

use of org.mvel2.templates.TemplateRegistry in project drools by kiegroup.

the class AbstractModel method getMappedRuleUnit.

@Override
public Map.Entry<String, String> getMappedRuleUnit() {
    Map<String, String> result = new HashMap<>();
    if (!templateRegistry.contains(this.getRuleUnitTemplateName())) {
        this.addRuleUnitTemplateToRegistry(templateRegistry);
    }
    Map<String, Object> vars = new HashMap<>();
    String className = this.getRuleUnitClassName();
    vars.put("pmmlPackageName", this.getModelPackageName());
    vars.put("className", className);
    vars.put("pojoInputClassName", PMMLRequestData.class.getName());
    if (this instanceof Miningmodel) {
        vars.put("miningPojoClassName", this.getMiningPojoClassName());
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        TemplateRuntime.execute(templateRegistry.getNamedTemplate(this.getRuleUnitTemplateName()), null, new MapVariableResolverFactory(vars), baos);
    } catch (TemplateError te) {
        return null;
    } catch (TemplateRuntimeError tre) {
        // need to figure out logging here
        return null;
    }
    result.put(this.getModelPackageName() + "." + className, new String(baos.toByteArray()));
    return result.isEmpty() ? null : result.entrySet().iterator().next();
}
Also used : TemplateRuntimeError(org.mvel2.templates.TemplateRuntimeError) PMMLRequestData(org.kie.api.pmml.PMMLRequestData) HashMap(java.util.HashMap) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TemplateError(org.mvel2.templates.TemplateError)

Aggregations

MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)8 CompiledTemplate (org.mvel2.templates.CompiledTemplate)8 SimpleTemplateRegistry (org.mvel2.templates.SimpleTemplateRegistry)7 TemplateRegistry (org.mvel2.templates.TemplateRegistry)7 HashMap (java.util.HashMap)6 InputStream (java.io.InputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 List (java.util.List)3 Map (java.util.Map)3 ClassObjectType (org.drools.core.base.ClassObjectType)3 Declaration (org.drools.core.rule.Declaration)3 PatternExtractor (org.drools.core.spi.PatternExtractor)3 Test (org.junit.Test)3 TemplateRuntimeError (org.mvel2.templates.TemplateRuntimeError)3 Cheese (org.drools.compiler.Cheese)2 Person (org.drools.compiler.Person)2 TemplateError (org.mvel2.templates.TemplateError)2 Node (org.mvel2.templates.res.Node)2 PMMLRequestData (org.kie.api.pmml.PMMLRequestData)1