use of org.kie.server.client.QueryServicesClient in project kiegroup-examples by tkobayas.
the class KieServerRestUtils method getQueryServicesClient.
public static QueryServicesClient getQueryServicesClient(String username, String password) {
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(BASE_URL, username, password);
List<String> capabilities = new ArrayList<String>();
capabilities.add(KieServerConstants.CAPABILITY_BPM);
config.setCapabilities(capabilities);
// config.setMarshallingFormat(MarshallingFormat.JSON);
config.setMarshallingFormat(MarshallingFormat.JAXB);
KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
QueryServicesClient queryServiceClient = client.getServicesClient(QueryServicesClient.class);
return queryServiceClient;
}
use of org.kie.server.client.QueryServicesClient in project droolsjbpm-integration by kiegroup.
the class BaseKieServerClientKarafIntegrationTest method testCompleteInteractionWithKieServer.
protected void testCompleteInteractionWithKieServer(MarshallingFormat marshallingFormat) {
KieServicesConfiguration configuration = KieServicesFactory.newRestConfiguration(serverUrl, KieServerConstants.user, KieServerConstants.password);
configuration.setMarshallingFormat(marshallingFormat);
// configuration.addJaxbClasses(extraClasses);
// KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(configuration, kieContainer.getClassLoader());
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(configuration, this.getClass().getClassLoader());
// query for all available process definitions
QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
List<ProcessDefinition> processes = queryClient.findProcesses(0, 10);
System.out.println("\t######### Available processes" + processes);
ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
// get details of process definition
ProcessDefinition definition = processClient.getProcessDefinition(KieServerConstants.containerId, KieServerConstants.processId);
System.out.println("\t######### Definition details: " + definition);
// start process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("employee", KieServerConstants.user);
Long processInstanceId = processClient.startProcess(KieServerConstants.containerId, KieServerConstants.processId, params);
System.out.println("\t######### Process instance id: " + processInstanceId);
UserTaskServicesClient taskClient = kieServicesClient.getServicesClient(UserTaskServicesClient.class);
// find available tasks
List<TaskSummary> tasks = taskClient.findTasks(KieServerConstants.user, 0, 10);
System.out.println("\t######### Tasks: " + tasks);
// complete task
Long taskId = tasks.get(0).getId();
taskClient.startTask(KieServerConstants.containerId, taskId, KieServerConstants.user);
taskClient.completeTask(KieServerConstants.containerId, taskId, KieServerConstants.user, null);
// work with rules
List<ExecutableCommand<?>> commands = new ArrayList<ExecutableCommand<?>>();
BatchExecutionCommandImpl executionCommand = new BatchExecutionCommandImpl(commands);
executionCommand.setLookup("defaultKieSession");
InsertObjectCommand insertObjectCommand = new InsertObjectCommand();
insertObjectCommand.setOutIdentifier("person");
insertObjectCommand.setObject("john");
FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand();
commands.add(insertObjectCommand);
commands.add(fireAllRulesCommand);
RuleServicesClient ruleClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
ruleClient.executeCommands(KieServerConstants.containerId, executionCommand);
System.out.println("\t######### Rules executed");
// at the end abort process instance
processClient.abortProcessInstance(KieServerConstants.containerId, processInstanceId);
ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId);
System.out.println("\t######### ProcessInstance: " + processInstance);
}
use of org.kie.server.client.QueryServicesClient in project droolsjbpm-integration by kiegroup.
the class KieServerMigrationTest method testProcessStartAndAbort.
@Test
public void testProcessStartAndAbort() {
// query for all available process definitions
QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
ProcessAdminServicesClient processAdminClient = kieServicesClient.getServicesClient(ProcessAdminServicesClient.class);
// start process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("employee", "john");
params.put("reason", "test on spring boot");
Long processInstanceId = processClient.startProcess(containerId, processId, params);
assertNotNull(processInstanceId);
ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId);
assertNotNull(processInstance);
assertEquals(1, processInstance.getState().intValue());
assertEquals(containerId, processInstance.getContainerId());
try {
MigrationReportInstance report = processAdminClient.migrateProcessInstance(containerId, processInstanceId, containerId2, processId);
assertTrue(report.isSuccessful());
processInstance = queryClient.findProcessInstanceById(processInstanceId);
assertNotNull(processInstance);
assertEquals(1, processInstance.getState().intValue());
assertEquals(containerId2, processInstance.getContainerId());
} catch (Exception ex) {
// clean up if failure
try {
processClient.abortProcessInstance(containerId, processInstanceId);
} catch (Exception abortEx) {
logger.warn("Error aborting process instance over container " + containerId, abortEx);
}
fail("Migration failed: " + ex);
throw ex;
}
// abort process instance (outside try/catch), to not hide exception that will certainly occur if migration fails
processClient.abortProcessInstance(containerId2, processInstanceId);
processInstance = queryClient.findProcessInstanceById(processInstanceId);
assertNotNull(processInstance);
assertEquals(3, processInstance.getState().intValue());
}
use of org.kie.server.client.QueryServicesClient in project droolsjbpm-integration by kiegroup.
the class KieServerTest method testProcessStartAndAbortUsingAlias.
@Test
public void testProcessStartAndAbortUsingAlias() {
// query for all available process definitions
QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
List<ProcessDefinition> processes = queryClient.findProcesses(0, 10);
assertEquals(1, processes.size());
ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
// get details of process definition
ProcessDefinition definition = processClient.getProcessDefinition(containerId, processId);
assertNotNull(definition);
assertEquals(processId, definition.getId());
String resolvedContainerId = aliasResolver.latest(containerAlias);
// start process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("employee", "john");
params.put("reason", "test on spring boot");
Long processInstanceId = processClient.startProcess(resolvedContainerId, processId, params);
assertNotNull(processInstanceId);
resolvedContainerId = aliasResolver.forProcessInstance(containerAlias, processInstanceId);
// find active process instances
List<ProcessInstance> instances = queryClient.findProcessInstances(0, 10);
assertEquals(1, instances.size());
// at the end abort process instance
processClient.abortProcessInstance(resolvedContainerId, processInstanceId);
ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId);
assertNotNull(processInstance);
assertEquals(3, processInstance.getState().intValue());
}
use of org.kie.server.client.QueryServicesClient in project droolsjbpm-integration by kiegroup.
the class KieServerTest method testProcessStartAndAbort.
@Test
public void testProcessStartAndAbort() {
// query for all available process definitions
QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
List<ProcessDefinition> processes = queryClient.findProcesses(0, 10);
assertEquals(1, processes.size());
ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
// get details of process definition
ProcessDefinition definition = processClient.getProcessDefinition(containerId, processId);
assertNotNull(definition);
assertEquals(processId, definition.getId());
// start process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("employee", "john");
params.put("reason", "test on spring boot");
Long processInstanceId = processClient.startProcess(containerId, processId, params);
assertNotNull(processInstanceId);
// find active process instances
List<ProcessInstance> instances = queryClient.findProcessInstances(0, 10);
assertEquals(1, instances.size());
// at the end abort process instance
processClient.abortProcessInstance(containerId, processInstanceId);
ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId);
assertNotNull(processInstance);
assertEquals(3, processInstance.getState().intValue());
}
Aggregations