本文整理汇总了Java中org.kie.api.command.Command类的典型用法代码示例。如果您正苦于以下问题:Java Command类的具体用法?Java Command怎么用?Java Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Command类属于org.kie.api.command包,在下文中一共展示了Command类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processRules
import org.kie.api.command.Command; //导入依赖的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;
}
示例2: doTest
import org.kie.api.command.Command; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void doTest() throws Exception {
ClaimTaskCommand claimTaskCmd = new ClaimTaskCommand();
claimTaskCmd.setTaskId(TASK_ID);
claimTaskCmd.setUserId(USER);
StartTaskCommand startTaskCmd = new StartTaskCommand();
startTaskCmd.setTaskId(TASK_ID);
startTaskCmd.setUserId(USER);
CompleteTaskCommand completeTaskCommand = new CompleteTaskCommand();
completeTaskCommand.setTaskId(TASK_ID);
completeTaskCommand.setUserId(USER);
List<Command> cmds = new ArrayList<>();
cmds.add(claimTaskCmd);
cmds.add(startTaskCmd);
cmds.add(completeTaskCommand);
executeCommand(cmds);
}
示例3: executeCommand
import org.kie.api.command.Command; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private List<JaxbCommandResponse<?>> executeCommand(List<Command> commands)
throws Exception {
URL address = new URL(APP_URL + "/rest/execute");
ClientRequest request = createRequest(address);
// NEEDED ON 6.1
request.header(JaxbSerializationProvider.EXECUTE_DEPLOYMENT_ID_HEADER,
DEPLOYMENT_ID);
JaxbCommandsRequest commandMessage = new JaxbCommandsRequest();
commandMessage.setCommands(commands);
commandMessage.setDeploymentId(DEPLOYMENT_ID);
String body = convertJaxbObjectToString(commandMessage);
System.out.println(body);
request.body(MediaType.APPLICATION_XML, body);
ClientResponse<String> responseObj = request.post(String.class);
String strResponse = responseObj.getEntity();
System.out.println("RESPONSE FROM THE SERVER: \n" + strResponse);
JaxbCommandsResponse cmdsResp = convertStringToJaxbObject(strResponse);
return cmdsResp.getResponses();
}
示例4: main
import org.kie.api.command.Command; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// Our list of commands to be executed;
List<Command> commands = new ArrayList<>();
/*
Create the signal event command and set the object
SignalEventCommand command = new SignalEventCommand();
command.setEventType("TEST");
command.setEvent(new Person("William", 27));
command.setProcessInstanceId(PROCESS_INSTANCE_ID);
commands.add(command);
*/
List<JaxbCommandResponse<?>> response = executeCommand(DEPLOYMENT_ID,
commands);
System.out.printf("Command %s executed.\n", response.toString());
System.out.println("commands1" + commands);
}
示例5: executeCommand
import org.kie.api.command.Command; //导入依赖的package包/类
static List<JaxbCommandResponse<?>> executeCommand(String deploymentId,
List<Command> commands) throws Exception {
URL address = new URL(APP_URL + "/execute");
ClientRequest request = createRequest(address);
// NEEDED ON 6.1
request.header(JaxbSerializationProvider.EXECUTE_DEPLOYMENT_ID_HEADER, DEPLOYMENT_ID);
JaxbCommandsRequest commandMessage = new JaxbCommandsRequest();
commandMessage.setCommands(commands);
commandMessage.setDeploymentId(DEPLOYMENT_ID);
String body = convertJaxbObjectToString(commandMessage);
request.body(MediaType.APPLICATION_XML, body);
ClientResponse<String> responseObj = request.post(String.class);
String strResponse = responseObj.getEntity();
System.out.println("RESPONSE FROM THE SERVER: \n" + strResponse);
JaxbCommandsResponse cmdsResp = convertStringToJaxbObject(strResponse);
return cmdsResp.getResponses();
}
示例6: executeCommand
import org.kie.api.command.Command; //导入依赖的package包/类
static List<JaxbCommandResponse<?>> executeCommand(String deploymentId,
List<Command> commands) throws Exception {
URL address = new URL(APP_URL + "/rest/execute");
ClientRequest request = createRequest(address);
// NEEDED ON 6.1
request.header(JaxbSerializationProvider.EXECUTE_DEPLOYMENT_ID_HEADER, DEPLOYMENT_ID);
JaxbCommandsRequest commandMessage = new JaxbCommandsRequest();
commandMessage.setCommands(commands);
commandMessage.setDeploymentId(DEPLOYMENT_ID);
String body = convertJaxbObjectToString(commandMessage);
request.body(MediaType.APPLICATION_XML, body);
ClientResponse<String> responseObj = request.post(String.class);
String strResponse = responseObj.getEntity();
System.out.println("RESPONSE FROM THE SERVER: \n" + strResponse);
JaxbCommandsResponse cmdsResp = convertStringToJaxbObject(strResponse);
return cmdsResp.getResponses();
}
示例7: main
import org.kie.api.command.Command; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// Our list of commands to be executed;
List<Command> commands = new ArrayList<>();
// a sample command to start a process
StartProcessCommand startProcessCommand = new StartProcessCommand();
JaxbStringObjectPairArray params = new JaxbStringObjectPairArray();
// Add your process parameters here
//params.getItems().add(new JaxbStringObjectPair(PROCESS_PARAM_NAME, new MyPOJO("My POJO TESTING")));
startProcessCommand.setProcessId(PROCESS_ID);
startProcessCommand.setParameter(params);
commands.add(startProcessCommand);
List<JaxbCommandResponse<?>> response = executeCommand(DEPLOYMENT_ID,
commands);
System.out.printf("Command %s executed.\n", response.toString());
System.out.println("commands1" + commands);
}
示例8: main
import org.kie.api.command.Command; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// Our list of commands to be executed;
List<Command> commands = new ArrayList<>();
// a sample command to start a process
StartProcessCommand startProcessCommand = new StartProcessCommand();
JaxbStringObjectPairArray params = new JaxbStringObjectPairArray();
// Add your process parameters here
// params.getItems().add(new JaxbStringObjectPair("p_person", new Person("William", 27)));
startProcessCommand.setProcessId(PROCESS_ID);
startProcessCommand.setParameter(params);
commands.add(startProcessCommand);
List<JaxbCommandResponse<?>> response = executeCommand(DEPLOYMENT_ID,
commands);
System.out.printf("Command %s executed.\n", response.toString());
System.out.println("commands1" + commands);
}
示例9: main
import org.kie.api.command.Command; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// Our list of commands to be executed;
List<Command> commands = new ArrayList<>();
// a sample command to start a process
StartProcessCommand startProcessCommand = new StartProcessCommand();
JaxbStringObjectPairArray params = new JaxbStringObjectPairArray();
// Add your process parameters here
Product prod = new Product(10, "Bread", 10f);
params.getItems().add(new JaxbStringObjectPair(PROCESS_PARAM_NAME, prod));
startProcessCommand.setProcessId(PROCESS_ID);
startProcessCommand.setParameter(params);
commands.add(startProcessCommand);
List<JaxbCommandResponse<?>> response = executeCommand(DEPLOYMENT_ID,
commands);
System.out.printf("Command %s executed.\n", response.toString());
System.out.println("commands1" + commands);
}
示例10: executeCommands
import org.kie.api.command.Command; //导入依赖的package包/类
@Test
public void executeCommands() {
System.out.println("== Sending commands to the server ==");
RuleServicesClient rulesClient = kieServicesClient
.getServicesClient(RuleServicesClient.class);
KieCommands commandsFactory = KieServices.Factory.get().getCommands();
Command<?> insert = commandsFactory.newInsert("Some String OBJ");
Command<?> fireAllRules = commandsFactory.newFireAllRules();
Command<?> batchCommand = commandsFactory.newBatchExecution(Arrays
.asList(insert, fireAllRules));
ServiceResponse<ExecutionResults> executeResponse = rulesClient
.executeCommandsWithResults(RULES_CONTAINER, batchCommand);
if (executeResponse.getType() == ResponseType.SUCCESS) {
System.out.println("Commands executed with success! Response: ");
System.out.println(executeResponse.getResult());
} else {
System.out.println("Error executing rules. Message: ");
System.out.println(executeResponse.getMsg());
}
}
示例11: executeCommands
import org.kie.api.command.Command; //导入依赖的package包/类
@Test
public void executeCommands() {
System.out.println("== Sending commands to the server ==");
RuleServicesClient rulesClient = kieServicesClient
.getServicesClient(RuleServicesClient.class);
KieCommands commandsFactory = KieServices.Factory.get().getCommands();
Command<?> insert = commandsFactory.newInsert("Some String OBJ");
Command<?> fireAllRules = commandsFactory.newFireAllRules();
Command<?> batchCommand = commandsFactory.newBatchExecution(Arrays
.asList(insert, fireAllRules));
ServiceResponse<ExecutionResults> executeResponse = rulesClient.executeCommandsWithResults(RULES_CONTAINER, batchCommand);
if (executeResponse.getType() == ResponseType.SUCCESS) {
System.out.println("Commands executed with success! Response: ");
System.out.println(executeResponse.getResult());
} else {
System.out.println("Error executing rules. Message: ");
System.out.println(executeResponse.getMsg());
}
}
示例12: start
import org.kie.api.command.Command; //导入依赖的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);
}
}
示例13: testExecutionResults
import org.kie.api.command.Command; //导入依赖的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()));
}
示例14: createRandomCommand
import org.kie.api.command.Command; //导入依赖的package包/类
public BatchExecutionCommand createRandomCommand() {
Person person = new Person();
String name = NAMES[random.nextInt(NAMES.length)];
person.setName(name);
List<Command<?>> cmds = new ArrayList<Command<?>>();
KieCommands commands = KieServices.Factory.get().getCommands();
cmds.add(commands.newInsert(person));
cmds.add(commands.newFireAllRules());
cmds.add(commands.newQuery("greetings", "get greeting"));
BatchExecutionCommand command = commands.newBatchExecution(cmds, "HelloRulesSession");
return command;
}
示例15: execute
import org.kie.api.command.Command; //导入依赖的package包/类
public Object execute(Command command, String containerId) {
BatchExecutionHelperProviderImpl batchExecutionHelperProviderImpl = new BatchExecutionHelperProviderImpl();
XStream xstream = batchExecutionHelperProviderImpl
.newXStreamMarshaller();
String payload = xstream.toXML(command);
LOG.debug("payload=" + payload);
ServiceResponse<String> serviceResponse = kieServicesClient
.executeCommands(containerId, payload);
if (serviceResponse.getType().equals(ResponseType.FAILURE)) {
throw new RuntimeException(serviceResponse.getMsg());
}
String response = serviceResponse.getResult();
LOG.debug("response=" + response);
return xstream.fromXML(response);
}