use of org.kie.pmml.evaluator.api.exceptions.KiePMMLModelException in project drools by kiegroup.
the class KiePMMLSessionUtils method addObjectsToSession.
/**
* Add <code>Object</code>s to the underlying <code>KieSession</code>.
* Such <code>Object</code>s are retrieved/instantiated from the given <code>Map</code>s and the content of the current kieSession' <code>KieBase</code>
* @param unwrappedInputParams
* @param fieldTypeMap
*/
private void addObjectsToSession(final Map<String, Object> unwrappedInputParams, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap) {
for (Map.Entry<String, Object> entry : unwrappedInputParams.entrySet()) {
if (!fieldTypeMap.containsKey(entry.getKey())) {
throw new KiePMMLModelException(String.format("Field %s not mapped to generated type", entry.getKey()));
}
try {
String generatedTypeName = fieldTypeMap.get(entry.getKey()).getGeneratedType();
FactType factType = kieSession.getKieBase().getFactType(packageName, generatedTypeName);
if (factType == null) {
String name = String.format(PACKAGE_CLASS_TEMPLATE, packageName, generatedTypeName);
String error = String.format("Failed to retrieve FactType %s for input value %s", name, entry.getKey());
throw new KiePMMLModelException(error);
}
Object toAdd = factType.newInstance();
factType.set(toAdd, "value", entry.getValue());
commands.add(COMMAND_FACTORY_SERVICE.newInsert(toAdd));
} catch (Exception e) {
throw new KiePMMLModelException(e.getMessage(), e);
}
}
}
Aggregations