KiePMMLScorecardModelCharacteristicASTFactory { public List<KiePMMLDroolsRule> declareRulesFromCharacteristics(final Characteristics characteristics, final String parentPath, Number initialScore) { logger.trace("declareRulesFromCharacteristics {} {} {}", characteristics, parentPath, initialScore); final List<KiePMMLDroolsRule> toReturn = new ArrayList<>(); final List<Characteristic> characteristicList = characteristics.getCharacteristics(); for (int i = 0; i < characteristicList.size(); i++) { final Characteristic characteristic = characteristicList.get(i); if (i == 0) { String statusConstraint = StringUtils.isEmpty(parentPath) ? KiePMMLAbstractModelASTFactory.STATUS_NULL : String.format(KiePMMLAbstractModelASTFactory.STATUS_PATTERN, parentPath); String currentRule = String.format(PATH_PATTERN, parentPath, characteristic.getName()); KiePMMLDroolsRule.Builder builder = KiePMMLDroolsRule.builder(currentRule, currentRule, null) .withStatusConstraint(statusConstraint); if (initialScore != null) { builder = builder.withAccumulation(initialScore); } toReturn.add(builder.build()); } boolean isLastCharacteristic = (i == characteristicList.size() - 1); String statusToSet = isLastCharacteristic ? DONE : String.format(PATH_PATTERN, parentPath, characteristicList.get(i + 1).getName()); declareRuleFromCharacteristic(characteristic, parentPath, toReturn, statusToSet, isLastCharacteristic); } return toReturn; } private  KiePMMLScorecardModelCharacteristicASTFactory(final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap, final List<KiePMMLOutputField> outputFields, final DATA_TYPE targetType); static KiePMMLScorecardModelCharacteristicASTFactory factory(final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap, final List<KiePMMLOutputField> outputFields, final DATA_TYPE targetType); KiePMMLScorecardModelCharacteristicASTFactory withReasonCodes(Number baselineScore, REASONCODE_ALGORITHM reasonCodeAlgorithm); List<KiePMMLDroolsRule> declareRulesFromCharacteristics(final Characteristics characteristics, final String parentPath, Number initialScore);  }
@Test public void declareRulesFromCharacteristics() { Characteristics characteristics = scorecardModel.getCharacteristics(); String parentPath = "_will"; List<KiePMMLDroolsRule> retrieved = getKiePMMLScorecardModelCharacteristicASTFactory() .declareRulesFromCharacteristics(characteristics, parentPath, null); final List<Characteristic> characteristicList = characteristics.getCharacteristics(); List<Attribute> attributes = new ArrayList<>(); AtomicInteger counter = new AtomicInteger(0); for (int i = 0; i < characteristicList.size(); i++) { Characteristic characteristic = characteristicList.get(i); attributes.addAll(characteristic.getAttributes()); for (int j = 0; j < characteristic.getAttributes().size(); j++) { Attribute attribute = characteristic.getAttributes().get(j); KiePMMLDroolsRule rule = retrieved.get(counter.incrementAndGet()); int expectedOperatorValuesSize = 1; Integer expectedAndConstraints = null; Integer expectedInConstraints = null; BOOLEAN_OPERATOR expectedOperator = BOOLEAN_OPERATOR.AND; if (attribute.getPredicate() instanceof SimplePredicate) { expectedAndConstraints = 1; } if (attribute.getPredicate() instanceof CompoundPredicate) { expectedOperatorValuesSize = ((CompoundPredicate) attribute.getPredicate()).getPredicates().size(); expectedAndConstraints = 1; } if (attribute.getPredicate() instanceof SimpleSetPredicate) { expectedInConstraints = 1; } boolean isLastCharacteristic = (i == characteristicList.size() - 1); String statusToSet = isLastCharacteristic ? DONE : String.format(PATH_PATTERN, parentPath, characteristicList.get(i + 1).getName()); commonValidateRule(rule, attribute, statusToSet, parentPath + "_" + characteristic.getName(), j, isLastCharacteristic, expectedAndConstraints, expectedInConstraints, expectedOperator, null, expectedOperatorValuesSize); } } assertEquals(attributes.size() + 1, retrieved.size()); }