Search in sources :

Example 1 with ProcessDefinition

use of org.kie.server.api.model.definition.ProcessDefinition 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 2 with ProcessDefinition

use of org.kie.server.api.model.definition.ProcessDefinition in project droolsjbpm-integration by kiegroup.

the class RuntimeDataResource method getProcessesByDeploymentIdProcessId.

@ApiOperation(value = "Returns information about a specified process definition in a specified KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = ProcessDefinition.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_DEF_RESPONSE_JSON) })) })
@GET
@Path(PROCESS_DEFINITIONS_BY_CONTAINER_ID_DEF_ID_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessesByDeploymentIdProcessId(@Context HttpHeaders headers, @ApiParam(value = "container id that process definition belongs to", required = true) @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "process id to load process definition", required = true) @PathParam(PROCESS_ID) String processId) {
    Variant v = getVariant(headers);
    // no container id available so only used to transfer conversation id if given by client
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    ProcessDefinition processDesc = null;
    try {
        processDesc = runtimeDataServiceBase.getProcessesByDeploymentIdProcessId(containerId, processId);
        return createCorrectVariant(processDesc, headers, Response.Status.OK, conversationIdHeader);
    } catch (IllegalArgumentException e) {
        return notFound(MessageFormat.format(PROCESS_DEFINITION_NOT_FOUND, processId, containerId), v, conversationIdHeader);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with ProcessDefinition

use of org.kie.server.api.model.definition.ProcessDefinition in project droolsjbpm-integration by kiegroup.

the class ProcessClientIntegrationTest method testGetProcessDefinition.

@Test
public void testGetProcessDefinition() {
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("containerId", CONTAINER_ID);
    parameters.put("processId", PROCESS_ID);
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("process");
    executionServerCommand.setOperation("getProcessDefinition");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(ProcessDefinition.class);
    final ProcessDefinition processDefinition = (ProcessDefinition) response;
    Assertions.assertThat(processDefinition.getName()).isEqualTo(PROCESS_ID);
    Assertions.assertThat(processDefinition.getVersion()).isEqualTo("1.0");
}
Also used : HashMap(java.util.HashMap) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Example 4 with ProcessDefinition

use of org.kie.server.api.model.definition.ProcessDefinition in project droolsjbpm-integration by kiegroup.

the class QueryClientIntegrationTest method testFindProcessesById.

@Test
public void testFindProcessesById() {
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("processId", PROCESS_ID);
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("query");
    executionServerCommand.setOperation("findProcessesById");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(List.class);
    final List<ProcessDefinition> processDefinitions = (List<ProcessDefinition>) response;
    Assertions.assertThat(processDefinitions).isNotEmpty();
    final List<String> processIds = processDefinitions.stream().map(p -> p.getId()).collect(Collectors.toList());
    Assertions.assertThat(processIds).contains(PROCESS_ID);
}
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) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) List(java.util.List) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Example 5 with ProcessDefinition

use of org.kie.server.api.model.definition.ProcessDefinition in project droolsjbpm-integration by kiegroup.

the class QueryClientIntegrationTest method testFindProcessByContainerIdProcessId.

@Test
public void testFindProcessByContainerIdProcessId() {
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("containerId", CONTAINER_ID);
    parameters.put("processId", PROCESS_ID);
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("query");
    executionServerCommand.setOperation("findProcessByContainerIdProcessId");
    executionServerCommand.setParameters(parameters);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(ProcessDefinition.class);
    final ProcessDefinition processDefinition = (ProcessDefinition) response;
    Assertions.assertThat(processDefinition.getContainerId()).isEqualTo(CONTAINER_ID);
    Assertions.assertThat(processDefinition.getId()).isEqualTo(PROCESS_ID);
}
Also used : HashMap(java.util.HashMap) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Aggregations

ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)24 Test (org.junit.Test)19 HashMap (java.util.HashMap)16 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)10 QueryServicesClient (org.kie.server.client.QueryServicesClient)8 List (java.util.List)6 ExecutionServerCommand (org.kie.camel.container.api.ExecutionServerCommand)6 ProcessServicesClient (org.kie.server.client.ProcessServicesClient)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Collectors (java.util.stream.Collectors)4 Arrays (java.util.Arrays)3 Map (java.util.Map)3 Assertions (org.assertj.core.api.Assertions)3 ServiceResponse (org.kie.server.api.model.ServiceResponse)3 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)3 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)2 ArrayList (java.util.ArrayList)2 CommandScript (org.kie.server.api.commands.CommandScript)2 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)2 KieServerCommand (org.kie.server.api.model.KieServerCommand)2