• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java CommandFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.kie.internal.command.CommandFactory的典型用法代码示例。如果您正苦于以下问题:Java CommandFactory类的具体用法?Java CommandFactory怎么用?Java CommandFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CommandFactory类属于org.kie.internal.command包,在下文中一共展示了CommandFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: determineWorkgroups

import org.kie.internal.command.CommandFactory; //导入依赖的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.internal.command.CommandFactory; //导入依赖的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: processRules

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
public Measure processRules(@Body Measure measure) {
	
	KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(
			kieHost, kieUser,
			kiePassword);
	
	Set<Class<?>> jaxBClasses = new HashSet<Class<?>>();
	jaxBClasses.add(Measure.class);
	
	config.addJaxbClasses(jaxBClasses);
	config.setMarshallingFormat(MarshallingFormat.JAXB);
	RuleServicesClient client = KieServicesFactory.newKieServicesClient(config)
			.getServicesClient(RuleServicesClient.class);

       List<Command<?>> cmds = new ArrayList<Command<?>>();
	KieCommands commands = KieServices.Factory.get().getCommands();
	cmds.add(commands.newInsert(measure));
	
    GetObjectsCommand getObjectsCommand = new GetObjectsCommand();
    getObjectsCommand.setOutIdentifier("objects");

	
	cmds.add(commands.newFireAllRules());
	cmds.add(getObjectsCommand);
	BatchExecutionCommand myCommands = CommandFactory.newBatchExecution(cmds,
			"DecisionTableKS");
	ServiceResponse<ExecutionResults> response = client.executeCommandsWithResults("iot-ocp-businessrules-service", myCommands);
			
	List responseList = (List) response.getResult().getValue("objects");
	
	Measure responseMeasure = (Measure) responseList.get(0);
	
	return responseMeasure;

}
 
开发者ID:sabre1041,项目名称:iot-ocp,代码行数:36,代码来源:BusinessRulesBean.java


示例4: start

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
/**
 *
 */
public void start() throws Exception {

    for (int i = 0; i < 10; i++) {
        Customer customer = customer();
        logger.info("------------------- START ------------------\n"
                + " KieSession fireAllRules. {}", customer);

        List<Command<?>> commands = new ArrayList<Command<?>>();

        commands.add(CommandFactory.newInsert(customer, "customer"));
        commands.add(CommandFactory.newFireAllRules("num-rules-fired"));

        ExecutionResults results = ksession.execute(CommandFactory
                .newBatchExecution(commands));

        int fired = Integer.parseInt(results.getValue("num-rules-fired")
                .toString());

        customer = (Customer)results.getValue("customer");

        logger.info("After rule rules-fired={} {} \n"
                        + "------------------- STOP ---------------------", fired,
                customer);
    }
}
 
开发者ID:apache,项目名称:servicemix,代码行数:29,代码来源:SimpleRuleBean.java


