本文整理汇总了Java中org.kie.internal.io.ResourceFactory类的典型用法代码示例。如果您正苦于以下问题:Java ResourceFactory类的具体用法?Java ResourceFactory怎么用?Java ResourceFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceFactory类属于org.kie.internal.io包,在下文中一共展示了ResourceFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addRule
import org.kie.internal.io.ResourceFactory; //导入依赖的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: addResource
import org.kie.internal.io.ResourceFactory; //导入依赖的package包/类
public void addResource(Resource r){
switch (r.getPathType()) {
case CLASSPATH:
this.kBuilder.add(ResourceFactory.newClassPathResource(r.getPath()),r.getType());
break;
case FILE:
this.kBuilder.add(ResourceFactory.newFileResource(r.getPath()),r.getType());
break;
case URL:
this.kBuilder.add(ResourceFactory.newUrlResource(r.getPath()),r.getType());
break;
default:
throw new RuntimeException("not support pathtype");
}
if(this.kBuilder.hasErrors()){
throw new RuntimeException(this.kBuilder.getErrors().toString());
}
}
示例3: getRuntimeManager
import org.kie.internal.io.ResourceFactory; //导入依赖的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;
}
示例4: testCallService
import org.kie.internal.io.ResourceFactory; //导入依赖的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());
}
示例5: runFaultBoundaryProcess
import org.kie.internal.io.ResourceFactory; //导入依赖的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();
}
示例6: testCallService
import org.kie.internal.io.ResourceFactory; //导入依赖的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());
}
示例7: runFaultBoundaryProcess
import org.kie.internal.io.ResourceFactory; //导入依赖的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();
}
示例8: testInsertWithReturnObjectFalse
import org.kie.internal.io.ResourceFactory; //导入依赖的package包/类
@Test
public void testInsertWithReturnObjectFalse() throws Exception {
String str = "";
str += "package org.kie \n";
str += "import org.kie.camel.testdomain.Cheese \n";
str += "rule rule1 \n";
str += " when \n";
str += " $c : Cheese() \n";
str += " \n";
str += " then \n";
str += " $c.setPrice( $c.getPrice() + 5 ); \n";
str += "end\n";
KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
setExec(ksession);
String outXml = execContent("testInsertWithReturnObjectFalse.in.1");
ExecutionResults result = unmarshalOutXml(outXml, ExecutionResults.class);
String expectedXml = getContent("testInsertWithReturnObjectFalse.expected.1", ((FactHandle)result.getFactHandle("outStilton")).toExternalForm());
assertXMLEqual(expectedXml, outXml);
}
示例9: testExecuteUsingKieAPI
import org.kie.internal.io.ResourceFactory; //导入依赖的package包/类
/**
* Test execute using kie api.
*
* @throws Exception the exception
*/
@Test
public void testExecuteUsingKieAPI() throws Exception {
// get the resource
Resource dt = ResourceFactory.newClassPathResource("/data/IntegrationExampleTest.xls", getClass());
// create the builder
KieSession ksession = getKieSession(dt);
ksession.insert(new Cheese("stilton", 42));
ksession.insert(new Person("michael", "stilton", 42));
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("Old man stilton", list.get(0));
}
示例10: testNamedWorksheet
import org.kie.internal.io.ResourceFactory; //导入依赖的package包/类
/**
* Test named worksheet.
*
* @throws Exception the exception
*/
@Test
public void testNamedWorksheet() throws Exception {
DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
dtconf.setInputType(DecisionTableInputType.XLS);
dtconf.setWorksheetName("Tables");
Resource dt = ResourceFactory.newClassPathResource("/data/IntegrationExampleTest.xls", getClass()).setConfiguration(
dtconf);
KieSession ksession = getKieSession(dt);
// ASSERT AND FIRE
ksession.insert(new Cheese("cheddar", 42));
ksession.insert(new Person("michael", "stilton", 21));
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("Young man cheddar", list.get(0));
}
示例11: uploadDroolFiles
import org.kie.internal.io.ResourceFactory; //导入依赖的package包/类
private void uploadDroolFiles() {
logger.info("Starting Drools with drl files from: " + resourceFilePath);
File directory = new File(resourceFilePath);
File[] fList = directory.listFiles();
logger.info("Uploading Drool rules...");
if (fList != null && fList.length > 0) {
for (File file : fList) {
kfs.write(ResourceFactory.newFileResource(resourceFilePath + "/" + file.getName()));
logger.info("... " + file.getName());
}
} else {
logger.info("...no rules found to upload");
}
}
示例12: initKieJar
import org.kie.internal.io.ResourceFactory; //导入依赖的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();
}
示例13: addPackage
import org.kie.internal.io.ResourceFactory; //导入依赖的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();
}
}
示例14: visitFile
import org.kie.internal.io.ResourceFactory; //导入依赖的package包/类
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
File file = path.toFile();
if (file.isFile() && file.getName().endsWith(RULE_FILENAME_EXTENSION)) {
kieFileSystem.write(ResourceFactory.newFileResource(file));
rulesLoaded++;
}
return FileVisitResult.CONTINUE;
}
示例15: addClassPathResource
import org.kie.internal.io.ResourceFactory; //导入依赖的package包/类
@Override
public KnowledgeService addClassPathResource(String resourceName, Handler<AsyncResult<Void>> handler) {
Resource resource = ResourceFactory.newClassPathResource(resourceName);
environmentBuilder.addAsset(resource, resource.getResourceType());
handler.handle(Future.succeededFuture());
return this;
}