@Test public void populateKiePMMLFieldOperatorValueListWithCompoundPredicates() { final List<KiePMMLFieldOperatorValue> toPopulate = new ArrayList<>(); KiePMMLASTFactoryUtils.populateKiePMMLFieldOperatorValueListWithCompoundPredicates(toPopulate, compoundPredicates, fieldTypeMap); assertFalse(toPopulate.isEmpty()); assertEquals(2, toPopulate.size()); final Map<CompoundPredicate.BooleanOperator, List<CompoundPredicate>> partitionedCompoundPredicates = compoundPredicates.stream() .collect(Collectors.groupingBy(CompoundPredicate::getBooleanOperator)); partitionedCompoundPredicates.forEach((booleanOperator, compoundPredicates) -> { final KiePMMLFieldOperatorValue operatorValue = toPopulate.stream() .filter(kiePMMLFieldOperatorValue -> kiePMMLFieldOperatorValue.getOperator().equals(BOOLEAN_OPERATOR.byName(booleanOperator.value()))) .findFirst() .orElseThrow(() -> new RuntimeException("Failed toRetrieve KiePMMLFieldOperatorValue for " + "BooleanOperator " + booleanOperator)); final List<KiePMMLFieldOperatorValue> nestedKiePMMLFieldOperatorValues = operatorValue.getNestedKiePMMLFieldOperatorValues(); final List<Predicate> nestedPredicates = compoundPredicates.stream().flatMap(compoundPredicate -> compoundPredicate.getPredicates().stream()).collect(Collectors.toList()); assertEquals(nestedPredicates.size(), nestedKiePMMLFieldOperatorValues.size()); nestedKiePMMLFieldOperatorValues.forEach(new Consumer<KiePMMLFieldOperatorValue>() { @Override public void accept(KiePMMLFieldOperatorValue kiePMMLFieldOperatorValue) { assertEquals(1, kiePMMLFieldOperatorValue.getKiePMMLOperatorValues().size()); final KiePMMLOperatorValue kiePMMLOperatorValue = kiePMMLFieldOperatorValue.getKiePMMLOperatorValues().get(0); SimplePredicate simplePredicate = nestedPredicates.stream() .map(predicate -> (SimplePredicate) predicate) .filter(predicate -> predicate.getField().getValue().equals(getOriginalPredicateName(kiePMMLFieldOperatorValue.getName()))) .findFirst() .orElseThrow(() -> new RuntimeException("Failed to find SimplePredicate for " + kiePMMLFieldOperatorValue.getName())); commonVerifyKiePMMLOperatorValue(kiePMMLOperatorValue, simplePredicate); nestedPredicates.remove(simplePredicate); } }); assertTrue(nestedPredicates.isEmpty()); }); }
static void populateKiePMMLFieldOperatorValueListWithCompoundPredicates(final List<KiePMMLFieldOperatorValue> toPopulate, final List<CompoundPredicate> compoundPredicates, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap) { final List<KiePMMLFieldOperatorValue> nestedAndPredicates = new LinkedList<>(); final List<KiePMMLFieldOperatorValue> nestedOrPredicates = new LinkedList<>(); compoundPredicates.forEach(nestedCompoundPredicate -> { switch ((nestedCompoundPredicate).getBooleanOperator()) { case OR: nestedOrPredicates.addAll(getConstraintEntriesFromAndOrCompoundPredicate(nestedCompoundPredicate, fieldTypeMap)); break; case AND: nestedAndPredicates.addAll(getConstraintEntriesFromAndOrCompoundPredicate(nestedCompoundPredicate, fieldTypeMap)); break; default: throw new IllegalStateException(String.format("Unmanaged CompoundPredicate.booleanOperator %s at populateKiePMMLFieldOperatorValueListWithCompoundPredicates", nestedCompoundPredicate.getBooleanOperator())); } }); if (!nestedAndPredicates.isEmpty()) { toPopulate.add(new KiePMMLFieldOperatorValue(null, BOOLEAN_OPERATOR.AND, Collections.emptyList(), nestedAndPredicates)); } if (!nestedOrPredicates.isEmpty()) { toPopulate.add(new KiePMMLFieldOperatorValue(null, BOOLEAN_OPERATOR.OR, Collections.emptyList(), nestedOrPredicates)); } }
KiePMMLASTFactoryUtils { static void populateKiePMMLFieldOperatorValueListWithCompoundPredicates(final List<KiePMMLFieldOperatorValue> toPopulate, final List<CompoundPredicate> compoundPredicates, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap) { final List<KiePMMLFieldOperatorValue> nestedAndPredicates = new LinkedList<>(); final List<KiePMMLFieldOperatorValue> nestedOrPredicates = new LinkedList<>(); compoundPredicates.forEach(nestedCompoundPredicate -> { switch ((nestedCompoundPredicate).getBooleanOperator()) { case OR: nestedOrPredicates.addAll(getConstraintEntriesFromAndOrCompoundPredicate(nestedCompoundPredicate, fieldTypeMap)); break; case AND: nestedAndPredicates.addAll(getConstraintEntriesFromAndOrCompoundPredicate(nestedCompoundPredicate, fieldTypeMap)); break; default: throw new IllegalStateException(String.format("Unmanaged CompoundPredicate.booleanOperator %s at populateKiePMMLFieldOperatorValueListWithCompoundPredicates", nestedCompoundPredicate.getBooleanOperator())); } }); if (!nestedAndPredicates.isEmpty()) { toPopulate.add(new KiePMMLFieldOperatorValue(null, BOOLEAN_OPERATOR.AND, Collections.emptyList(), nestedAndPredicates)); } if (!nestedOrPredicates.isEmpty()) { toPopulate.add(new KiePMMLFieldOperatorValue(null, BOOLEAN_OPERATOR.OR, Collections.emptyList(), nestedOrPredicates)); } } }
KiePMMLASTFactoryUtils { static void populateKiePMMLFieldOperatorValueListWithCompoundPredicates(final List<KiePMMLFieldOperatorValue> toPopulate, final List<CompoundPredicate> compoundPredicates, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap) { final List<KiePMMLFieldOperatorValue> nestedAndPredicates = new LinkedList<>(); final List<KiePMMLFieldOperatorValue> nestedOrPredicates = new LinkedList<>(); compoundPredicates.forEach(nestedCompoundPredicate -> { switch ((nestedCompoundPredicate).getBooleanOperator()) { case OR: nestedOrPredicates.addAll(getConstraintEntriesFromAndOrCompoundPredicate(nestedCompoundPredicate, fieldTypeMap)); break; case AND: nestedAndPredicates.addAll(getConstraintEntriesFromAndOrCompoundPredicate(nestedCompoundPredicate, fieldTypeMap)); break; default: throw new IllegalStateException(String.format("Unmanaged CompoundPredicate.booleanOperator %s at populateKiePMMLFieldOperatorValueListWithCompoundPredicates", nestedCompoundPredicate.getBooleanOperator())); } }); if (!nestedAndPredicates.isEmpty()) { toPopulate.add(new KiePMMLFieldOperatorValue(null, BOOLEAN_OPERATOR.AND, Collections.emptyList(), nestedAndPredicates)); } if (!nestedOrPredicates.isEmpty()) { toPopulate.add(new KiePMMLFieldOperatorValue(null, BOOLEAN_OPERATOR.OR, Collections.emptyList(), nestedOrPredicates)); } } private  KiePMMLASTFactoryUtils(); }
KiePMMLASTFactoryUtils { static void populateKiePMMLFieldOperatorValueListWithCompoundPredicates(final List<KiePMMLFieldOperatorValue> toPopulate, final List<CompoundPredicate> compoundPredicates, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap) { final List<KiePMMLFieldOperatorValue> nestedAndPredicates = new LinkedList<>(); final List<KiePMMLFieldOperatorValue> nestedOrPredicates = new LinkedList<>(); compoundPredicates.forEach(nestedCompoundPredicate -> { switch ((nestedCompoundPredicate).getBooleanOperator()) { case OR: nestedOrPredicates.addAll(getConstraintEntriesFromAndOrCompoundPredicate(nestedCompoundPredicate, fieldTypeMap)); break; case AND: nestedAndPredicates.addAll(getConstraintEntriesFromAndOrCompoundPredicate(nestedCompoundPredicate, fieldTypeMap)); break; default: throw new IllegalStateException(String.format("Unmanaged CompoundPredicate.booleanOperator %s at populateKiePMMLFieldOperatorValueListWithCompoundPredicates", nestedCompoundPredicate.getBooleanOperator())); } }); if (!nestedAndPredicates.isEmpty()) { toPopulate.add(new KiePMMLFieldOperatorValue(null, BOOLEAN_OPERATOR.AND, Collections.emptyList(), nestedAndPredicates)); } if (!nestedOrPredicates.isEmpty()) { toPopulate.add(new KiePMMLFieldOperatorValue(null, BOOLEAN_OPERATOR.OR, Collections.emptyList(), nestedOrPredicates)); } } private  KiePMMLASTFactoryUtils(); static List<KiePMMLFieldOperatorValue> getConstraintEntriesFromAndOrCompoundPredicate(final CompoundPredicate compoundPredicate, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap); static List<KiePMMLFieldOperatorValue> getConstraintEntriesFromXOrCompoundPredicate(final CompoundPredicate compoundPredicate, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap); static KiePMMLFieldOperatorValue getConstraintEntryFromSimplePredicates(final String fieldName,
                                                                                   final BOOLEAN_OPERATOR containerOperator,
                                                                                   final List<SimplePredicate> simplePredicates,
                                                                                   final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap); static List<KiePMMLFieldOperatorValue> getXORConstraintEntryFromSimplePredicates(final List<Predicate> predicates, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap); static Object getCorrectlyFormattedObject(final SimplePredicate simplePredicate, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap); }
