@Test public void getKiePMMLCompoundPredicateSourcesMap() { KiePMMLSimplePredicate kiePMMLSimplePredicateInt = KiePMMLSimplePredicate .builder("SIMPLEPREDICATEINTNAME", Collections.emptyList(), OPERATOR.GREATER_OR_EQUAL) .withValue(24) .build(); KiePMMLSimplePredicate kiePMMLSimplePredicateString = KiePMMLSimplePredicate .builder("SIMPLEPREDICATESTRINGNAME", Collections.emptyList(), OPERATOR.GREATER_OR_EQUAL) .withValue("FOR") .build(); ARRAY_TYPE arrayType = ARRAY_TYPE.STRING; IN_NOTIN inNotIn = IN_NOTIN.IN; List<Object> values = getObjects(arrayType, 3); KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicate = KiePMMLSimpleSetPredicate .builder("SIMPLESETPREDICATE", Collections.emptyList(), arrayType, inNotIn) .withValues(values) .build(); List<KiePMMLPredicate> kiePMMLPredicates = Arrays.asList(kiePMMLSimplePredicateInt, kiePMMLSimplePredicateString, kiePMMLSimpleSetPredicate); KiePMMLCompoundPredicate kiePMMLCompoundPredicate = KiePMMLCompoundPredicate.builder(Collections.emptyList(), BOOLEAN_OPERATOR.OR) .withKiePMMLPredicates(kiePMMLPredicates) .build(); String packageName = "PACKAGENAME"; final Map<String, String> retrieved = KiePMMLPredicateFactory.getKiePMMLCompoundPredicateSourcesMap(kiePMMLCompoundPredicate, packageName); commonVerifySourceMap(retrieved, packageName, getSanitizedClassName(kiePMMLCompoundPredicate.getId()), 4); }
static Map<String, String> getKiePMMLCompoundPredicateSourcesMap(final KiePMMLCompoundPredicate kiePMMLCompoundPredicate, final String packageName) { String className = getSanitizedClassName(kiePMMLCompoundPredicate.getId()); final Map<String, String> toReturn = new HashMap<>(); if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) { kiePMMLCompoundPredicate.getKiePMMLPredicates().forEach(kiePMMLPredicate -> toReturn.putAll(getPredicateSourcesMap(kiePMMLPredicate, packageName))); } CompilationUnit cloneCU = JavaParserUtils.getKiePMMLModelCompilationUnit(className, packageName, KIE_PMML_COMPOUND_PREDICATE_TEMPLATE_JAVA, KIE_PMML_COMPOUND_PREDICATE_TEMPLATE); ClassOrInterfaceDeclaration predicateTemplate = cloneCU.getClassByName(className) .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className)); final ConstructorDeclaration constructorDeclaration = predicateTemplate.getDefaultConstructor() .orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, predicateTemplate.getName()))); Set<String> predicatesClasses = new HashSet<>(); if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) { predicatesClasses = kiePMMLCompoundPredicate.getKiePMMLPredicates().stream() .map(predicate -> packageName + "." + getSanitizedClassName(predicate.getId())) .collect(Collectors.toSet()); } if (!toReturn.keySet().containsAll(predicatesClasses)) { String missingClasses = String.join(", ", predicatesClasses); throw new KiePMMLException("Expected generated class " + missingClasses + " not found"); } setCompoundPredicateConstructor(className, kiePMMLCompoundPredicate.getName(), constructorDeclaration, kiePMMLCompoundPredicate.getBooleanOperator(), predicatesClasses); toReturn.put(getFullClassName(cloneCU), cloneCU.toString()); return toReturn; }
KiePMMLPredicateFactory { static Map<String, String> getKiePMMLCompoundPredicateSourcesMap(final KiePMMLCompoundPredicate kiePMMLCompoundPredicate, final String packageName) { String className = getSanitizedClassName(kiePMMLCompoundPredicate.getId()); final Map<String, String> toReturn = new HashMap<>(); if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) { kiePMMLCompoundPredicate.getKiePMMLPredicates().forEach(kiePMMLPredicate -> toReturn.putAll(getPredicateSourcesMap(kiePMMLPredicate, packageName))); } CompilationUnit cloneCU = JavaParserUtils.getKiePMMLModelCompilationUnit(className, packageName, KIE_PMML_COMPOUND_PREDICATE_TEMPLATE_JAVA, KIE_PMML_COMPOUND_PREDICATE_TEMPLATE); ClassOrInterfaceDeclaration predicateTemplate = cloneCU.getClassByName(className) .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className)); final ConstructorDeclaration constructorDeclaration = predicateTemplate.getDefaultConstructor() .orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, predicateTemplate.getName()))); Set<String> predicatesClasses = new HashSet<>(); if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) { predicatesClasses = kiePMMLCompoundPredicate.getKiePMMLPredicates().stream() .map(predicate -> packageName + "." + getSanitizedClassName(predicate.getId())) .collect(Collectors.toSet()); } if (!toReturn.keySet().containsAll(predicatesClasses)) { String missingClasses = String.join(", ", predicatesClasses); throw new KiePMMLException("Expected generated class " + missingClasses + " not found"); } setCompoundPredicateConstructor(className, kiePMMLCompoundPredicate.getName(), constructorDeclaration, kiePMMLCompoundPredicate.getBooleanOperator(), predicatesClasses); toReturn.put(getFullClassName(cloneCU), cloneCU.toString()); return toReturn; } }
KiePMMLPredicateFactory { static Map<String, String> getKiePMMLCompoundPredicateSourcesMap(final KiePMMLCompoundPredicate kiePMMLCompoundPredicate, final String packageName) { String className = getSanitizedClassName(kiePMMLCompoundPredicate.getId()); final Map<String, String> toReturn = new HashMap<>(); if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) { kiePMMLCompoundPredicate.getKiePMMLPredicates().forEach(kiePMMLPredicate -> toReturn.putAll(getPredicateSourcesMap(kiePMMLPredicate, packageName))); } CompilationUnit cloneCU = JavaParserUtils.getKiePMMLModelCompilationUnit(className, packageName, KIE_PMML_COMPOUND_PREDICATE_TEMPLATE_JAVA, KIE_PMML_COMPOUND_PREDICATE_TEMPLATE); ClassOrInterfaceDeclaration predicateTemplate = cloneCU.getClassByName(className) .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className)); final ConstructorDeclaration constructorDeclaration = predicateTemplate.getDefaultConstructor() .orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, predicateTemplate.getName()))); Set<String> predicatesClasses = new HashSet<>(); if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) { predicatesClasses = kiePMMLCompoundPredicate.getKiePMMLPredicates().stream() .map(predicate -> packageName + "." + getSanitizedClassName(predicate.getId())) .collect(Collectors.toSet()); } if (!toReturn.keySet().containsAll(predicatesClasses)) { String missingClasses = String.join(", ", predicatesClasses); throw new KiePMMLException("Expected generated class " + missingClasses + " not found"); } setCompoundPredicateConstructor(className, kiePMMLCompoundPredicate.getName(), constructorDeclaration, kiePMMLCompoundPredicate.getBooleanOperator(), predicatesClasses); toReturn.put(getFullClassName(cloneCU), cloneCU.toString()); return toReturn; } private  KiePMMLPredicateFactory(); }
KiePMMLPredicateFactory { static Map<String, String> getKiePMMLCompoundPredicateSourcesMap(final KiePMMLCompoundPredicate kiePMMLCompoundPredicate, final String packageName) { String className = getSanitizedClassName(kiePMMLCompoundPredicate.getId()); final Map<String, String> toReturn = new HashMap<>(); if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) { kiePMMLCompoundPredicate.getKiePMMLPredicates().forEach(kiePMMLPredicate -> toReturn.putAll(getPredicateSourcesMap(kiePMMLPredicate, packageName))); } CompilationUnit cloneCU = JavaParserUtils.getKiePMMLModelCompilationUnit(className, packageName, KIE_PMML_COMPOUND_PREDICATE_TEMPLATE_JAVA, KIE_PMML_COMPOUND_PREDICATE_TEMPLATE); ClassOrInterfaceDeclaration predicateTemplate = cloneCU.getClassByName(className) .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className)); final ConstructorDeclaration constructorDeclaration = predicateTemplate.getDefaultConstructor() .orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, predicateTemplate.getName()))); Set<String> predicatesClasses = new HashSet<>(); if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) { predicatesClasses = kiePMMLCompoundPredicate.getKiePMMLPredicates().stream() .map(predicate -> packageName + "." + getSanitizedClassName(predicate.getId())) .collect(Collectors.toSet()); } if (!toReturn.keySet().containsAll(predicatesClasses)) { String missingClasses = String.join(", ", predicatesClasses); throw new KiePMMLException("Expected generated class " + missingClasses + " not found"); } setCompoundPredicateConstructor(className, kiePMMLCompoundPredicate.getName(), constructorDeclaration, kiePMMLCompoundPredicate.getBooleanOperator(), predicatesClasses); toReturn.put(getFullClassName(cloneCU), cloneCU.toString()); return toReturn; } private  KiePMMLPredicateFactory(); static List<KiePMMLPredicate> getPredicates(List<Predicate> predicates, DataDictionary dataDictionary); static KiePMMLPredicate getPredicate(Predicate predicate, DataDictionary dataDictionary); static KiePMMLSimplePredicate getKiePMMLSimplePredicate(SimplePredicate predicate, DataType dataType); static KiePMMLSimpleSetPredicate getKiePMMLSimpleSetPredicate(SimpleSetPredicate predicate); static KiePMMLCompoundPredicate getKiePMMLCompoundPredicate(CompoundPredicate predicate,
                                                                       DataDictionary dataDictionary); static KiePMMLTruePredicate getKiePMMLTruePredicate(); static KiePMMLFalsePredicate getKiePMMLFalsePredicate(); static Map<String, String> getPredicateSourcesMap(final KiePMMLPredicate kiePMMLPredicate,
                                                             final String packageName); }
