use of org.kie.pmml.models.drools.ast.factories.KiePMMLAbstractModelASTFactory.STATUS_NULL in project drools by kiegroup.
the class KiePMMLSimpleSetPredicateASTFactory method getBuilderForSimpleSetPredicate.
private KiePMMLDroolsRule.Builder getBuilderForSimpleSetPredicate(final String statusToSet) {
logger.trace("declareRuleFromSimpleSetPredicate {}", statusToSet);
String statusConstraint = StringUtils.isEmpty(predicateASTFactoryData.getParentPath()) ? STATUS_NULL : String.format(STATUS_PATTERN, predicateASTFactoryData.getParentPath());
SimpleSetPredicate simpleSetPredicate = (SimpleSetPredicate) predicateASTFactoryData.getPredicate();
String key = predicateASTFactoryData.getFieldTypeMap().get(simpleSetPredicate.getField().getValue()).getGeneratedType();
String stringValue = (String) simpleSetPredicate.getArray().getValue();
String[] valuesArray = stringValue.split(" ");
List<Object> value = Arrays.stream(valuesArray).map(rawValue -> {
String originalType = predicateASTFactoryData.getFieldTypeMap().get(simpleSetPredicate.getField().getValue()).getOriginalType();
switch(originalType) {
case "string":
return "\"" + rawValue + "\"";
case "double":
return Double.valueOf(rawValue).toString();
default:
return rawValue;
}
}).collect(Collectors.toList());
Map<String, List<Object>> constraints = Collections.singletonMap(key, value);
KiePMMLDroolsRule.Builder toReturn = KiePMMLDroolsRule.builder(predicateASTFactoryData.getCurrentRule(), statusToSet, predicateASTFactoryData.getOutputFields()).withStatusConstraint(statusConstraint);
if (SimpleSetPredicate.BooleanOperator.IS_IN.equals(simpleSetPredicate.getBooleanOperator())) {
toReturn = toReturn.withInConstraints(constraints);
} else {
toReturn = toReturn.withNotInConstraints(constraints);
}
return toReturn;
}
Aggregations