KiePMMLASTFactoryUtils { static void populateKiePMMLFieldOperatorValueListWithCompoundPredicates(final List<KiePMMLFieldOperatorValue> toPopulate, final List<CompoundPredicate> compoundPredicates, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap) { final List<KiePMMLFieldOperatorValue> nestedAndPredicates = new LinkedList<>(); final List<KiePMMLFieldOperatorValue> nestedOrPredicates = new LinkedList<>(); compoundPredicates.forEach(nestedCompoundPredicate -> { switch ((nestedCompoundPredicate).getBooleanOperator()) { case OR: nestedOrPredicates.addAll(getConstraintEntriesFromAndOrCompoundPredicate(nestedCompoundPredicate, fieldTypeMap)); break; case AND: nestedAndPredicates.addAll(getConstraintEntriesFromAndOrCompoundPredicate(nestedCompoundPredicate, fieldTypeMap)); break; default: throw new IllegalStateException(String.format("Unmanaged CompoundPredicate.booleanOperator %s at populateKiePMMLFieldOperatorValueListWithCompoundPredicates", nestedCompoundPredicate.getBooleanOperator())); } }); if (!nestedAndPredicates.isEmpty()) { toPopulate.add(new KiePMMLFieldOperatorValue(null, BOOLEAN_OPERATOR.AND, Collections.emptyList(), nestedAndPredicates)); } if (!nestedOrPredicates.isEmpty()) { toPopulate.add(new KiePMMLFieldOperatorValue(null, BOOLEAN_OPERATOR.OR, Collections.emptyList(), nestedOrPredicates)); } } private  KiePMMLASTFactoryUtils(); static List<KiePMMLFieldOperatorValue> getConstraintEntriesFromAndOrCompoundPredicate(final CompoundPredicate compoundPredicate, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap); static List<KiePMMLFieldOperatorValue> getConstraintEntriesFromXOrCompoundPredicate(final CompoundPredicate compoundPredicate, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap); static KiePMMLFieldOperatorValue getConstraintEntryFromSimplePredicates(final String fieldName,
                                                                                   final BOOLEAN_OPERATOR containerOperator,
                                                                                   final List<SimplePredicate> simplePredicates,
                                                                                   final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap); static List<KiePMMLFieldOperatorValue> getXORConstraintEntryFromSimplePredicates(final List<Predicate> predicates, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap); static Object getCorrectlyFormattedObject(final SimplePredicate simplePredicate, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap);  }