Search in sources :

Example 1 with ProcessInstanceCustomVars

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

the class QueryDataServiceIntegrationTest method testGetProcessInstanceCustomMapper.

@Test
public void testGetProcessInstanceCustomMapper() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(CONTAINER_ID));
    Long pid = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    QueryDefinition query = new QueryDefinition();
    query.setName("jbpmProcessWithVarsSearch");
    query.setSource(System.getProperty("org.kie.server.persistence.ds", "jdbc/jbpm-ds"));
    query.setExpression("select p. PROCESSINSTANCEID, p.PROCESSID,  p.PROCESSNAME, p.PROCESSVERSION, p.STATUS,  " + "p.EXTERNALID, pr.STARTDATE as START_DATE,   p.USER_IDENTITY, p.PROCESSINSTANCEDESCRIPTION, " + "p.CORRELATIONKEY, p.PARENTPROCESSINSTANCEID, pr.LASTMODIFICATIONDATE, var.variableId, var.value " + "from PROCESSINSTANCELOG p inner join PROCESSINSTANCEINFO pr on p.PROCESSINSTANCEID = pr.INSTANCEID " + "inner join (select v.processInstanceId, v.variableId, v.value from VariableInstanceLog v " + "where v.id = (select MAX(vil.id) from VariableInstanceLog vil " + "where v.variableId = vil.variableId and v.processInstanceId = vil.processInstanceId)) var " + "on  p.PROCESSINSTANCEID = var.PROCESSINSTANCEID");
    query.setTarget("CUSTOM");
    try {
        queryClient.registerQuery(query);
        List<ProcessInstanceCustomVars> instance = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_PI_CUSTOM, 0, 10, ProcessInstanceCustomVars.class);
        assertNotNull(instance);
        assertEquals(1, instance.size());
        final Map<String, Object> variables = instance.get(0).getVariables();
        assertNotNull(variables);
        assertEquals(3, variables.size());
        assertEquals(TestConfig.getUsername(), variables.get("initiator"));
        assertEquals("waiting for signal", variables.get("stringData"));
        assertEquals(parameters.get("personData").toString(), variables.get("personData"));
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, pid);
        queryClient.unregisterQuery(query.getName());
    }
}
Also used : ProcessInstanceCustomVars(org.kie.server.api.model.instance.ProcessInstanceCustomVars) QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with ProcessInstanceCustomVars

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

the class ConvertUtils method convertToProcessInstanceCustomVarsList.

public static ProcessInstanceCustomVarsList convertToProcessInstanceCustomVarsList(Collection<ProcessInstanceCustomDesc> instances) {
    if (instances == null) {
        return new ProcessInstanceCustomVarsList(new org.kie.server.api.model.instance.ProcessInstanceCustomVars[0]);
    }
    List<ProcessInstanceCustomVars> processInstances = new ArrayList<ProcessInstanceCustomVars>(instances.size());
    for (ProcessInstanceCustomDesc pi : instances) {
        org.kie.server.api.model.instance.ProcessInstanceCustomVars instance = convertToProcessInstanceCustomVars(pi);
        processInstances.add(instance);
    }
    return new ProcessInstanceCustomVarsList(processInstances);
}
Also used : ProcessInstanceCustomVars(org.kie.server.api.model.instance.ProcessInstanceCustomVars) ArrayList(java.util.ArrayList) ProcessInstanceCustomVarsList(org.kie.server.api.model.instance.ProcessInstanceCustomVarsList) ProcessInstanceCustomVars(org.kie.server.api.model.instance.ProcessInstanceCustomVars) ProcessInstanceCustomDesc(org.jbpm.services.api.model.ProcessInstanceCustomDesc)

Example 3 with ProcessInstanceCustomVars

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

the class ConvertUtils method convertToProcessInstanceCustomVarsList.

