use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class KiePMMLCompoundPredicateASTFactory method declareRuleFromCompoundPredicateSurrogate.
/**
* Method to be invoked when <b>compoundPredicate.getBooleanOperator()</b> is <code>SURROGATE</code>.
* Throws exception otherwise
* @param agendaActivationGroup
* @param statusToSet
*/
private void declareRuleFromCompoundPredicateSurrogate(final String agendaActivationGroup, final String statusToSet) {
logger.trace("declareRuleFromCompoundPredicateSurrogate {} {}", agendaActivationGroup, statusToSet);
CompoundPredicate compoundPredicate = (CompoundPredicate) predicateASTFactoryData.getPredicate();
if (!CompoundPredicate.BooleanOperator.SURROGATE.equals(compoundPredicate.getBooleanOperator())) {
throw new KiePMMLException(String.format("declareRuleFromCompoundPredicateSurrogate invoked with %s CompoundPredicate", compoundPredicate.getBooleanOperator()));
}
KiePMMLDroolsRule.Builder builder = KiePMMLDroolsRule.builder(predicateASTFactoryData.getCurrentRule(), null, predicateASTFactoryData.getOutputFields()).withStatusConstraint(String.format(STATUS_PATTERN, predicateASTFactoryData.getParentPath())).withFocusedAgendaGroup(agendaActivationGroup);
predicateASTFactoryData.getRules().add(builder.build());
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class PMMLRuntimeInternalImplTest method removePMMLListener.
@Test
public void removePMMLListener() {
try {
PMMLListener listener = getPMMLListener(new ArrayList<>());
pmmlRuntime.addPMMLListener(listener);
pmmlRuntime.removePMMLListener(listener);
pmmlRuntime.evaluate("MODEL_NAME", pmmlContextMock);
verify(pmmlContextMock, never()).addPMMLListener(listener);
} catch (KiePMMLException e) {
commonManageException(e);
}
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class KiePMMLDroolsModel method evaluate.
@Override
public Object evaluate(final Object knowledgeBase, final Map<String, Object> requestData, final PMMLContext context) {
logger.trace("evaluate {} {}", knowledgeBase, requestData);
if (!(knowledgeBase instanceof KieBase)) {
throw new KiePMMLException(String.format("Expecting KieBase, received %s", knowledgeBase.getClass().getName()));
}
final PMML4Result toReturn = getPMML4Result(targetField);
String fullClassName = this.getClass().getName();
String packageName = fullClassName.contains(".") ? fullClassName.substring(0, fullClassName.lastIndexOf('.')) : "";
KiePMMLSessionUtils.Builder builder = KiePMMLSessionUtils.builder((KieBase) knowledgeBase, name, packageName, toReturn).withObjectsInSession(requestData, fieldTypeMap).withOutputFieldsMap(context.getOutputFieldsMap());
if (logger.isDebugEnabled()) {
builder = builder.withAgendaEventListener(agendaEventListener);
}
final KiePMMLSessionUtils kiePMMLSessionUtils = builder.build();
kiePMMLSessionUtils.fireAllRules();
return toReturn;
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class DroolsModelProvider method getKiePMMLModelWithSources.
@Override
public KiePMMLDroolsModelWithSources getKiePMMLModelWithSources(final CompilationDTO<T> compilationDTO) {
logger.trace("getKiePMMLModelWithSources {} {} {}", compilationDTO.getPackageName(), compilationDTO.getFields(), compilationDTO.getModel());
if (!(compilationDTO.getHasClassloader() instanceof HasKnowledgeBuilder)) {
throw new KiePMMLException(String.format(EXPECTING_HAS_KNOWLEDGEBUILDER_TEMPLATE, compilationDTO.getHasClassloader().getClass().getName()));
}
try {
final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
KiePMMLDroolsAST kiePMMLDroolsAST = getKiePMMLDroolsASTCommon(compilationDTO.getFields(), compilationDTO.getModel(), fieldTypeMap);
final DroolsCompilationDTO<T> droolsCompilationDTO = DroolsCompilationDTO.fromCompilationDTO(compilationDTO, fieldTypeMap);
Map<String, String> sourcesMap = getKiePMMLDroolsModelSourcesMap(droolsCompilationDTO);
PackageDescr packageDescr = getPackageDescr(kiePMMLDroolsAST, compilationDTO.getPackageName());
HasKnowledgeBuilder hasKnowledgeBuilder = (HasKnowledgeBuilder) compilationDTO.getHasClassloader();
KnowledgeBuilderImpl knowledgeBuilder = (KnowledgeBuilderImpl) hasKnowledgeBuilder.getKnowledgeBuilder();
String pkgUUID = getPkgUUID(knowledgeBuilder.getReleaseId(), compilationDTO.getPackageName());
packageDescr.setPreferredPkgUUID(pkgUUID);
Map<String, String> rulesSourceMap = Collections.unmodifiableMap(getRulesSourceMap(packageDescr));
KiePMMLDroolsModelWithSources toReturn = new KiePMMLDroolsModelWithSources(compilationDTO.getModelName(), compilationDTO.getPackageName(), compilationDTO.getKieMiningFields(), compilationDTO.getKieOutputFields(), compilationDTO.getKieTargetFields(), sourcesMap, pkgUUID, rulesSourceMap);
knowledgeBuilder.registerPackage(packageDescr);
return toReturn;
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class KiePMMLScorecardModelFactory method getKiePMMLScorecardModel.
public static KiePMMLScorecardModel getKiePMMLScorecardModel(final DroolsCompilationDTO<Scorecard> compilationDTO) throws IllegalAccessException, InstantiationException {
logger.trace("getKiePMMLScorecardModel {} {}", compilationDTO.getPackageName(), compilationDTO.getModel());
Map<String, String> sourcesMap = getKiePMMLScorecardModelSourcesMap(compilationDTO);
try {
Class<?> kiePMMLScorecardModelClass = compilationDTO.compileAndLoadClass(sourcesMap);
return (KiePMMLScorecardModel) kiePMMLScorecardModelClass.newInstance();
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
Aggregations