use of org.drools.KnowledgeBase in project Activiti by Activiti.
the class RulesDeployer method deploy.
public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) {
log.debug("Processing deployment {}", deployment.getName());
KnowledgeBuilder knowledgeBuilder = null;
DeploymentManager deploymentManager = Context.getProcessEngineConfiguration().getDeploymentManager();
Map<String, ResourceEntity> resources = deployment.getResources();
for (String resourceName : resources.keySet()) {
log.info("Processing resource {}", resourceName);
if (resourceName.endsWith(".drl")) {
// is only parsing .drls sufficient? what about other rule dsl's? (@see ResourceType)
if (knowledgeBuilder == null) {
knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
}
ResourceEntity resourceEntity = resources.get(resourceName);
byte[] resourceBytes = resourceEntity.getBytes();
Resource droolsResource = ResourceFactory.newByteArrayResource(resourceBytes);
knowledgeBuilder.add(droolsResource, ResourceType.DRL);
}
}
if (knowledgeBuilder != null) {
KnowledgeBase knowledgeBase = knowledgeBuilder.newKnowledgeBase();
deploymentManager.getKnowledgeBaseCache().add(deployment.getId(), knowledgeBase);
}
}
use of org.drools.KnowledgeBase in project sling by apache.
the class AbstractUsingBundleListMojo method createKnowledgeBase.
private KnowledgeBase createKnowledgeBase(File[] files) throws MojoExecutionException {
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
builder.add(ResourceFactory.newClassPathResource("drools-globals.drl", getClass()), ResourceType.DRL);
for (File file : files) {
getLog().info("Parsing rule file " + file.getAbsolutePath());
builder.add(ResourceFactory.newFileResource(file), ResourceType.DRL);
}
if (builder.hasErrors()) {
getLog().error("Rule errors:");
for (KnowledgeBuilderError error : builder.getErrors()) {
getLog().error(error.toString());
}
throw new MojoExecutionException("Unable to create rules. See log for details.");
}
KnowledgeBase base = KnowledgeBaseFactory.newKnowledgeBase();
base.addKnowledgePackages(builder.getKnowledgePackages());
return base;
}
Aggregations