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();
}
Aggregations