public static ProcessInstanceCustomVarsList convertToProcessInstanceCustomVarsList(List<ProcessInstanceWithVarsDesc> data) {
    List<ProcessInstanceCustomVars> processInstances = new ArrayList<>();
    for (ProcessInstanceWithVarsDesc proc : data) {
        ProcessInstanceCustomVars tmp = new ProcessInstanceCustomVars();
        tmp.setId(proc.getId());
        tmp.setVariables(proc.getVariables());
        tmp.setProcessId(proc.getProcessId());
        tmp.setCorrelationKey(proc.getCorrelationKey());
        tmp.setContainerId(proc.getDeploymentId());
        tmp.setProcessName(proc.getProcessName());
        tmp.setProcessVersion(proc.getProcessVersion());
        tmp.setDate(proc.getDataTimeStamp());
        tmp.setInitiator(proc.getInitiator());
        tmp.setState(proc.getState());
        processInstances.add(tmp);
    }
    ProcessInstanceCustomVarsList result = new ProcessInstanceCustomVarsList();
    result.setProcessInstances(processInstances.stream().toArray(ProcessInstanceCustomVars[]::new));
    return result;
}
Also used : ProcessInstanceCustomVars(org.kie.server.api.model.instance.ProcessInstanceCustomVars) ProcessInstanceWithVarsDesc(org.jbpm.services.api.model.ProcessInstanceWithVarsDesc) ArrayList(java.util.ArrayList) ProcessInstanceCustomVarsList(org.kie.server.api.model.instance.ProcessInstanceCustomVarsList)

Example 4 with ProcessInstanceCustomVars

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

the class RuntimeDataServiceIntegrationTest method testQueryProcessesByVariables.

@Test
public void testQueryProcessesByVariables() throws Exception {
    Assume.assumeTrue(configuration.isRest());
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    List<TaskSummary> tasks = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, null, 0, 10);
    Assertions.assertThat(tasks).hasSize(1);
    SearchQueryFilterSpec spec = new SearchQueryFilterSpec();
    spec.setAttributesQueryParams(list(equalsTo(PROCESS_ATTR_DEPLOYMENT_ID, CONTAINER_ID)));
    List<ProcessInstanceCustomVars> listProcesses = queryClient.queryProcessesByVariables(spec, 0, 2);
    Assertions.assertThat(listProcesses).extracting(ProcessInstanceCustomVars::getContainerId).containsOnly(CONTAINER_ID);
    SearchQueryFilterSpec specHistory = new SearchQueryFilterSpec();
    specHistory.setAttributesQueryParams(list(history(), equalsTo(PROCESS_ATTR_DEPLOYMENT_ID, CONTAINER_ID)));
    List<ProcessInstanceCustomVars> listHistoryProcesses = queryClient.queryProcessesByVariables(specHistory, 0, 2, "processInstanceId", false);
    assertNotNull(listHistoryProcesses);
    listHistoryProcesses.stream().forEach(e -> assertEquals(CONTAINER_ID, e.getContainerId()));
    spec = new SearchQueryFilterSpec();
    spec.setAttributesQueryParams(list(onlyActiveTasks(), equalsTo(PROCESS_ATTR_DEFINITION_ID, PROCESS_ID_USERTASK)));
    List<ProcessInstanceUserTaskWithVariables> listTasks = queryClient.queryUserTaskByVariables(spec, 0, 2, "processInstanceId", true);
    Assertions.assertThat(listTasks).hasSize(1).extracting(ProcessInstanceUserTaskWithVariables::getProcessDefinitionId).containsOnly(PROCESS_ID_USERTASK);
    this.taskClient.startTask(CONTAINER_ID, listTasks.get(0).getId(), "yoda");
    this.taskClient.completeTask(CONTAINER_ID, listTasks.get(0).getId(), "yoda", Collections.emptyMap());
    spec = new SearchQueryFilterSpec();
    spec.setAttributesQueryParams(list(onlyCompletedTasks(), equalsTo(PROCESS_ATTR_DEFINITION_ID, PROCESS_ID_USERTASK)));
    listTasks = queryClient.queryUserTaskByVariables(spec, 0, 2, "task.id", false);
    Assertions.assertThat(listTasks).hasSize(1);
    spec = new SearchQueryFilterSpec();
    spec.setAttributesQueryParams(list(onlyActiveTasks(), equalsTo(PROCESS_ATTR_DEFINITION_ID, PROCESS_ID_USERTASK)));
    listTasks = queryClient.queryUserTaskByVariables(spec, 0, 2, "task.id", true);
    Assertions.assertThat(listTasks).hasSize(1);
    this.taskClient.startTask(CONTAINER_ID, listTasks.get(0).getId(), "yoda");
    this.taskClient.completeTask(CONTAINER_ID, listTasks.get(0).getId(), "yoda", Collections.emptyMap());
    spec = new SearchQueryFilterSpec();
    spec.setAttributesQueryParams(list(onlyActiveTasks(), equalsTo(PROCESS_ATTR_DEFINITION_ID, PROCESS_ID_USERTASK)));
    listTasks = queryClient.queryUserTaskByVariables(spec, 0, 2);
    Assertions.assertThat(listTasks).isEmpty();
    spec = new SearchQueryFilterSpec();
    spec.setAttributesQueryParams(list(onlyCompletedTasks(), equalsTo(PROCESS_ATTR_DEFINITION_ID, PROCESS_ID_USERTASK)));
    listTasks = queryClient.queryUserTaskByVariables(spec, 0, 2);
    Assertions.assertThat(listTasks).isEmpty();
}
Also used : ProcessInstanceCustomVars(org.kie.server.api.model.instance.ProcessInstanceCustomVars) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) SearchQueryFilterSpec(org.kie.server.api.model.definition.SearchQueryFilterSpec) ProcessInstanceUserTaskWithVariables(org.kie.server.api.model.instance.ProcessInstanceUserTaskWithVariables) Test(org.junit.Test)

