本文整理汇总了Java中org.kie.api.builder.KieBuilder类的典型用法代码示例。如果您正苦于以下问题:Java KieBuilder类的具体用法?Java KieBuilder怎么用?Java KieBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KieBuilder类属于org.kie.api.builder包,在下文中一共展示了KieBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initKie
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
private void initKie() {
KieServices ks = KieServices.Factory.get();
kfs = ks.newKieFileSystem();
uploadDroolFiles();
KieBuilder kbuilder = ks.newKieBuilder(kfs);
kbuilder.buildAll();
if (kbuilder.getResults().hasMessages(Level.ERROR)) {
throw new IllegalArgumentException(kbuilder.getResults().toString());
}
KieContainer kcontainer = ks.newKieContainer(kbuilder.getKieModule().getReleaseId());
KieBaseConfiguration kbConfig = KieServices.Factory.get().newKieBaseConfiguration();
kbConfig.setOption(ConstraintJittingThresholdOption.get(-1));
kbase = kcontainer.newKieBase(kbConfig);
}
示例2: createKJar
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
public static byte[] createKJar(ReleaseId releaseId, List<String> drls) {
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId);
drls.forEach(drl -> kfs.write("src/main/resources/" + drl.hashCode() + ".drl", drl));
KieBuilder kb = kieServices.newKieBuilder(kfs).buildAll();
if (kb.getResults().hasMessages(Message.Level.ERROR)) {
for (Message result : kb.getResults().getMessages()) {
System.out.println(result.getText());
}
return null;
}
InternalKieModule kieModule = (InternalKieModule) kieServices.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
return jar;
}
示例3: loadContainerFromString
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
private KieContainer loadContainerFromString(List<Rule> rules) {
long startTime = System.currentTimeMillis();
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();
for (Rule rule:rules) {
String drl=rule.getContent();
kfs.write("src/main/resources/" + drl.hashCode() + ".drl", drl);
}
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
if (kb.getResults().hasMessages(Message.Level.ERROR)) {
throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
}
long endTime = System.currentTimeMillis();
System.out.println("Time to build rules : " + (endTime - startTime) + " ms" );
startTime = System.currentTimeMillis();
KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
endTime = System.currentTimeMillis();
System.out.println("Time to load container: " + (endTime - startTime) + " ms" );
return kContainer;
}
示例4: createKieContainer
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
private KieContainer createKieContainer(String... ruleFiles) {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
for (String ruleFile : ruleFiles) {
InputStream ruleFileIs = DroolsTestSupport.class.getResourceAsStream("/" + ruleFile);
Assert.assertNotNull("Can't open stream for rule file. Does it exist?", ruleFileIs);
kfs.write(ks.getResources().newInputStreamResource(ruleFileIs).setSourcePath(ruleFile));
try {
ruleFileIs.close();
} catch (IOException e) {
throw new RuntimeException("InputStream of rule file could not be closed.");
}
}
kieBuilder.buildAll();
StringBuilder message = new StringBuilder();
List<Message> messages = kieBuilder.getResults().getMessages();
for (Message m : messages) {
message.append(m.toString()).append("\n");
}
Assert.assertEquals(message.toString(), 0, messages.size());
return ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
}
示例5: generateRelease
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
private ReleaseId generateRelease(Collection<Precondition> preconditionsToAdd, Collection<Precondition> preconditionsToRemove) throws EngineException {
if (services == null) {
throw new IllegalStateException("Engine not initialized.");
}
ReleaseId release = services.newReleaseId(RELEASE_GROUP_ID, RELEASE_ARTIFACT_ID, String.valueOf(versionNumber++));
if (preconditionsToAdd != null) {
addPreconditionsRules(preconditionsToAdd);
}
if (preconditionsToRemove != null) {
deletePreconditionRules(preconditionsToRemove);
}
fileSystem.generateAndWritePomXML(release);
KieBuilder builder = services.newKieBuilder(fileSystem);
builder.buildAll();
if (builder.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
// TODO - Check if the error is due to wrong evaluation string specifications and launch a specific exception
throw new EngineException("Engine errors:\n" + builder.getResults().toString());
}
return release;
}
示例6: getKieSession
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
/** create empty knowledge base */
private KieSession getKieSession() {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieResources kieResources = ks.getResources();
kfs.write(kieResources.newClassPathResource("getOlder.drl", getClass()).setResourceType(ResourceType.DRL));
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
if (!errors.isEmpty()) {
fail("" + errors);
}
return ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
}
示例7: registerKnowledgeRuntime
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
protected KieSession registerKnowledgeRuntime(String identifier, String rule) {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieResources kieResources = ks.getResources();
if (rule != null && rule.length() > 0) {
kfs.write("src/main/resources/rule.drl", rule);
}
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
if (!errors.isEmpty()) {
fail("" + errors);
}
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
try {
jndiContext.bind(identifier, ksession);
} catch (NamingException e) {
throw new RuntimeException(e);
}
return ksession;
}
示例8: initKieJar
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
/**
* 初始化一个kjar:把原有的drl包含进新建的kjar中
*
* @param ks
* @param releaseId
* @return
* @throws IOException
*/
public static InternalKieModule initKieJar(KieServices ks, ReleaseId releaseId) throws IOException {
KieFileSystem kfs = createKieFileSystemWithKProject(ks, true);
kfs.writePomXML(getPom(releaseId));
for (File file : getRuleFiles()) {
kfs.write("src/main/resources/" + file.getName(),
ResourceFactory.newClassPathResource(RULES_PATH + File.separator + file.getName(), "UTF-8"));
}
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
if (!kieBuilder.buildAll().getResults().getMessages().isEmpty()) {
throw new IllegalStateException("Error creating KieBuilder.");
}
return (InternalKieModule) kieBuilder.getKieModule();
}
示例9: createKieJar
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
public static InternalKieModule createKieJar(KieServices ks, ReleaseId releaseId, ResourceWrapper resourceWrapper) {
KieFileSystem kfs = createKieFileSystemWithKProject(ks, true);
kfs.writePomXML(getPom(releaseId));
kfs.write("src/main/resources/" + resourceWrapper.getTargetResourceName(), resourceWrapper.getResource());
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
if (!kieBuilder.getResults().getMessages().isEmpty()) {
System.out.println(kieBuilder.getResults().getMessages());
throw new IllegalStateException("Error creating KieBuilder.");
}
return (InternalKieModule) kieBuilder.getKieModule();
}
示例10: addRuleSet
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
public void addRuleSet(String ruleSetName, File ruleSetDirectory) throws RuleExecutorException {
// Create the in-memory File System and add the resources files to it
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
try {
final RuleLoader ruleLoader = new RuleLoader(kieFileSystem);
Files.walkFileTree(ruleSetDirectory.toPath(), ruleLoader);
int rulesLoaded = ruleLoader.getRulesLoaded();
if (rulesLoaded == 0) {
logger.warn("No rules loaded. Rules directory: {}", ruleSetDirectory.getAbsolutePath());
} else {
logger.info("{} rules loaded.", ruleLoader.getRulesLoaded());
totalRulesLoaded += rulesLoaded;
}
} catch (IOException e) {
throw new RuleExecutorException("Failed to load rule set " + ruleSetName, e);
}
// Create the builder for the resources of the File System
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
// Build the KieBases
kieBuilder.buildAll();
// Check for errors
if (kieBuilder.getResults().hasMessages(Message.Level.ERROR)) {
throw new RuleExecutorException(kieBuilder.getResults().toString());
}
// Get the Release ID (mvn style: groupId, artifactId,version)
ReleaseId relId = kieBuilder.getKieModule().getReleaseId();
// Create the Container, wrapping the KieModule with the given ReleaseId
ruleSetContainers.put(ruleSetName, kieServices.newKieContainer(relId));
}
示例11: kieContainer
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(KieContainer.class)
public KieContainer kieContainer() throws IOException {
final KieRepository kieRepository = getKieServices().getRepository();
kieRepository.addKieModule(new KieModule() {
public ReleaseId getReleaseId() {
return kieRepository.getDefaultReleaseId();
}
});
KieBuilder kieBuilder = getKieServices().newKieBuilder(kieFileSystem());
kieBuilder.buildAll();
return getKieServices().newKieContainer(kieRepository.getDefaultReleaseId());
}
示例12: DecisionTableKieBaseProvider
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
public DecisionTableKieBaseProvider() {
KieServices kieServices = KieServices.Factory.get();
KieRepository kieRepository = kieServices.getRepository();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
//addResource(kieFileSystem, "com.redhatbank.brms.tracktrace.model.SLACriteria.gdst");
addResource(kieFileSystem, "org.acme.insurance.TestDS.xls");
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
for (Message message : kieBuilder.getResults().getMessages()) {
System.out.println(message);
}
kieContainer = kieServices.newKieContainer(kieRepository.getDefaultReleaseId());
}
示例13: getStatelessKieSessionFromResource
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
private StatelessKieSession getStatelessKieSessionFromResource(Resource resource) {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(resource);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
if (!errors.isEmpty()) {
fail("" + errors);
}
return ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newStatelessKieSession();
}
示例14: getKieSessionFromResource
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
private KieSession getKieSessionFromResource(Resource resource) {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(resource);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
if (!errors.isEmpty()) {
fail("" + errors);
}
return ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
}
示例15: registerKnowledgeRuntime
import org.kie.api.builder.KieBuilder; //导入依赖的package包/类
@Override
protected KieSession registerKnowledgeRuntime(String identifier, String rule) {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieResources kieResources = ks.getResources();
Options xjcOpts = new Options();
xjcOpts.setSchemaLanguage(Language.XMLSCHEMA);
JaxbConfiguration jaxbConfiguration = KnowledgeBuilderFactory.newJaxbConfiguration(xjcOpts, "xsd");
kfs.write(kieResources.newClassPathResource("person.xsd", getClass()).setResourceType(ResourceType.XSD).setConfiguration(jaxbConfiguration));
if (rule != null && rule.length() > 0) {
kfs.write("src/main/resources/rule.drl", rule);
}
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
if (!errors.isEmpty()) {
fail("" + errors);
}
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
classLoader = ((KnowledgeBaseImpl)ksession.getKieBase()).getRootClassLoader();
try {
jndiContext.bind(identifier, ksession);
} catch (NamingException e) {
throw new RuntimeException(e);
}
return ksession;
}