示例5: testQuery

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
/** insert 2 facts into session, then launch query command with one argument */
@Test
public void testQuery() throws Exception {
    KieSession session = getKieSession();

    initializeTemplate(session);

    List<Person> persons = new ArrayList<Person>();
    persons.add(new Person("john", "john", 25));
    persons.add(new Person("sarah", "john", 35));

    session.execute(CommandFactory.newInsertElements(persons));
    assertEquals(2, session.getFactCount());

    QueryResults results = query("people over the age of x", new Object[] {30});
    assertNotNull(results);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:18,代码来源:JsonQueryTest.java


示例6: testExecutionResults

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
@Test
public void testExecutionResults() throws JAXBException {
    JAXBContext jaxbContext = getJaxbContext();

    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

    List<Command> commands = new ArrayList<Command>();
    commands.add(CommandFactory.newInsert(new Person("darth", 105), "p"));
    commands.add(CommandFactory.newFireAllRules());

    ExecutionResults res1 = ksession.execute(CommandFactory.newBatchExecution(commands));

    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    marshaller.marshal(res1, baos);

    // note it's using xsi:type
    logger.debug(new String(baos.toByteArray()));

    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    ExecutionResults res2 = (ExecutionResults)unmarshaller.unmarshal(new StringReader(baos.toString()));
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:25,代码来源:JaxbTest.java


示例7: execute

import org.kie.internal.command.CommandFactory; //导入依赖的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


示例8: getSubTaskPlan

import org.kie.internal.command.CommandFactory; //导入依赖的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


示例9: fireAllRules

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
@Override
public void fireAllRules() {
    FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand();
    fireAllRulesCommand.setOutIdentifier(IDENTIFIER_NUMBER_OF_FIRED_RULES);
    commands.add(fireAllRulesCommand);
    ExecutionResults executionResults = kSession.execute(CommandFactory.newBatchExecution(commands));
    this.numberOfFiredRules = (Integer) executionResults.getValue(IDENTIFIER_NUMBER_OF_FIRED_RULES);
}
 
开发者ID:jeichler,项目名称:junit-drools,代码行数:9,代码来源:DroolsStatelessSession.java


示例10: insert

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
@Override
public void insert(Object... objects) {
    if (objects != null) {
        for (Object object : objects) {
            if (object != null) {
                commands.add(CommandFactory.newInsert(object));
            }
        }
    }
}
 
开发者ID:jeichler,项目名称:junit-drools,代码行数:11,代码来源:DroolsStatelessSession.java


示例11: insertAndFireAll

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
public void insertAndFireAll(Exchange exchange) {
    final Message in = exchange.getIn();
    final Object body = in.getBody();

    final List<Command<?>> commands = new ArrayList<Command<?>>(2);
    commands.add(CommandFactory.newInsert(body));
    commands.add(CommandFactory.newFireAllRules());

    Command<?> batch = CommandFactory.newBatchExecution(commands);
    in.setBody(batch);
}
 
开发者ID:apache,项目名称:servicemix,代码行数:12,代码来源:Utils.java


示例12: insertAndFireAll

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
/**
 * Create commands for Drools engine.
 *
 * @param body {@link org.apache.camel.Exchange}
 */
public Command<ExecutionResults> insertAndFireAll(final Customer body) {

    Command<?> insert = CommandFactory.newInsert(body, "customer");

    @SuppressWarnings("unchecked")
    Command<ExecutionResults> batch = CommandFactory
            .newBatchExecution(Arrays.asList(insert));

    return batch;
}
 
开发者ID:apache,项目名称:servicemix,代码行数:16,代码来源:Utils.java


示例13: query

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
/** build json query command and send it to drools */
private QueryResults query(String queryName, Object[] args) {
    Command command = CommandFactory.newQuery("persons", queryName, args);
    String queryStr = template.requestBody("direct:marshall", command, String.class);

    String json = template.requestBody("direct:test-session", queryStr, String.class);
    ExecutionResults res = (ExecutionResults)template.requestBody("direct:unmarshall", json);
    return (QueryResults)res.getValue("persons");
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:10,代码来源:JsonQueryTest.java


示例14: testSessionInsert

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
@Test
public void testSessionInsert() throws Exception {
    Person person = new Person();
    person.setName("Mauricio");

    InsertObjectCommand cmd = (InsertObjectCommand)CommandFactory.newInsert(person, "salaboy");

    ExecutionResults response = (ExecutionResults)template.requestBody("direct:test-with-session", cmd);
    assertTrue("Expected valid ExecutionResults object", response != null);
    assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") != null);
    assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") instanceof FactHandle);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:13,代码来源:CamelEndpointTest.java


示例15: testNoSessionInsert

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
@Test
public void testNoSessionInsert() throws Exception {
    Person person = new Person();
    person.setName("Mauricio");

    InsertObjectCommand cmd = (InsertObjectCommand)CommandFactory.newInsert(person, "salaboy");

    ExecutionResults response = (ExecutionResults)template.requestBodyAndHeader("direct:test-no-session", cmd, KieComponent.KIE_LOOKUP, "ksession1");
    assertTrue("Expected valid ExecutionResults object", response != null);
    assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") != null);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:12,代码来源:CamelEndpointTest.java


示例16: testSessionBatchExecutionCommand

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
@Test
public void testSessionBatchExecutionCommand() throws Exception {
    Person john = new Person();
    john.setName("John Smith");

    List<Command> commands = new ArrayList<Command>();
    commands.add(CommandFactory.newInsert(john, "john"));
    BatchExecutionCommand batchExecutionCommand = CommandFactory.newBatchExecution(commands);

    ExecutionResults response = (ExecutionResults)template.requestBody("direct:test-with-session", batchExecutionCommand);
    assertTrue("Expected valid ExecutionResults object", response != null);
    assertTrue("ExecutionResults missing expected fact", response.getFactHandle("john") != null);
    assertTrue("ExecutionResults missing expected fact", response.getFactHandle("john") instanceof FactHandle);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:15,代码来源:CamelEndpointTest.java


示例17: testSessionBatchExecutionCommandWithHeader

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
@Test
public void testSessionBatchExecutionCommandWithHeader() throws Exception {

    MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader", MockEndpoint.class);

    String headerName = "testHeaderName";
    String headerValue = "testHeaderValue";

    Person john = new Person();
    john.setName("John Smith");

    List<Command> commands = new ArrayList<Command>();
    commands.add(CommandFactory.newInsert(john, "john"));
    BatchExecutionCommand batchExecutionCommand = CommandFactory.newBatchExecution(commands);

    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(headerName, headerValue);

    // set mock expectations
    mockResult.expectedMessageCount(1);
    mockResult.expectedHeaderReceived(headerName, headerValue);

    // do test
    template.requestBodyAndHeaders("direct:test-with-session-withHeader", batchExecutionCommand, headers);

    ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class);

    assertTrue("Expected valid ExecutionResults object", response != null);
    assertTrue("ExecutionResults missing expected fact", response.getFactHandle("john") != null);
    assertTrue("ExecutionResults missing expected fact", response.getFactHandle("john") instanceof FactHandle);

    mockResult.assertIsSatisfied();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:34,代码来源:CamelEndpointTest.java


示例18: testSessionGetObject

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
@Test
public void testSessionGetObject() throws Exception {
    FactHandle factHandle = DefaultFactHandle.createFromExternalFormat(handle);
    GetObjectCommand cmd = (GetObjectCommand)CommandFactory.newGetObject(factHandle);
    cmd.setOutIdentifier("rider");

    ExecutionResults response = (ExecutionResults)template.requestBody("direct:test-with-session", cmd);
    assertTrue("Expected valid ExecutionResults object", response != null);
    assertTrue("ExecutionResults missing expected object", response.getValue("rider") != null);
    assertTrue("FactHandle object not of expected type", response.getValue("rider") instanceof Person);
    assertEquals("Hadrian", ((Person)response.getValue("rider")).getName());
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:13,代码来源:CamelEndpointTest.java


示例19: testSessionInsert

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
@Test
public void testSessionInsert() throws Exception {
    Person person = new Person();
    person.setName("Mauricio");

    InsertObjectCommand cmd = (InsertObjectCommand)CommandFactory.newInsert(person, "salaboy");
    ExecutionResults response = (ExecutionResults)template.requestBody("direct:test-no-marshal", cmd);
    assertTrue("Expected valid ExecutionResults object", response != null);
    assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") != null);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:11,代码来源:CamelProxyEndpointTest.java


示例20: testInsert

import org.kie.internal.command.CommandFactory; //导入依赖的package包/类
/** bz771203
 * creates batch-execution command with insert. Marshalls it to XML
 * and send to drools */
@Test
public void testInsert() throws Exception {
    Person p = new Person("Alice", "spicy meals", 30);
    List<Command> commands = new ArrayList<Command>();
    commands.add(CommandFactory.newInsert(p, "tempPerson"));
    BatchExecutionCommand command = CommandFactory.newBatchExecution(commands);
    String xmlCommand = template.requestBody("direct:marshall", command, String.class);

    String xml = template.requestBody("direct:test-session", xmlCommand, String.class);
    ExecutionResults res = (ExecutionResults)template.requestBody("direct:unmarshall", xml);

    Object o = res.getFactHandle("tempPerson");
    assertTrue("returned String instead of FactHandle instance", o instanceof FactHandle);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:18,代码来源:JaxbInsertTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Path类代码示例发布时间:2022-05-22
下一篇:
Java EMError类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap