本文整理汇总了Java中org.kie.api.runtime.StatelessKieSession类的典型用法代码示例。如果您正苦于以下问题:Java StatelessKieSession类的具体用法?Java StatelessKieSession怎么用?Java StatelessKieSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StatelessKieSession类属于org.kie.api.runtime包,在下文中一共展示了StatelessKieSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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());
}
示例3: recommendMeal
import org.kie.api.runtime.StatelessKieSession; //导入依赖的package包/类
@Override
public Meal recommendMeal(Person person) throws BusinessException {
StatelessKieSession kieSession = kContainer.newStatelessKieSession();
InsertObjectCommand insertObjectCommand = new InsertObjectCommand(person);
FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand();
QueryCommand queryCommand = new QueryCommand("results", "getMeal", (Object[]) null);
List<GenericCommand<?>> commands = new ArrayList<GenericCommand<?>>();
commands.add(insertObjectCommand);
commands.add(fireAllRulesCommand);
commands.add(queryCommand);
BatchExecutionCommand batch = new BatchExecutionCommandImpl(commands);
ExecutionResults results = kieSession.execute(batch);
QueryResults queryResults = (QueryResults) results.getValue("results");
Iterator<QueryResultsRow> iterator = queryResults.iterator();
while (iterator.hasNext()) {
Meal meal = (Meal) iterator.next().get("$m");
if (meal != null) {
System.out.println("Meal : " + meal);
return meal;
}
}
return null;
}
示例4: 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();
}
示例5: 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);
}
}
示例6: RuleServlet
import org.kie.api.runtime.StatelessKieSession; //导入依赖的package包/类
public RuleServlet() {
Inspector inspector = new Inspector();
KieServices kieServices = KieServices.Factory.get();
// returns default session
StatelessKieSession kieSession = kieServices.getKieClasspathContainer().newStatelessKieSession();
KieBase kieBase = kieSession.getKieBase();
this.rules = inspector.inspectBase(kieBase);
}
示例7: getStatelessKieSessionFromResource
import org.kie.api.runtime.StatelessKieSession; //导入依赖的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();
}
示例8: getStatelessKieSessionFromResource
import org.kie.api.runtime.StatelessKieSession; //导入依赖的package包/类
private StatelessKieSession getStatelessKieSessionFromResource(Resource resource) throws Exception {
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();
}
示例9: testManualFireAllRules
import org.kie.api.runtime.StatelessKieSession; //导入依赖的package包/类
@Test
public void testManualFireAllRules() throws Exception {
String str = "";
str += "package org.kie \n";
str += "import org.kie.camel.testdomain.Cheese \n";
str += "global java.util.List list1 \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 += " list1.add( $c );";
str += "end\n";
StatelessKieSession ksession = getStatelessKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
setExec(ksession);
String outXml = execContent("testManualFireAllRules.in.1");
ExecutionResults result = unmarshalOutXml(outXml, ExecutionResults.class);
assertXMLEqual(getContent("testManualFireAllRules.expected.1", ((FactHandle)result.getFactHandle("outBrie")).toExternalForm()), outXml);
// brie should not have been added to the list
List list = (List)result.getValue("list1");
Cheese stilton25 = new Cheese("stilton", 30);
Cheese stilton30 = new Cheese("stilton", 35);
Set expectedList = new HashSet();
expectedList.add(stilton25);
expectedList.add(stilton30);
assertEquals(expectedList, new HashSet(list));
// brie should not have changed
Cheese brie10 = new Cheese("brie", 10);
brie10.setOldPrice(5);
assertEquals(brie10, result.getValue("outBrie"));
}
示例10: execute
import org.kie.api.runtime.StatelessKieSession; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void execute() throws ActivityException {
String knowledgeBaseName = null;
String knowledgeBaseVersion = null;
try {
knowledgeBaseName = getAttributeValueSmart(KNOWLEDGE_BASE);
knowledgeBaseVersion = getAttributeValueSmart(KNOWLEDGE_BASE_ASSET_VERSION);
}
catch (PropertyException ex) {
throw new ActivityException(ex.getMessage(), ex);
}
if (StringHelper.isEmpty(knowledgeBaseName))
throw new ActivityException("Missing attribute: " + KNOWLEDGE_BASE);
KieBase knowledgeBase = getKnowledgeBase(knowledgeBaseName, knowledgeBaseVersion);
if (knowledgeBase == null)
throw new ActivityException("Cannot load KnowledgeBase: " + knowledgeBaseName);
// TODO stateful session option
StatelessKieSession kSession = knowledgeBase.newStatelessKieSession();
List<Object> facts = new ArrayList<Object>();
Map<String,Object> values = new HashMap<String,Object>();
for (VariableInstance variableInstance : getParameters()) {
Object value = getVariableValue(variableInstance.getName());
values.put(variableInstance.getName(), value);
}
facts.add(values);
setGlobalValues(kSession);
kSession.execute(CommandFactory.newInsertElements(facts));
String temp = getAttributeValue(OUTPUTDOCS);
setOutputDocuments(temp == null ? new String[0] : StringHelper.parseList(temp).toArray(new String[0]));
// TODO handle document variables
Process processVO = getProcessDefinition();
for (Variable variable : processVO.getVariables()) {
Object newValue = values.get(variable.getName());
if (newValue != null)
setVariableValue(variable.getName(), variable.getType(), newValue);
}
}
示例11: 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());
}
示例12: getStatelessKnowledgeSession
import org.kie.api.runtime.StatelessKieSession; //导入依赖的package包/类
public static StatelessKieSession getStatelessKnowledgeSession(KieContainer kieContainer, String sessionName) {
StatelessKieSession kSession = kieContainer.newStatelessKieSession(sessionName);
return kSession;
}
示例13: getStatelessKnowledgeSession
import org.kie.api.runtime.StatelessKieSession; //导入依赖的package包/类
public static StatelessKieSession getStatelessKnowledgeSession(KieContainer kieContainer, String sessionName) {
StatelessKieSession kSession = kieContainer.newStatelessKieSession(sessionName);
return kSession;
}
示例14: createStatelessSessionSingleRuleFile
import org.kie.api.runtime.StatelessKieSession; //导入依赖的package包/类
private DroolsSession<?> createStatelessSessionSingleRuleFile() {
StatelessKieSession statelessKieSession = kieBase.newStatelessKieSession();
return new DroolsStatelessSession(statelessKieSession);
}
示例15: DroolsStatelessSession
import org.kie.api.runtime.StatelessKieSession; //导入依赖的package包/类
public DroolsStatelessSession(StatelessKieSession statelessKieSession) {
this.kSession = statelessKieSession;
}