当前位置: 首页>>代码示例>>Java>>正文


Java StatelessKieSession.setGlobal方法代码示例

本文整理汇总了Java中org.kie.api.runtime.StatelessKieSession.setGlobal方法的典型用法代码示例。如果您正苦于以下问题:Java StatelessKieSession.setGlobal方法的具体用法?Java StatelessKieSession.setGlobal怎么用?Java StatelessKieSession.setGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.kie.api.runtime.StatelessKieSession的用法示例。


在下文中一共展示了StatelessKieSession.setGlobal方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: determineWorkgroups

import org.kie.api.runtime.StatelessKieSession; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<String> determineWorkgroups(TaskTemplate taskTemplate, TaskInstance taskInstance) throws StrategyException {
    KieBase knowledgeBase = getKnowledgeBase();

    StatelessKieSession knowledgeSession = knowledgeBase.newStatelessKieSession();

    List<Object> facts = new ArrayList<Object>();
    facts.add(getParameters());
    knowledgeSession.setGlobal("taskTemplate", taskTemplate);
    knowledgeSession.setGlobal("taskInstance", taskInstance);
    knowledgeSession.setGlobal("now", new Date());

    knowledgeSession.execute(CommandFactory.newInsertElements(facts));

    return taskInstance.getWorkgroups();
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw-demo,代码行数:17,代码来源:RulesBasedRoutingStrategy.java

示例2: determineDueDate

import org.kie.api.runtime.StatelessKieSession; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Date determineDueDate(TaskTemplate taskTemplate) throws StrategyException {

    TaskInstance taskInstanceVO = new TaskInstance();  // for holding values

    // execute rules only once (results are stored in taskInstanceVO)
    KieBase knowledgeBase = getKnowledgeBase();
    StatelessKieSession knowledgeSession = knowledgeBase.newStatelessKieSession();

    List<Object> facts = new ArrayList<Object>();
    facts.add(getParameters());
    knowledgeSession.setGlobal("taskTemplate", taskTemplate);
    knowledgeSession.setGlobal("taskInstance", taskInstanceVO);

    knowledgeSession.execute(CommandFactory.newInsertElements(facts));

    return Date.from(taskInstanceVO.getDue());
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw-demo,代码行数:20,代码来源:RulesBasedPrioritizationStrategy.java

示例3: execute

import org.kie.api.runtime.StatelessKieSession; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object execute(Asset rulesAsset, Operand input) throws ExecutionException {

    ClassLoader cloudClassLoader = null;
    if (input.getContext() != null && input.getContext().getPackage() != null)
        cloudClassLoader = input.getContext().getPackage().getCloudClassLoader();
    if (cloudClassLoader == null) // fall back to rules asset pkg classloader
        cloudClassLoader = PackageCache.getPackage(rulesAsset.getPackageName()).getCloudClassLoader();

    KnowledgeBaseAsset kbAsset = DroolsKnowledgeBaseCache
            .getKnowledgeBaseAsset(rulesAsset.getName(), null, null, cloudClassLoader);
    if (kbAsset == null) {
        throw new ExecutionException("Cannot load KnowledgeBase asset: "
                + rulesAsset.getPackageName() + "/" + rulesAsset.getLabel());
    }

    KieBase knowledgeBase = kbAsset.getKnowledgeBase();

    StatelessKieSession kSession = knowledgeBase.newStatelessKieSession();

    List<Object> facts = new ArrayList<Object>();
    if (input.getInput() != null) {
        facts.add(input.getInput()); // direct access
        if (input.getInput() instanceof Jsonable)
            facts.add(((Jsonable)input.getInput()).getJson());
    }

    kSession.setGlobal("operand", input);
    kSession.execute(CommandFactory.newInsertElements(facts));
    return input.getResult();
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw-demo,代码行数:33,代码来源:DroolsExecutor.java

示例4: getSubTaskPlan

import org.kie.api.runtime.StatelessKieSession; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public String getSubTaskPlan(TaskRuntimeContext masterTaskContext) throws StrategyException {
    TaskInstance masterTaskInstance = masterTaskContext.getTaskInstance();
    KieBase knowledgeBase = getKnowledgeBase();

    StatelessKieSession knowledgeSession = knowledgeBase.newStatelessKieSession();

    List<Object> facts = new ArrayList<Object>();
    facts.add(getParameters());
    knowledgeSession.setGlobal("masterTaskInstance", masterTaskInstance);
    SubTaskPlan subTaskPlan = new SubTaskPlan();
    knowledgeSession.setGlobal("subTaskPlan", subTaskPlan);
    knowledgeSession.setGlobal("now", new Date());

    knowledgeSession.execute(CommandFactory.newInsertElements(facts));
    try {
        String planXml = marshalJaxb(subTaskPlan);
        if (logger.isDebugEnabled()) {
            logger.debug("SubTask plan XML: " + planXml);
        }
        return planXml;
    }
    catch (Exception ex) {
        throw new StrategyException(ex.getMessage(), ex);
    }

}
 
开发者ID:CenturyLinkCloud,项目名称:mdw-demo,代码行数:28,代码来源:RulesBasedSubTaskStrategy.java

示例5: setGlobalValues

import org.kie.api.runtime.StatelessKieSession; //导入方法依赖的package包/类
protected void setGlobalValues(StatelessKieSession knowledgeSession) throws ActivityException {
    knowledgeSession.setGlobal("activity", this); // TODO deprecate
    knowledgeSession.setGlobal("runtimeContext", getRuntimeContext());
    knowledgeSession.setGlobal("now", new Date());
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw-demo,代码行数:6,代码来源:DroolsActivity.java

示例6: testProcess

import org.kie.api.runtime.StatelessKieSession; //导入方法依赖的package包/类
@Test
public void testProcess() throws SAXException, IOException {
    String str = "";
    str += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    str += "<process xmlns=\"http://drools.org/drools-5.0/process\"\n";
    str += "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    str += "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n";
    str += "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.actions\" package-name=\"org.drools\" version=\"1\" >\n";
    str += "\n";
    str += "  <header>\n";
    str += "    <imports>\n";
    str += "      <import name=\"org.kie.camel.testdomain.TestVariable\" />\n";
    str += "    </imports>\n";
    str += "    <globals>\n";
    str += "      <global identifier=\"list\" type=\"java.util.List\" />\n";
    str += "    </globals>\n";
    str += "    <variables>\n";
    str += "      <variable name=\"person\" >\n";
    str += "        <type name=\"org.drools.core.process.core.datatype.impl.type.ObjectDataType\" className=\"TestVariable\" />\n";
    str += "      </variable>\n";
    str += "    </variables>\n";
    str += "  </header>\n";
    str += "\n";
    str += "  <nodes>\n";
    str += "    <start id=\"1\" name=\"Start\" />\n";
    str += "    <actionNode id=\"2\" name=\"MyActionNode\" >\n";
    str += "      <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Triggered\");\n";
    str += "list.add(person.name);\n";
    str += "</action>\n";
    str += "    </actionNode>\n";
    str += "    <end id=\"3\" name=\"End\" />\n";
    str += "  </nodes>\n";
    str += "\n";
    str += "  <connections>\n";
    str += "    <connection from=\"1\" to=\"2\" />\n";
    str += "    <connection from=\"2\" to=\"3\" />\n";
    str += "  </connections>\n" + "\n";
    str += "</process>";

    StatelessKieSession ksession = getStatelessKieSessionFromResource(ResourceFactory.newByteArrayResource(str.getBytes()).setSourcePath("src/main/resources/rule.rf")
        .setResourceType(ResourceType.DRF));

    setExec(ksession);
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    TestVariable person = new TestVariable("John Doe");

    String inXml = "";
    inXml += "<batch-execution>";
    inXml += "  <start-process processId='org.drools.actions'>";
    inXml += "    <parameter identifier='person'>";
    inXml += "       <org.kie.camel.testdomain.TestVariable>";
    inXml += "         <name>John Doe</name>";
    inXml += "    </org.kie.camel.testdomain.TestVariable>";
    inXml += "    </parameter>";
    inXml += "  </start-process>";
    inXml += "  <get-global identifier='list' out-identifier='out-list'/>";
    inXml += "</batch-execution>";

    String outXml = template.requestBody("direct:exec", inXml, String.class);

    assertEquals(1, list.size());
    assertEquals("John Doe", list.get(0));

    String expectedXml = "";
    expectedXml += "<execution-results>\n";
    expectedXml += "  <result identifier=\"out-list\">\n";
    expectedXml += "    <list>\n";
    expectedXml += "      <string>John Doe</string>\n";
    expectedXml += "    </list>\n";
    expectedXml += "  </result>\n";
    expectedXml += "</execution-results>\n";

    assertXMLEqual(expectedXml, outXml);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:76,代码来源:XStreamBatchExecutionTest.java

示例7: testProcess

import org.kie.api.runtime.StatelessKieSession; //导入方法依赖的package包/类
@Test
public void testProcess() throws Exception {
    String str = "";
    str += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    str += "<process xmlns=\"http://drools.org/drools-5.0/process\"\n";
    str += "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    str += "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n";
    str += "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.actions\" package-name=\"org.drools\" version=\"1\" >\n";
    str += "\n";
    str += "  <header>\n";
    str += "    <imports>\n";
    str += "      <import name=\"org.kie.camel.testdomain.TestVariable\" />\n";
    str += "    </imports>\n";
    str += "    <globals>\n";
    str += "      <global identifier=\"list1\" type=\"java.util.List\" />\n";
    str += "    </globals>\n";
    str += "    <variables>\n";
    str += "      <variable name=\"person\" >\n";
    str += "        <type name=\"org.drools.core.process.core.datatype.impl.type.ObjectDataType\" className=\"TestVariable\" />\n";
    str += "      </variable>\n";
    str += "    </variables>\n";
    str += "  </header>\n";
    str += "\n";
    str += "  <nodes>\n";
    str += "    <start id=\"1\" name=\"Start\" />\n";
    str += "    <actionNode id=\"2\" name=\"MyActionNode\" >\n";
    str += "      <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Triggered\");\n";
    str += "list1.add(person.name);\n";
    str += "</action>\n";
    str += "    </actionNode>\n";
    str += "    <end id=\"3\" name=\"End\" />\n";
    str += "  </nodes>\n";
    str += "\n";
    str += "  <connections>\n";
    str += "    <connection from=\"1\" to=\"2\" />\n";
    str += "    <connection from=\"2\" to=\"3\" />\n";
    str += "  </connections>\n" + "\n";
    str += "</process>";

    StatelessKieSession ksession = getStatelessKieSessionFromResource(ResourceFactory.newByteArrayResource(str.getBytes()).setSourcePath("src/main/resources/rule.rf")
        .setResourceType(ResourceType.DRF));
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list1", list);
    setExec(ksession);

    String outXml = execContent("testProcess.in.1");

    assertXMLEqual(getContent("testProcess.expected.1"), outXml);

    ExecutionResults results = unmarshalOutXml(outXml, ExecutionResults.class);

    list = (List)results.getValue("out-list");

    assertEquals(1, list.size());
    assertEquals("John Doe", list.get(0));
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:57,代码来源:BatchTest.java


注:本文中的org.kie.api.runtime.StatelessKieSession.setGlobal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。