Search in sources :

Example 1 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class QueryServicesClientImpl method findProcessInstanceByCorrelationKey.

@Override
public ProcessInstance findProcessInstanceByCorrelationKey(CorrelationKey correlationKey) {
    ProcessInstance result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CORRELATION_KEY, correlationKey.toExternalForm());
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCE_BY_CORRELATION_KEY_GET_URI, valuesMap), ProcessInstance.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstanceByCorrelationKey", new Object[] { correlationKey.toExternalForm() })));
        ServiceResponse<ProcessInstance> response = (ServiceResponse<ProcessInstance>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        return response.getResult();
    }
    return result;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance)

Example 2 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class TaskAssigningIntegrationTest method task_assigning_with_skills.

@Test
public void task_assigning_with_skills() {
    // Skip for MySQL and MariaDB until PLANNER-2079 is fixed
    assumeFalse(TestConfig.isMySqlDataSource());
    assumeFalse(TestConfig.isMariaDbDataSource());
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("cardType", "VISA");
    parameters.put("language", "ZH");
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID, parameters);
    // maciek is in the CreditAnalyst group and has a VISA skill => should be assigned to the ResolveDispute task.
    doNextTaskByUser("maciek");
    // mary is in the ClientRelations group and has a ZH (Chinese) skill => should be assigned to the NotifyCustomer task.
    doNextTaskByUser("mary");
    ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.getState().intValue()).isEqualTo(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED);
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieServerBaseIntegrationTest(org.kie.server.integrationtests.shared.basetests.KieServerBaseIntegrationTest) Test(org.junit.Test)

Example 3 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance 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 4 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class AbstractRemoteIntegrationTest method findActiveProcesses.

protected List<ProcessInstance> findActiveProcesses() {
    final List<Integer> statuses = Arrays.asList(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE);
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("status", statuses);
    parameters.put("page", "0");
    parameters.put("pageSize", "100");
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("query");
    executionServerCommand.setOperation("findProcessInstancesByStatus");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    final List<ProcessInstance> processInstances = (List<ProcessInstance>) response;
    return processInstances;
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) List(java.util.List) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand)

Example 5 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class QueryClientIntegrationTest method testFindProcessInstancesByStatus.

@Test
public void testFindProcessInstancesByStatus() {
    final Long processInstanceId = startProcess(CONTAINER_ID, PROCESS_WITH_SIGNAL_ID);
    final List<Integer> statuses = Arrays.asList(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE);
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("status", statuses);
    parameters.put("page", "0");
    parameters.put("pageSize", "10");
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("query");
    executionServerCommand.setOperation("findProcessInstancesByStatus");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(List.class);
    final List<ProcessInstance> processInstances = (List<ProcessInstance>) response;
    Assertions.assertThat(processInstances).isNotEmpty();
    final List<Long> processInstancesIds = processInstances.stream().map(p -> p.getId()).collect(Collectors.toList());
    Assertions.assertThat(processInstancesIds).contains(processInstanceId);
    sendSignalToProcessInstance(CONTAINER_ID, processInstanceId, SIGNAL_NAME);
}
Also used : Arrays(java.util.Arrays) List(java.util.List) QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) HashMap(java.util.HashMap) Test(org.junit.Test) Collectors(java.util.stream.Collectors) HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) List(java.util.List) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Aggregations

ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)125 Test (org.junit.Test)97 HashMap (java.util.HashMap)75 TaskSummary (org.kie.server.api.model.instance.TaskSummary)31 ArrayList (java.util.ArrayList)24 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)22 KieServicesException (org.kie.server.api.exception.KieServicesException)17 ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)11 List (java.util.List)9 QueryServicesClient (org.kie.server.client.QueryServicesClient)9 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)9 Category (org.junit.experimental.categories.Category)7 CorrelationKey (org.kie.internal.process.CorrelationKey)7 CorrelationKeyFactory (org.kie.internal.process.CorrelationKeyFactory)7 ProcessServicesClient (org.kie.server.client.ProcessServicesClient)7 Arrays (java.util.Arrays)6 Map (java.util.Map)6 Assertions (org.assertj.core.api.Assertions)6 After (org.junit.After)6 TaskInstance (org.kie.server.api.model.instance.TaskInstance)6