KiePMMLSegmentationFactory { public static Map<String, String> getSegmentationSourcesMap(final String parentPackageName, final DataDictionary dataDictionary, final TransformationDictionary transformationDictionary, final Segmentation segmentation, final String segmentationName, final KnowledgeBuilder kBuilder, final List<KiePMMLModel> nestedModels) { logger.debug("getSegmentationSourcesMap {}", segmentation); final String packageName = getSanitizedPackageName(parentPackageName + "." + segmentationName); final Map<String, String> toReturn = getSegmentsSourcesMap(packageName, dataDictionary, transformationDictionary, segmentation.getSegments(), kBuilder, nestedModels); String className = getSanitizedClassName(segmentationName); CompilationUnit cloneCU = JavaParserUtils.getKiePMMLModelCompilationUnit(className, packageName, KIE_PMML_SEGMENTATION_TEMPLATE_JAVA, KIE_PMML_SEGMENTATION_TEMPLATE); ClassOrInterfaceDeclaration segmentationTemplate = cloneCU.getClassByName(className) .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className)); final ConstructorDeclaration constructorDeclaration = segmentationTemplate.getDefaultConstructor().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, segmentationName))); Set<String> segmentsClasses = segmentation.getSegments().stream() .map(segment -> getSanitizedPackageName(packageName + "." + segment.getId()) + "." + getSanitizedClassName(segment.getId())) .collect(Collectors.toSet()); if (!toReturn.keySet().containsAll(segmentsClasses)) { String missingClasses = String.join(", ", segmentsClasses); throw new KiePMMLException("Expected generated class " + missingClasses + " not found"); } setConstructor(className, segmentationName, constructorDeclaration, MULTIPLE_MODEL_METHOD.byName(segmentation.getMultipleModelMethod().value()), segmentsClasses); toReturn.put(getFullClassName(cloneCU), cloneCU.toString()); return toReturn; } private  KiePMMLSegmentationFactory(); static KiePMMLSegmentation getSegmentation(final DataDictionary dataDictionary,
                                                      final TransformationDictionary transformationDictionary,
                                                      final Segmentation segmentation,
                                                      final String segmentationName,
                                                      final KnowledgeBuilder kBuilder); static Map<String, String> getSegmentationSourcesMap(final String parentPackageName,
                                                                final DataDictionary dataDictionary,
                                                                final TransformationDictionary transformationDictionary,
                                                                final Segmentation segmentation,
                                                                final String segmentationName,
                                                                final KnowledgeBuilder kBuilder,
                                                                final List<KiePMMLModel> nestedModels);  }
@Test public void getSegmentationSourcesMap() { final String segmentationName = "SEGMENTATION_NAME"; final String packageName = "packagename"; final List<KiePMMLModel> nestedModels = new ArrayList<>(); final Map<String, String> retrieved = KiePMMLSegmentationFactory.getSegmentationSourcesMap(packageName, DATA_DICTIONARY, TRANSFORMATION_DICTIONARY, MINING_MODEL.getSegmentation(), segmentationName, KNOWLEDGE_BUILDER, nestedModels); assertNotNull(retrieved); int expectedNestedModels = MINING_MODEL.getSegmentation().getSegments().size(); assertEquals(expectedNestedModels, nestedModels.size()); }