Search in sources :

Example 1 with QueryServicesClient

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;
}
Also used : QueryServicesClient(org.kie.server.client.QueryServicesClient) ArrayList(java.util.ArrayList) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient)

Example 2 with QueryServicesClient

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);
}
Also used : QueryServicesClient(org.kie.server.client.QueryServicesClient) HashMap(java.util.HashMap) UserTaskServicesClient(org.kie.server.client.UserTaskServicesClient) FireAllRulesCommand(org.drools.core.command.runtime.rule.FireAllRulesCommand) ArrayList(java.util.ArrayList) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) RuleServicesClient(org.kie.server.client.RuleServicesClient) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) BatchExecutionCommandImpl(org.drools.core.command.runtime.BatchExecutionCommandImpl) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ExecutableCommand(org.kie.api.command.ExecutableCommand) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) InsertObjectCommand(org.drools.core.command.runtime.rule.InsertObjectCommand)

Example 3 with QueryServicesClient

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());
}
Also used : QueryServicesClient(org.kie.server.client.QueryServicesClient) HashMap(java.util.HashMap) MigrationReportInstance(org.kie.server.api.model.admin.MigrationReportInstance) ProcessAdminServicesClient(org.kie.server.client.admin.ProcessAdminServicesClient) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with QueryServicesClient

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());
}
Also used : QueryServicesClient(org.kie.server.client.QueryServicesClient) HashMap(java.util.HashMap) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with QueryServicesClient

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());
}
Also used : QueryServicesClient(org.kie.server.client.QueryServicesClient) HashMap(java.util.HashMap) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

QueryServicesClient (org.kie.server.client.QueryServicesClient)12 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)10 Test (org.junit.Test)9 ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)8 HashMap (java.util.HashMap)7 ProcessServicesClient (org.kie.server.client.ProcessServicesClient)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 ArrayList (java.util.ArrayList)3 TaskSummary (org.kie.server.api.model.instance.TaskSummary)3 KieServicesClient (org.kie.server.client.KieServicesClient)3 KieServicesConfiguration (org.kie.server.client.KieServicesConfiguration)3 UserTaskServicesClient (org.kie.server.client.UserTaskServicesClient)3 MappingBuilder (com.github.tomakehurst.wiremock.client.MappingBuilder)2 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock (com.github.tomakehurst.wiremock.client.WireMock)1 WireMockRule (com.github.tomakehurst.wiremock.junit.WireMockRule)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1