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


Java CommandFactory类代码示例

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


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


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