use of org.drools.modelcompiler.builder.PackageSources in project drools by kiegroup.
the class DroolsModelProvider method generateRulesFiles.
/**
* This method depends on exec-model. Be aware in case of refactoring
* @param packageDescr
* @return
*/
protected List<GeneratedFile> generateRulesFiles(PackageDescr packageDescr) {
ModelBuilderImpl<PackageSources> modelBuilder = new ModelBuilderImpl<>(PackageSources::dumpSources, new KnowledgeBuilderConfigurationImpl(getClass().getClassLoader()), new ReleaseIdImpl("dummy:dummy:0.0.0"), false);
CompositeKnowledgeBuilder batch = modelBuilder.batch();
batch.add(new DescrResource(packageDescr), ResourceType.DESCR);
try {
batch.build();
if (modelBuilder.hasErrors()) {
StringBuilder builder = new StringBuilder();
for (DroolsError error : modelBuilder.getErrors().getErrors()) {
logger.error(error.toString());
builder.append(error.toString()).append(" ");
}
throw new KiePMMLException(builder.toString());
}
} catch (Exception e) {
logger.error(e.getMessage());
StringBuilder builder = new StringBuilder(e.getMessage()).append(" ");
for (DroolsError error : modelBuilder.getErrors().getErrors()) {
logger.error(error.toString());
builder.append(error.toString()).append(" ");
}
throw new RuntimeException(builder.toString(), e);
}
return generateModels(modelBuilder).stream().map(f -> new GeneratedFile(GeneratedFile.Type.RULE, f.getPath(), new String(f.getData()))).collect(toList());
}
Aggregations