use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class KiePMMLTargetFactory method getKiePMMLTargetVariableInitializer.
static MethodCallExpr getKiePMMLTargetVariableInitializer(final TargetField targetField) {
final MethodDeclaration methodDeclaration = TARGET_TEMPLATE.getMethodsByName(GETKIEPMMLTARGET).get(0).clone();
final BlockStmt targetBody = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(targetBody, TARGET).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, TARGET, targetBody)));
variableDeclarator.setName(targetField.getName());
final MethodCallExpr toReturn = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, TARGET, targetBody))).asMethodCallExpr();
final MethodCallExpr builder = getChainedMethodCallExprFrom("builder", toReturn);
final StringLiteralExpr nameExpr = new StringLiteralExpr(targetField.getName());
builder.setArgument(0, nameExpr);
final ObjectCreationExpr targetFieldInstantiation = getTargetFieldVariableInitializer(targetField);
builder.setArgument(2, targetFieldInstantiation);
return toReturn;
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class KiePMMLTransformationDictionaryFactory method getKiePMMLTransformationDictionaryVariableDeclaration.
/**
* @param transformationDictionary
* @return
*/
static BlockStmt getKiePMMLTransformationDictionaryVariableDeclaration(final TransformationDictionary transformationDictionary) {
final MethodDeclaration methodDeclaration = TRANSFORMATION_DICTIONARY_TEMPLATE.getMethodsByName(GETKIEPMMLTRANSFORMATIONDICTIONARY).get(0).clone();
final BlockStmt transformationDictionaryBody = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(transformationDictionaryBody, TRANSFORMATION_DICTIONARY).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, TRANSFORMATION_DICTIONARY, transformationDictionaryBody)));
final MethodCallExpr initializer = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, TRANSFORMATION_DICTIONARY, methodDeclaration))).asMethodCallExpr();
final BlockStmt toReturn = new BlockStmt();
if (transformationDictionary.hasDefineFunctions()) {
NodeList<Expression> defineFunctions = addDefineFunctions(toReturn, transformationDictionary.getDefineFunctions());
getChainedMethodCallExprFrom("withDefineFunctions", initializer).setArguments(defineFunctions);
}
if (transformationDictionary.hasDerivedFields()) {
NodeList<Expression> derivedFields = addDerivedField(toReturn, transformationDictionary.getDerivedFields());
getChainedMethodCallExprFrom("withDerivedFields", initializer).setArguments(derivedFields);
}
transformationDictionaryBody.getStatements().forEach(toReturn::addStatement);
return toReturn;
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class TargetFieldFactory method getTargetFieldVariableInitializer.
static ObjectCreationExpr getTargetFieldVariableInitializer(final TargetField targetField) {
final MethodDeclaration methodDeclaration = TARGET_TEMPLATE.getMethodsByName(GETTARGET_FIELD).get(0).clone();
final BlockStmt targetBody = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(targetBody, TARGET_FIELD).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, TARGET_FIELD, targetBody)));
variableDeclarator.setName(targetField.getName());
final ObjectCreationExpr toReturn = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, TARGET_FIELD, targetBody))).asObjectCreationExpr();
final NodeList<Expression> arguments = new NodeList<>();
if (targetField.getTargetValues() != null) {
for (TargetValue targetValue : targetField.getTargetValues()) {
arguments.add(getTargetValueVariableInitializer(targetValue));
}
}
toReturn.getArgument(0).asMethodCallExpr().setArguments(arguments);
OP_TYPE oPT = targetField.getOpType();
Expression opType = oPT != null ? new NameExpr(oPT.getClass().getName() + "." + oPT.name()) : new NullLiteralExpr();
toReturn.setArgument(1, opType);
toReturn.setArgument(2, getExpressionForObject(targetField.getField()));
CAST_INTEGER cstInt = targetField.getCastInteger();
Expression castInteger = cstInt != null ? new NameExpr(cstInt.getClass().getName() + "." + cstInt.name()) : new NullLiteralExpr();
toReturn.setArgument(3, castInteger);
toReturn.setArgument(4, getExpressionForObject(targetField.getMin()));
toReturn.setArgument(5, getExpressionForObject(targetField.getMax()));
toReturn.setArgument(6, getExpressionForObject(targetField.getRescaleConstant()));
toReturn.setArgument(7, getExpressionForObject(targetField.getRescaleFactor()));
return toReturn;
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class CommonCodegenUtils method setExplicitConstructorInvocationStmtArgument.
/**
* Set the <b>value</b> of the given <b>parameterName</b> in the given
* <code>ExplicitConstructorInvocationStmt</code>
* @param constructorInvocationStmt
* @param parameterName
* @param value
* @throws KiePMMLException if the given parameter is not found
*/
public static void setExplicitConstructorInvocationStmtArgument(final ExplicitConstructorInvocationStmt constructorInvocationStmt, final String parameterName, final String value) {
final NameExpr parameterExpr = getExplicitConstructorInvocationParameter(constructorInvocationStmt, parameterName).orElseThrow(() -> new KiePMMLException(String.format(MISSING_PARAMETER_IN_CONSTRUCTOR_INVOCATION, parameterName, constructorInvocationStmt)));
parameterExpr.setName(value);
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class CommonCodegenUtils method setAssignExpressionValue.
/**
* Set the value of the variable with the given <b>assignExpressionName</b> in the given <code>BlockStmt</code>
* It throws <code>KiePMMLException</code> if variable is not found
* @param body
* @param assignExpressionName
* @param value
* @throws <code>KiePMMLException</code> if <code>AssignExpr</code> with given <b>assignExpressionName</b> is not
* found
*/
public static void setAssignExpressionValue(final BlockStmt body, final String assignExpressionName, final Expression value) {
AssignExpr assignExpr = getAssignExpression(body, assignExpressionName).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, assignExpressionName, body)));
assignExpr.setValue(value);
}
Aggregations