use of org.kie.server.api.model.definition.SearchQueryFilterSpec in project droolsjbpm-integration by kiegroup.
the class RuntimeDataServiceBase method queryProcessesByVariables.
public ProcessInstanceCustomVarsList queryProcessesByVariables(String payload, String payloadType, QueryContext queryContext) {
SearchQueryFilterSpec filter = new SearchQueryFilterSpec();
if (payload != null) {
filter = marshallerHelper.unmarshal(payload, payloadType, SearchQueryFilterSpec.class);
}
List<String> params = filter.getAttributesQueryParams().stream().map(e -> e.getColumn()).collect(toList());
params.removeAll(asList(TASK_ATTR_NAME, TASK_ATTR_OWNER, TASK_ATTR_STATUS));
if (params.size() == filter.getAttributesQueryParams().size() && filter.getTaskVariablesQueryParams().isEmpty()) {
return convertToProcessInstanceCustomVarsList(advanceRuntimeDataService.queryProcessByVariables(convertToServiceApiQueryParam(filter.getAttributesQueryParams()), convertToServiceApiQueryParam(filter.getProcessVariablesQueryParams()), queryContext));
}
return convertToProcessInstanceCustomVarsList(advanceRuntimeDataService.queryProcessByVariablesAndTask(convertToServiceApiQueryParam(filter.getAttributesQueryParams()), convertToServiceApiQueryParam(filter.getProcessVariablesQueryParams()), convertToServiceApiQueryParam(filter.getTaskVariablesQueryParams()), getOwnersQueryParam(filter), queryContext));
}
use of org.kie.server.api.model.definition.SearchQueryFilterSpec 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.definition.SearchQueryFilterSpec in project droolsjbpm-integration by kiegroup.
the class CaseServiceIntegrationTest method testQueryByVariable.
@Test
public void testQueryByVariable() {
Assume.assumeTrue(configuration.isRest());
String caseId = startCarInsuranceClaimCase(USER_YODA, USER_JOHN, USER_YODA);
Assertions.assertThat(caseId).isNotNull();
Assertions.assertThat(caseId).startsWith(CLAIM_CASE_ID_PREFIX);
CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
assertCarInsuranceCaseInstance(caseInstance, caseId, USER_YODA);
caseClient.closeCaseInstance(CONTAINER_ID, caseId, "work done at the moment");
CaseInstance closed = caseClient.getCaseInstance(CONTAINER_ID, caseId);
Assertions.assertThat(closed.getCaseStatus()).isEqualTo(2);
Assertions.assertThat(closed.getCompletionMessage()).isEqualTo("work done at the moment");
Map<String, Object> data = new HashMap<>();
data.put("additionalComment", "reopening the case");
caseClient.reopenCase(caseId, CONTAINER_ID, CLAIM_CASE_DEF_ID, data);
caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
Assertions.assertThat(caseInstance).isNotNull();
Assertions.assertThat(caseInstance.getCaseId()).isEqualTo(caseId);
Object additionalComment = caseClient.getCaseInstanceData(CONTAINER_ID, caseId, "additionalComment");
Assertions.assertThat(additionalComment).isNotNull();
Assertions.assertThat(additionalComment).isEqualTo("reopening the case");
List<QueryParam> attrs = list(equalsTo(CASE_ATTR_CORRELATION_KEY, caseId));
SearchQueryFilterSpec filter = new SearchQueryFilterSpec();
filter.setAttributesQueryParams(attrs);
List<CaseInstanceCustomVars> caseInstanceCustomVarsList = caseClient.queryCasesByVariables(filter, 0, 2);
assertNotNull(caseInstanceCustomVarsList);
Assertions.assertThat(caseInstanceCustomVarsList).hasSize(2);
attrs = list(likeTo(CASE_ATTR_CORRELATION_KEY, false, CLAIM_CASE_ID_PREFIX + "%"));
filter = new SearchQueryFilterSpec();
filter.setAttributesQueryParams(attrs);
caseInstanceCustomVarsList = caseClient.queryCasesByVariables(filter, 0, 2);
assertNotNull(caseInstanceCustomVarsList);
caseInstanceCustomVarsList.stream().forEach(e -> assertTrue(e.getCaseId().startsWith(CLAIM_CASE_ID_PREFIX)));
List<CaseUserTaskWithVariables> caseUserTaskWithVariablesList = caseClient.queryUserTaskByVariables(new SearchQueryFilterSpec(), 0, 2);
assertNotNull(caseUserTaskWithVariablesList);
Assertions.assertThat(caseUserTaskWithVariablesList.size()).isGreaterThan(0);
}
use of org.kie.server.api.model.definition.SearchQueryFilterSpec in project droolsjbpm-integration by kiegroup.
the class CaseManagementRuntimeDataServiceBase method queryCasesByVariables.
public CaseInstanceCustomVarsList queryCasesByVariables(String payload, String payloadType, QueryContext queryContext) {
SearchQueryFilterSpec filter = new SearchQueryFilterSpec();
if (payload != null) {
filter = marshallerHelper.unmarshal(payload, payloadType, SearchQueryFilterSpec.class);
}
List<String> params = filter.getAttributesQueryParams().stream().map(e -> e.getColumn()).collect(toList());
params.removeAll(asList(TASK_ATTR_NAME, TASK_ATTR_OWNER, TASK_ATTR_STATUS));
if (params.size() == filter.getAttributesQueryParams().size() && filter.getTaskVariablesQueryParams().isEmpty()) {
return convertToCaseInstanceCustomVarsList(advanceCaseRuntimeDataService.queryCaseByVariables(convertToServiceApiQueryParam(filter.getAttributesQueryParams()), convertToServiceApiQueryParam(filter.getCaseVariablesQueryParams()), queryContext));
} else {
return convertToCaseInstanceCustomVarsList(advanceCaseRuntimeDataService.queryCaseByVariablesAndTask(convertToServiceApiQueryParam(filter.getAttributesQueryParams()), convertToServiceApiQueryParam(filter.getTaskVariablesQueryParams()), convertToServiceApiQueryParam(filter.getCaseVariablesQueryParams()), filter.getOwners(), queryContext));
}
}
Aggregations