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


Java ExecutionResults.getValue方法代码示例

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


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

示例1: recommendMeal

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的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;
}
 
开发者ID:Salaboy,项目名称:drools-workshop,代码行数:27,代码来源:FoodRecommendationServiceImpl.java

示例2: testJSonSessionInsert

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testJSonSessionInsert() throws Exception {

    String inXml = "";
    inXml += "{\"batch-execution\":{\"commands\":[";
    inXml += "{\"insert\":{\"lookup\":\"ksession1\", ";
    inXml += "             \"object\":{\"org.kie.pipeline.camel.Person\":{\"name\":\"salaboy\"}}, \"out-identifier\":\"salaboy\" } }";
    inXml += ", {\"fire-all-rules\":\"\"}";
    inXml += "]}}";

    String outXml = new String((byte[])template.requestBody("direct:test-with-session-json", inXml));

    ExecutionResults result = (ExecutionResults)BatchExecutionHelper.newJSonMarshaller().fromXML(outXml);
    Person person = (Person)result.getValue("salaboy");
    assertEquals("salaboy", person.getName());
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:17,代码来源:CamelEndpointWithMarshallersTest.java

示例3: testSessionGetObject

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testSessionGetObject() throws Exception {
    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "<get-object out-identifier=\"rider\" fact-handle=\"" + this.handle + "\"/>\n";
    cmd += "</batch-execution>\n";

    String outXml = new String((byte[])template.requestBody("direct:test-with-session", cmd));

    ExecutionResults result = (ExecutionResults)BatchExecutionHelper.newXStreamMarshaller().fromXML(outXml);
    Person person = (Person)result.getValue("rider");
    assertEquals("Hadrian", person.getName());

    String expectedXml = "";
    expectedXml += "<?xml version='1.0' encoding='UTF-8'?><execution-results>";
    expectedXml += "<result identifier=\"rider\">";
    expectedXml += "<org.kie.pipeline.camel.Person>";
    expectedXml += "<name>Hadrian</name>";
    expectedXml += "</org.kie.pipeline.camel.Person>";
    expectedXml += "</result>";
    expectedXml += "</execution-results>";

    assertXMLEqual(expectedXml, outXml);

}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:26,代码来源:CamelEndpointWithMarshallersTest.java

示例4: testWorkingSetGlobalTestSessionSetAndGetGlobal

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testWorkingSetGlobalTestSessionSetAndGetGlobal() throws Exception {

    BatchExecutionCommandImpl cmd = new BatchExecutionCommandImpl();
    cmd.setLookup("ksession1");

    SetGlobalCommand setGlobal = new SetGlobalCommand("list", new WrappedList());
    setGlobal.setOutIdentifier("list");

    cmd.getCommands().add(setGlobal);
    cmd.getCommands().add(new InsertObjectCommand(new Person("baunax")));
    cmd.getCommands().add(new FireAllRulesCommand());
    cmd.getCommands().add(new GetGlobalCommand("list"));

    Marshaller marshaller = getJaxbContext().createMarshaller();
    marshaller.setProperty("jaxb.formatted.output", true);
    StringWriter xml = new StringWriter();
    marshaller.marshal(cmd, xml);

    logger.debug(xml.toString());

    byte[] response = (byte[])template.requestBody("direct:test-with-session", xml.toString());
    assertNotNull(response);
    logger.debug("response:\n" + new String(response));
    Unmarshaller unmarshaller = getJaxbContext().createUnmarshaller();
    ExecutionResults res = (ExecutionResults)unmarshaller.unmarshal(new ByteArrayInputStream(response));
    WrappedList resp = (WrappedList)res.getValue("list");
    assertNotNull(resp);

    assertEquals(resp.size(), 2);
    assertEquals("baunax", resp.get(0).getName());
    assertEquals("Hadrian", resp.get(1).getName());

}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:35,代码来源:CamelEndpointWithJaxWrapperCollectionTest.java

示例5: extractResult

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
public Greeting extractResult(ServiceResponse<ExecutionResults> response) {
    ExecutionResults res = response.getResult();
    Greeting greeting = null;
    if (res != null) {
        QueryResults queryResults = (QueryResults) res.getValue("greetings");
        for (QueryResultsRow queryResult : queryResults) {
            greeting = (Greeting) queryResult.get("greeting");
            break;
        }
    }

    return greeting;
}
 
开发者ID:fabric8-quickstarts,项目名称:spring-boot-camel-drools,代码行数:14,代码来源:DecisionServerHelper.java

示例6: determinePersonsAge

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
private static Person determinePersonsAge(Person person, String containerId) {
	//The container id is used to specify the KieBase to be used on the remote server
	RemoteCommandExecutor remoteCommandExecutor = new RemoteCommandExecutor();

       BatchExecutionCommandImpl batchExecutionCommand = new BatchExecutionCommandImpl();
       
       //Set the KieSession name
       batchExecutionCommand.setLookup("defaultKieSession");
       InsertObjectCommand insertObjectCommand = new InsertObjectCommand(person);
       
       //Ensure the person object is returned
       insertObjectCommand.setOutIdentifier("person");
       FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand();
       batchExecutionCommand.getCommands().add(insertObjectCommand);
       batchExecutionCommand.getCommands().add(fireAllRulesCommand);

       ExecutionResults executionResult = (ExecutionResults) remoteCommandExecutor.execute(batchExecutionCommand, containerId);
	
       //Get the person object back 
       Object result = executionResult.getValue("person");
	
	
	if (result instanceof Person) {
		return (Person)result;
	} else {
		System.err.println(result.toString());
		return null;
	}
}
 
开发者ID:anurag-saran,项目名称:drools-usage-patterns,代码行数:30,代码来源:Runner.java

示例7: fireAllRules

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的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

示例8: testExecutionNodeLookup

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testExecutionNodeLookup() throws Exception {
    String str = "";
    str += "package org.drools \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("testExecutionNodeLookup.in.1");
    ExecutionResults results = unmarshalOutXml(outXml, ExecutionResults.class);

    Cheese stilton = (Cheese)results.getValue("outStilton");
    assertEquals(30, stilton.getPrice());

    FactHandle factHandle = (FactHandle)results.getFactHandle("outStilton");
    stilton = (Cheese)ksession.getObject(factHandle);
    assertEquals(30, stilton.getPrice());

    assertXMLEqual(getContent("testExecutionNodeLookup.expected.1", factHandle.toExternalForm()), outXml);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:29,代码来源:BatchTest.java

示例9: testInsertObjectWithDeclaredFact

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testInsertObjectWithDeclaredFact() throws Exception {
    String str = "";
    str += "package org.foo \n";
    str += "declare Whee \n\ttype: String\n\tprice: Integer\n\toldPrice: Integer\nend\n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Whee() \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);

    ExecutionResults results = null;
    String outXml = null;
    ClassLoader orig = null;
    ClassLoader cl = ((StatefulKnowledgeSessionImpl)ksession).getKnowledgeBase().getRootClassLoader();
    try {
        orig = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(cl);
        outXml = execContent("testInsertObjectWithDeclaredFact.in.1");
        results = unmarshalOutXml(outXml, ExecutionResults.class);
    } finally {
        Thread.currentThread().setContextClassLoader(orig);
    }
    FactHandle factHandle = (FactHandle)results.getFactHandle("outStilton");
    Object object = results.getValue("outStilton");

    assertEquals("org.foo.Whee", object.getClass().getName());
    assertXMLEqual(getContent("testInsertObjectWithDeclaredFact.expected.1", factHandle.toExternalForm()), outXml);

}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:36,代码来源:BatchTest.java

示例10: testGetObject

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testGetObject() 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);

    ExecutionResults result = execContent("testGetObject.in.1", ExecutionResults.class);

    Cheese stilton = (Cheese)result.getValue("outStilton");
    assertEquals(30, stilton.getPrice());

    String outXml = execContent("testGetObject.in.2", ((FactHandle)result.getFactHandle("outStilton")).toExternalForm());
    result = unmarshalOutXml(outXml, ExecutionResults.class);

    stilton = (Cheese)result.getValue("outStilton");
    assertEquals(30, stilton.getPrice());
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:28,代码来源:BatchTest.java

示例11: testSessionInsert

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testSessionInsert() throws Exception {

    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "  <insert out-identifier=\"salaboy\">\n";
    cmd += "      <org.kie.pipeline.camel.Person>\n";
    cmd += "         <name>salaboy</name>\n";
    cmd += "      </org.kie.pipeline.camel.Person>\n";
    cmd += "   </insert>\n";
    cmd += "   <fire-all-rules/>\n";
    cmd += "</batch-execution>\n";

    String outXml = new String((byte[])template.requestBody("direct:test-with-session", cmd));

    ExecutionResults result = (ExecutionResults)BatchExecutionHelper.newXStreamMarshaller().fromXML(outXml);
    Person person = (Person)result.getValue("salaboy");
    assertEquals("salaboy", person.getName());

    String expectedXml = "";
    expectedXml += "<?xml version='1.0' encoding='UTF-8'?><execution-results>";
    expectedXml += "<result identifier=\"salaboy\">";
    expectedXml += "<org.kie.pipeline.camel.Person>";
    expectedXml += "<name>salaboy</name>";
    expectedXml += "</org.kie.pipeline.camel.Person>";
    expectedXml += "</result>";
    expectedXml += "<fact-handle identifier=\"salaboy\" external-form=\"" + ((InternalFactHandle)result.getFactHandle("salaboy")).toExternalForm() + "\"/>";
    expectedXml += "</execution-results>";

    assertXMLEqual(expectedXml, outXml);

}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:33,代码来源:CamelEndpointWithMarshallersTest.java

示例12: testInsertElements

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testInsertElements() 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";
    KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
    setExec(ksession);

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

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

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

    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));
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:34,代码来源:BatchTest.java

