Search in sources :

Example 1 with HasRule

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);
        }
    }
}
Also used : HasRule(org.kie.pmml.commons.HasRule) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) HasNestedModels(org.kie.pmml.commons.model.HasNestedModels) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) HasSourcesMap(org.kie.pmml.commons.model.HasSourcesMap)

Example 2 with HasRule

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());
        }
    });
}
Also used : KiePMMLTestingModelWithSources(org.kie.pmml.commons.testingutility.KiePMMLTestingModelWithSources) ArrayList(java.util.ArrayList) FileSystemResource(org.drools.core.io.impl.FileSystemResource) Resource(org.kie.api.io.Resource) FileSystemResource(org.drools.core.io.impl.FileSystemResource) HasRule(org.kie.pmml.commons.HasRule) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) HasSourcesMap(org.kie.pmml.commons.model.HasSourcesMap) File(java.io.File) Test(org.junit.Test)

Aggregations

HasRule (org.kie.pmml.commons.HasRule)2 HasSourcesMap (org.kie.pmml.commons.model.HasSourcesMap)2 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 FileSystemResource (org.drools.core.io.impl.FileSystemResource)1 Test (org.junit.Test)1 Resource (org.kie.api.io.Resource)1 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)1 HasNestedModels (org.kie.pmml.commons.model.HasNestedModels)1 KiePMMLTestingModelWithSources (org.kie.pmml.commons.testingutility.KiePMMLTestingModelWithSources)1