PMMLCompilerService { static void addPMMLRuleMappers(final KiePMMLModel kiePMMLModel, final List<String> generatedRuleMappers, final String sourcePath) { if (!(kiePMMLModel instanceof HasSourcesMap)) { String errorMessage = String.format("Expecting HasSourcesMap instance, retrieved %s inside %s", kiePMMLModel.getClass().getName(), sourcePath); throw new KiePMMLException(errorMessage); } if (generatedRuleMappers.isEmpty()) { return; } String predictionRuleMapper = kiePMMLModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPERS_CLASS_NAME; String ruleMapperSource = PMMLRuleMappersFactory.getPMMLRuleMappersSource(kiePMMLModel.getKModulePackageName(), generatedRuleMappers); ((HasSourcesMap) kiePMMLModel).addSourceMap(predictionRuleMapper, ruleMapperSource); } private  PMMLCompilerService(); static List<KiePMMLModel> getKiePMMLModelsFromResourcesWithConfigurationsFromPlugin(KnowledgeBuilderImpl kbuilderImpl, Collection<ResourceWithConfiguration> resourceWithConfigurations); static List<KiePMMLModel> getKiePMMLModelsCompiledFromResourcesWithConfigurations(KnowledgeBuilderImpl kbuilderImpl, Collection<ResourceWithConfiguration> resourceWithConfigurations); static List<KiePMMLModel> getKiePMMLModelsCompiledFromResource(KnowledgeBuilderImpl kbuilderImpl,
                                                                          Resource resource); static List<KiePMMLModel> getKiePMMLModelsFromResourceFromPlugin(KnowledgeBuilderImpl kbuilderImpl,
                                                                            Resource resource);  }
@Test public void addPMMLRuleMappersHasSourceMap() { KiePMMLModelHasSourceMap kiePmmlModel = new KiePMMLModelHasSourceMap("TEST", Collections.emptyList()); assertTrue(kiePmmlModel.sourcesMap.isEmpty()); final List<String> generatedRuleMappers = IntStream.range(0, 3) .mapToObj(i -> "apackage" + i + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME).collect(Collectors.toList()); PMMLCompilerService.addPMMLRuleMappers(kiePmmlModel, generatedRuleMappers, "source_path"); assertFalse(kiePmmlModel.sourcesMap.isEmpty()); String expected = kiePmmlModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPERS_CLASS_NAME; assertTrue(kiePmmlModel.sourcesMap.containsKey(expected)); }
@Test(expected = KiePMMLException.class) public void addPMMLRuleMappersNotHasSourceMap() { final KiePMMLModel kiePmmlModel = getKiePMMLModel(); final List<String> generatedRuleMappers = IntStream.range(0, 3) .mapToObj(i -> "apackage" + i + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME).collect(Collectors.toList()); PMMLCompilerService.addPMMLRuleMappers(kiePmmlModel, generatedRuleMappers, "source_path"); }