Example 5 with ProcessInstanceCustomVars

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

the class QueryDataServiceIntegrationTest method testGetProcessInstanceCustomWithoutVarsMapper.

@Test
public void testGetProcessInstanceCustomWithoutVarsMapper() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(CONTAINER_ID));
    Long pid = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    QueryDefinition query = new QueryDefinition();
    query.setName("jbpmProcessSearch");
    query.setSource(System.getProperty("org.kie.server.persistence.ds", "jdbc/jbpm-ds"));
    query.setExpression("select p.PROCESSINSTANCEID, p.PROCESSID,  p.PROCESSNAME, p.PROCESSVERSION, p.STATUS,  p.EXTERNALID, " + "pr.STARTDATE as START_DATE,   p.USER_IDENTITY, p.PROCESSINSTANCEDESCRIPTION, p.CORRELATIONKEY, " + "p.PARENTPROCESSINSTANCEID, pr.LASTMODIFICATIONDATE from PROCESSINSTANCELOG p " + "inner join PROCESSINSTANCEINFO pr on p.PROCESSINSTANCEID = pr.INSTANCEID");
    query.setTarget("CUSTOM");
    try {
        queryClient.registerQuery(query);
        List<ProcessInstanceCustomVars> instance = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_PI_CUSTOM, 0, 10, ProcessInstanceCustomVars.class);
        assertNotNull(instance);
        assertEquals(1, instance.size());
        assertNull(instance.get(0).getVariables());
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, pid);
        queryClient.unregisterQuery(query.getName());
    }
}
Also used : ProcessInstanceCustomVars(org.kie.server.api.model.instance.ProcessInstanceCustomVars) QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

ProcessInstanceCustomVars (org.kie.server.api.model.instance.ProcessInstanceCustomVars)5 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)2 ProcessInstanceCustomVarsList (org.kie.server.api.model.instance.ProcessInstanceCustomVarsList)2 ProcessInstanceCustomDesc (org.jbpm.services.api.model.ProcessInstanceCustomDesc)1 ProcessInstanceWithVarsDesc (org.jbpm.services.api.model.ProcessInstanceWithVarsDesc)1 SearchQueryFilterSpec (org.kie.server.api.model.definition.SearchQueryFilterSpec)1 ProcessInstanceUserTaskWithVariables (org.kie.server.api.model.instance.ProcessInstanceUserTaskWithVariables)1 TaskSummary (org.kie.server.api.model.instance.TaskSummary)1