本文整理汇总了Java中org.kie.api.io.ResourceType类的典型用法代码示例。如果您正苦于以下问题:Java ResourceType类的具体用法?Java ResourceType怎么用?Java ResourceType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceType类属于org.kie.api.io包,在下文中一共展示了ResourceType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addRule
import org.kie.api.io.ResourceType; //导入依赖的package包/类
/**
* 单一规则上线
*
* @param packageName
* @param ruleName
*/
public void addRule(String packageName, String ruleName) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(packageName + "/" + ruleName + ".drl"), ResourceType.DRL);
if (kbuilder.hasErrors()) {
logger.error("Unable to compile drl. " + packageName + ruleName + ".drl");
return;
} else {
if (kbase.getRule(packageName, ruleName) != null) {
logger.info("update rule: " + packageName + "." + ruleName);
} else {
logger.info("add rule: " + packageName + "." + ruleName);
}
}
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
kieSession = kbase.newStatelessKieSession();
setGlobal();
printRules();
}
示例2: getRuntimeManager
import org.kie.api.io.ResourceType; //导入依赖的package包/类
/**
*
* Create the runtime manager for the process in the classpath
*
* @return
*/
public static RuntimeManager getRuntimeManager() {
setupPoolingDataSource();
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("org.jbpm.persistence.jpa");
RuntimeEnvironment env = RuntimeEnvironmentBuilder.Factory
.get()
.newDefaultBuilder()
.entityManagerFactory(emf)
.addAsset(
ResourceFactory
.newClassPathResource("helloProcess.bpmn2"),
ResourceType.BPMN2).get();
RuntimeManager manager = RuntimeManagerFactory.Factory.get()
.newSingletonRuntimeManager(env);
return manager;
}
示例3: testCallService
import org.kie.api.io.ResourceType; //导入依赖的package包/类
@Test
public void testCallService() throws Exception {
final Holder holder = new Holder();
serviceDomain.registerService(new QName("CallService"), new InOnlyService(), new BaseHandler(){
public void handleMessage(Exchange exchange) throws HandlerException {
holder.setValue("message handled");
}
});
serviceDomain.registerServiceReference(new QName("CallService"), new InOnlyService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(CALL_SERVICE_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
ksession.startProcess("CallService");
ksession.halt();
ksession.dispose();
Assert.assertEquals("message handled", holder.getValue());
}
示例4: runFaultBoundaryProcess
import org.kie.api.io.ResourceType; //导入依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
String output = (String)wpi.getVariable("TestOutput");
Assert.assertEquals(bomb ? "Failure" : "Success", output);
ksession.halt();
ksession.dispose();
}
示例5: testCallService
import org.kie.api.io.ResourceType; //导入依赖的package包/类
@Test
public void testCallService() throws Exception {
final Holder holder = new Holder();
serviceDomain.registerService(new QName("CallService"), new InOnlyService(), new BaseHandler() {
public void handleMessage(Exchange exchange) throws HandlerException {
holder.setValue("message handled");
}
});
serviceDomain.registerServiceReference(new QName("CallService"), new InOnlyService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(CALL_SERVICE_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
ksession.startProcess("CallService");
ksession.halt();
ksession.dispose();
Assert.assertEquals("message handled", holder.getValue());
}
示例6: runFaultBoundaryProcess
import org.kie.api.io.ResourceType; //导入依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler() {
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
String output = (String)wpi.getVariable("TestOutput");
Assert.assertEquals(bomb ? "Failure" : "Success", output);
ksession.halt();
ksession.dispose();
}
示例7: getKieSession
import org.kie.api.io.ResourceType; //导入依赖的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();
}
示例8: testSelect
import org.kie.api.io.ResourceType; //导入依赖的package包/类
@Test
public void testSelect() throws Exception {
KieHelper kieHelper = new KieHelper();
kieHelper.addResource(new ClassPathResource(PROCESS_DEFINITION, getClass()), ResourceType.BPMN2);
KieBase kbase = kieHelper.build();
KieSession kieSession = kbase.newKieSession();
kieSession.getWorkItemManager().registerWorkItemHandler("CamelSql", handler);
String sqlQuery = "select * from TEST";
Map<String, Object> params = new HashMap<String, Object>();
params.put("Query", sqlQuery);
params.put("DataSource", "myDs");
WorkflowProcessInstance wpi = (WorkflowProcessInstance)kieSession.startProcess("camelSqlProcess", params);
List<Map<String, Object>> result = (List<Map<String, Object>>)wpi.getVariable("QueryResult");
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
int id = (Integer)result.get(0).get("ID");
String name = (String)result.get(0).get("NAME");
Assert.assertEquals(1, id);
Assert.assertEquals("test", name);
}
示例9: drlSyntaxTest
import org.kie.api.io.ResourceType; //导入依赖的package包/类
@Test
public void drlSyntaxTest()
{
String str = "";
str += "package org.kie.test\n";
str += "global java.util.List list\n";
str += "rule rule1\n";
str += "when\n";
str += " Integer(intValue > 0)\n";
str += "then\n";
str += " list.add( 1 );\n";
str += "end\n";
str += "\n";
Map<String,String> drls = new HashMap<String,String>();
drls.put("rule1", str);
KieHelper kieHelper = new KieHelper();
for (String ruleId : drls.keySet()) {
kieHelper.addContent(drls.get(ruleId), ResourceType.DRL);
}
Results results = kieHelper.verify();
for (Message message : results.getMessages()) {
log.error(">> Message ({}): {}", message.getLevel(), message.getText());
}
if (results.hasMessages(Message.Level.ERROR)) {
throw new IllegalStateException("There are errors in the KB.");
}
KieSession ksession = kieHelper.build().newKieSession();
}
示例10: readFilenamesFromDirectory
import org.kie.api.io.ResourceType; //导入依赖的package包/类
private Boolean readFilenamesFromDirectory(String rootFilePath) {
Boolean compileOk = true;
final File folder = new File(rootFilePath);
final File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
try {
String ruleText = getFileAsText(listOfFiles[i]);
KieHelper kieHelper = new KieHelper();
kieHelper.addContent(ruleText, ResourceType.DRL);
Results results = kieHelper.verify();
for (Message message : results.getMessages()) {
log.error(">> Message ({}): {}", message.getLevel(), message.getText());
compileOk = false;
assertTrue("Drools Compile Error in "+listOfFiles[i].getName(),false);
}
} catch (final IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
readFilenamesFromDirectory(rootFilePath+"/"+listOfFiles[i].getName());
}
}
return compileOk;
}
示例11: addPackage
import org.kie.api.io.ResourceType; //导入依赖的package包/类
/**
* 规则集上线
*
* @param packageName
*/
public void addPackage(String packageName) {
try {
File path = new File(this.getClass().getClassLoader().getResource(packageName).toURI().getPath());
if (path.isDirectory()) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
File[] files = path.listFiles();
for (File file : files) {
if (file.getName().endsWith(".drl")) {
kbuilder.add(ResourceFactory.newClassPathResource(packageName + "/" + file.getName()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
logger.error("Unable to compile drl. " + packageName + file.getName());
return;
} else {
String ruleName = file.getName().replace(".drl", "");
if (kbase.getRule(packageName, ruleName) != null) {
logger.info("update rule: " + packageName + "." + ruleName);
} else {
logger.info("add rule: " + packageName + "." + ruleName);
}
}
}
}
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
kieSession = kbase.newStatelessKieSession();
setGlobal();
printRules();
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
示例12: validateRules
import org.kie.api.io.ResourceType; //导入依赖的package包/类
public static List<String> validateRules(InputStream resource) throws Exception {
VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
Verifier verifier = vBuilder.newVerifier();
verifier.addResourcesToVerify(new InputStreamResource(resource, "UTF8"), ResourceType.DRL);
List<String> errorList = new ArrayList<>();
for (int i = 0; i < verifier.getErrors().size(); i++)
{
errorList.add(verifier.getErrors().get(i).getMessage());
}
return errorList;
}
示例13: buildKieBase
import org.kie.api.io.ResourceType; //导入依赖的package包/类
private KieBase buildKieBase(Map<Resource, ResourceType> resources) {
KieHelper kieHelper = new KieHelper();
for (Map.Entry<Resource, ResourceType> entrySet : resources.entrySet()) {
kieHelper.addResource(entrySet.getKey(), entrySet.getValue());
}
this.assertBuildResults(kieHelper.verify());
return kieHelper.build();
}
示例14: updateConditions
import org.kie.api.io.ResourceType; //导入依赖的package包/类
public void updateConditions(String expiration, Collection<FullTrigger> activeTriggers) {
expression = new Expression(expiration, activeTriggers);
log.debugf("Rules: \n %s", expression);
stop();
KieBaseConfiguration kieBaseConfiguration = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kieBaseConfiguration.setOption( EventProcessingOption.STREAM );
KieBase kieBase = new KieHelper().addContent(expression.getDrl(), ResourceType.DRL).build(kieBaseConfiguration);
KieSessionConfiguration kieSessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
kieSessionConf.setOption( ClockTypeOption.get( "realtime" ) );
kieSession = kieBase.newKieSession(kieSessionConf, null);
results = new ArrayList<>();
kieSession.setGlobal("results", this);
kieSession.setGlobal("log", log);
if (log.isDebugEnabled()) {
kieSession.addEventListener(new CepAgendaEventListener());
kieSession.addEventListener(new CepRuleRuntimeEventListener());
}
log.debugf("Clock time [%s] ", kieSession.getSessionClock().getCurrentTime());
kieSession.getKieBase().getKiePackages().stream().forEach(p -> log.debugf("Rules: %s", p.getRules()));
executor.submit(() -> {
log.info("Starting fireUntilHalt()");
kieSession.fireUntilHalt();
log.info("Stopping fireUntilHalt()");
});
}
示例15: startSession
import org.kie.api.io.ResourceType; //导入依赖的package包/类
private void startSession(String drl) {
kieBaseConfiguration = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kieBaseConfiguration.setOption( EventProcessingOption.STREAM );
kieBase = new KieHelper().addContent(drl, ResourceType.DRL).build(kieBaseConfiguration);
kieSessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
kieSessionConf.setOption( ClockTypeOption.get( "pseudo" ) );
kieSession = kieBase.newKieSession(kieSessionConf, null);
clock = kieSession.getSessionClock();
// kieSession.addEventListener(new DebugAgendaEventListener());
// kieSession.addEventListener(new DebugRuleRuntimeEventListener());
results = new ArrayList<>();
kieSession.setGlobal("clock", clock);
kieSession.setGlobal("results", new CepEngine() {
@Override
public void sendResult(Event event) {
results.add(event);
}
@Override
public void updateConditions(String expiration, Collection<FullTrigger> activeTriggers) { }
@Override
public void processEvents(TreeSet<Event> events) { }
@Override
public void stop() { }
});
}