Search in sources :

Example 81 with KiePMMLException

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());
}
Also used : KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) CompoundPredicate(org.dmg.pmml.CompoundPredicate) KiePMMLASTFactoryUtils.getConstraintEntriesFromAndOrCompoundPredicate(org.kie.pmml.models.drools.utils.KiePMMLASTFactoryUtils.getConstraintEntriesFromAndOrCompoundPredicate) KiePMMLASTFactoryUtils.getConstraintEntriesFromXOrCompoundPredicate(org.kie.pmml.models.drools.utils.KiePMMLASTFactoryUtils.getConstraintEntriesFromXOrCompoundPredicate)

Example 82 with KiePMMLException

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);
    }
}
Also used : KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) PMMLListener(org.kie.pmml.api.runtime.PMMLListener) Test(org.junit.Test)

Example 83 with KiePMMLException

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;
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLSessionUtils(org.kie.pmml.models.drools.utils.KiePMMLSessionUtils) KieBase(org.kie.api.KieBase) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Example 84 with KiePMMLException

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);
    }
}
Also used : KiePMMLDroolsAST(org.kie.pmml.models.drools.ast.KiePMMLDroolsAST) HashMap(java.util.HashMap) IOException(java.io.IOException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) KiePMMLDroolsAST(org.kie.pmml.models.drools.ast.KiePMMLDroolsAST) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) HasKnowledgeBuilder(org.kie.pmml.kie.dependencies.HasKnowledgeBuilder) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) PackageDescr(org.drools.drl.ast.descr.PackageDescr) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) KiePMMLDroolsModelWithSources(org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModelWithSources)

Example 85 with KiePMMLException

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);
    }
}
Also used : KiePMMLScorecardModel(org.kie.pmml.models.drools.scorecard.model.KiePMMLScorecardModel) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Aggregations

KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)109 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)49 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)40 CommonCodegenUtils.getVariableDeclarator (org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getVariableDeclarator)38 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)37 Expression (com.github.javaparser.ast.expr.Expression)33 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)33 NameExpr (com.github.javaparser.ast.expr.NameExpr)32 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)26 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)20 KiePMMLInternalException (org.kie.pmml.api.exceptions.KiePMMLInternalException)18 CompilationUnit (com.github.javaparser.ast.CompilationUnit)17 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)17 NodeList (com.github.javaparser.ast.NodeList)13 HashMap (java.util.HashMap)12 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)10 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)9 ExplicitConstructorInvocationStmt (com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt)9 Test (org.junit.Test)7 IOException (java.io.IOException)6