Search in sources :

Example 1 with KiePMMLModelException

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);
        }
    }
}
Also used : KiePMMLModelException(org.kie.pmml.evaluator.api.exceptions.KiePMMLModelException) Map(java.util.Map) KiePMMLModelException(org.kie.pmml.evaluator.api.exceptions.KiePMMLModelException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) FactType(org.kie.api.definition.type.FactType)

Aggregations

Map (java.util.Map)1 FactType (org.kie.api.definition.type.FactType)1 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)1 KiePMMLModelException (org.kie.pmml.evaluator.api.exceptions.KiePMMLModelException)1