use of org.kie.pmml.commons.HasRule in project drools by kiegroup.
the class PMMLCompilerService method addPMMLRuleMapper.
static void addPMMLRuleMapper(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 (kiePMMLModel instanceof HasRule) {
String pkgUUID = ((HasRule) kiePMMLModel).getPkgUUID();
String rulesFileName = kiePMMLModel.getKModulePackageName() + "." + RULES_FILE_NAME + pkgUUID;
String pmmlRuleMapper = kiePMMLModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME;
String ruleMapperSource = PMMLRuleMapperFactory.getPMMLRuleMapperSource(rulesFileName);
((HasRule) kiePMMLModel).addSourceMap(pmmlRuleMapper, ruleMapperSource);
generatedRuleMappers.add(pmmlRuleMapper);
}
if (kiePMMLModel instanceof HasNestedModels) {
for (KiePMMLModel nestedModel : ((HasNestedModels) kiePMMLModel).getNestedModels()) {
addPMMLRuleMapper(nestedModel, generatedRuleMappers, sourcePath);
}
}
}
use of org.kie.pmml.commons.HasRule in project drools by kiegroup.
the class PMMLCompilerServiceTest method populateWithPMMLRuleMappers.
@Test
public void populateWithPMMLRuleMappers() {
final List<KiePMMLModel> toPopulate = new ArrayList<>();
toPopulate.add(new KiePMMLTestingModelWithSources("TEST", "kmodulePackageName", Collections.emptyMap()));
toPopulate.add(new KiePMMLModelHasRule("TEST", Collections.emptyList()));
toPopulate.add(new KiePMMLModelHasNestedModelsHasRule("TEST", Collections.emptyList()));
toPopulate.add(new KiePMMLModelHasNestedModelsHasSourceMap("TEST", Collections.emptyList()));
toPopulate.forEach(kiePMMLModel -> assertTrue(((HasSourcesMap) kiePMMLModel).getSourcesMap().isEmpty()));
final File file = new File("foo.pmml");
final Resource resource = new FileSystemResource(file);
PMMLCompilerService.populateWithPMMLRuleMappers(toPopulate, resource);
toPopulate.forEach(kiePmmlModel -> {
if (kiePmmlModel instanceof HasRule || kiePmmlModel instanceof KiePMMLModelHasNestedModelsHasRule) {
assertFalse(((HasSourcesMap) kiePmmlModel).getSourcesMap().isEmpty());
String expected = kiePmmlModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPERS_CLASS_NAME;
assertTrue(((HasSourcesMap) kiePmmlModel).getSourcesMap().containsKey(expected));
if (kiePmmlModel instanceof HasRule) {
expected = kiePmmlModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME;
assertTrue(((HasSourcesMap) kiePmmlModel).getSourcesMap().containsKey(expected));
}
} else {
assertTrue(((HasSourcesMap) kiePmmlModel).getSourcesMap().isEmpty());
}
});
}
Aggregations