示例13: testManualFireAllRules

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的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"));
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:41,代码来源:BatchTest.java

示例14: testSetGlobal

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testSetGlobal() 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 += "global java.util.List list2 \n";
    str += "global java.util.List list3 \n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Cheese() \n";
    str += " \n";
    str += "  then \n";
    str += "    $c.setPrice( 30 ); \n";
    str += "    list1.add( $c ); \n";
    str += "    list2.add( $c ); \n";
    str += "    list3.add( $c ); \n";
    str += "end\n";

    KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
    setExec(ksession);

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

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

    assertXMLEqual(getContent("testSetGlobal.expected.1", ((FactHandle)result.getFactHandle("outStilton")).toExternalForm()), outXml);

    Cheese stilton = new Cheese("stilton", 30);

    assertNull(result.getValue("list1"));

    List list2 = (List)result.getValue("list2");
    assertEquals(1, list2.size());
    assertEquals(stilton, list2.get(0));

    List list3 = (List)result.getValue("outList3");
    assertEquals(1, list3.size());
    assertEquals(stilton, list3.get(0));
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:41,代码来源:BatchTest.java

示例15: testInsertElements

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testInsertElements() throws Exception {

    BatchExecutionCommandImpl cmd = new BatchExecutionCommandImpl();
    cmd.setLookup("ksession1");
    InsertElementsCommand elems = new InsertElementsCommand("elems");
    elems.getObjects().add(new Person("lucaz", 25));
    elems.getObjects().add(new Person("hadrian", 25));
    elems.getObjects().add(new Person("baunax", 21));
    elems.getObjects().add("xxx");

    cmd.getCommands().add(elems);
    cmd.getCommands().add(new FireAllRulesCommand());

    StringWriter xmlReq = new StringWriter();
    Marshaller marshaller = getJaxbContext().createMarshaller();
    marshaller.setProperty("jaxb.formatted.output", true);
    marshaller.marshal(cmd, xmlReq);

    byte[] xmlResp = (byte[])template.requestBody("direct:test-with-session", xmlReq.toString());
    assertNotNull(xmlResp);

    ExecutionResults resp = (ExecutionResults)getJaxbContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xmlResp));
    assertNotNull(resp);

    assertEquals(1, resp.getIdentifiers().size());
    List<Person> list = (List<Person>)resp.getValue("elems");
    assertEquals("lucaz", list.get(0).getName());
    assertEquals("hadrian", list.get(1).getName());
    assertEquals("baunax", list.get(2).getName());

}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:33,代码来源:CamelEndpointWithJaxbTest.java


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