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());
}
}
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);
}
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;
}
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();
}
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());
}
}
Aggregations