KiePMMLPredicateFactory { static Map<String, String> getKiePMMLCompoundPredicateSourcesMap(final KiePMMLCompoundPredicate kiePMMLCompoundPredicate, final String packageName) { String className = getSanitizedClassName(kiePMMLCompoundPredicate.getId()); final Map<String, String> toReturn = new HashMap<>(); if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) { kiePMMLCompoundPredicate.getKiePMMLPredicates().forEach(kiePMMLPredicate -> toReturn.putAll(getPredicateSourcesMap(kiePMMLPredicate, packageName))); } CompilationUnit cloneCU = JavaParserUtils.getKiePMMLModelCompilationUnit(className, packageName, KIE_PMML_COMPOUND_PREDICATE_TEMPLATE_JAVA, KIE_PMML_COMPOUND_PREDICATE_TEMPLATE); ClassOrInterfaceDeclaration predicateTemplate = cloneCU.getClassByName(className) .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className)); final ConstructorDeclaration constructorDeclaration = predicateTemplate.getDefaultConstructor() .orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, predicateTemplate.getName()))); Set<String> predicatesClasses = new HashSet<>(); if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) { predicatesClasses = kiePMMLCompoundPredicate.getKiePMMLPredicates().stream() .map(predicate -> packageName + "." + getSanitizedClassName(predicate.getId())) .collect(Collectors.toSet()); } if (!toReturn.keySet().containsAll(predicatesClasses)) { String missingClasses = String.join(", ", predicatesClasses); throw new KiePMMLException("Expected generated class " + missingClasses + " not found"); } setCompoundPredicateConstructor(className, kiePMMLCompoundPredicate.getName(), constructorDeclaration, kiePMMLCompoundPredicate.getBooleanOperator(), predicatesClasses); toReturn.put(getFullClassName(cloneCU), cloneCU.toString()); return toReturn; } private  KiePMMLPredicateFactory(); static List<KiePMMLPredicate> getPredicates(List<Predicate> predicates, DataDictionary dataDictionary); static KiePMMLPredicate getPredicate(Predicate predicate, DataDictionary dataDictionary); static KiePMMLSimplePredicate getKiePMMLSimplePredicate(SimplePredicate predicate, DataType dataType); static KiePMMLSimpleSetPredicate getKiePMMLSimpleSetPredicate(SimpleSetPredicate predicate); static KiePMMLCompoundPredicate getKiePMMLCompoundPredicate(CompoundPredicate predicate,
                                                                       DataDictionary dataDictionary); static KiePMMLTruePredicate getKiePMMLTruePredicate(); static KiePMMLFalsePredicate getKiePMMLFalsePredicate(); static Map<String, String> getPredicateSourcesMap(final KiePMMLPredicate kiePMMLPredicate,
                                                             final String packageName);  }