Search in sources :

Example 1 with SearchQueryFilterSpec

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));
}
Also used : ConvertUtils.buildQueryFilter(org.kie.server.services.jbpm.ConvertUtils.buildQueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) KieServerConstants(org.kie.server.api.KieServerConstants) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) LoggerFactory(org.slf4j.LoggerFactory) ConvertUtils.convertToServiceApiQueryParam(org.kie.server.services.jbpm.ConvertUtils.convertToServiceApiQueryParam) ConvertUtils.convertToVariablesList(org.kie.server.services.jbpm.ConvertUtils.convertToVariablesList) QueryParam(org.jbpm.services.api.query.model.QueryParam) ConvertUtils.convertToProcessInstance(org.kie.server.services.jbpm.ConvertUtils.convertToProcessInstance) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) KieInternalServices(org.kie.internal.KieInternalServices) TaskEvent(org.kie.internal.task.api.model.TaskEvent) CountDefinition(org.kie.server.api.model.definition.CountDefinition) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) ConvertUtils.convertToProcessInstanceCustomVarsList(org.kie.server.services.jbpm.ConvertUtils.convertToProcessInstanceCustomVarsList) QueryParam.all(org.jbpm.services.api.query.model.QueryParam.all) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Collection(java.util.Collection) ConvertUtils.buildTaskStatuses(org.kie.server.services.jbpm.ConvertUtils.buildTaskStatuses) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) QueryContext(org.kie.api.runtime.query.QueryContext) VariableInstanceList(org.kie.server.api.model.instance.VariableInstanceList) AuditTask(org.kie.internal.task.api.AuditTask) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) List(java.util.List) ConvertUtils.buildQueryContext(org.kie.server.services.jbpm.ConvertUtils.buildQueryContext) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) ConvertUtils.convertToProcess(org.kie.server.services.jbpm.ConvertUtils.convertToProcess) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) ProcessInstanceCustomVarsList(org.kie.server.api.model.instance.ProcessInstanceCustomVarsList) TaskEventInstance(org.kie.server.api.model.instance.TaskEventInstance) ConvertUtils.convertToTaskSummaryList(org.kie.server.services.jbpm.ConvertUtils.convertToTaskSummaryList) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) Status(org.kie.api.task.model.Status) TaskEventInstanceList(org.kie.server.api.model.instance.TaskEventInstanceList) TASK_ATTR_NAME(org.jbpm.services.api.AdvanceRuntimeDataService.TASK_ATTR_NAME) ConvertUtils.convertToTask(org.kie.server.services.jbpm.ConvertUtils.convertToTask) ConvertUtils.convertToNodeInstanceList(org.kie.server.services.jbpm.ConvertUtils.convertToNodeInstanceList) EntryType(org.jbpm.services.api.RuntimeDataService.EntryType) ConvertUtils.convertToProcessInstanceList(org.kie.server.services.jbpm.ConvertUtils.convertToProcessInstanceList) MarshallerHelper(org.kie.server.services.impl.marshal.MarshallerHelper) HashMap(java.util.HashMap) QueryFilter(org.kie.internal.query.QueryFilter) ArrayList(java.util.ArrayList) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) TaskSummaryList(org.kie.server.api.model.instance.TaskSummaryList) TASK_ATTR_OWNER(org.jbpm.services.api.AdvanceRuntimeDataService.TASK_ATTR_OWNER) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) TASK_ATTR_STATUS(org.jbpm.services.api.AdvanceRuntimeDataService.TASK_ATTR_STATUS) ProcessInstanceUserTaskWithVariablesList(org.kie.server.api.model.instance.ProcessInstanceUserTaskWithVariablesList) IdentityProvider(org.kie.internal.identity.IdentityProvider) ConvertUtils.convertToNodeInstance(org.kie.server.services.jbpm.ConvertUtils.convertToNodeInstance) ConvertUtils.convertToProcessList(org.kie.server.services.jbpm.ConvertUtils.convertToProcessList) Logger(org.slf4j.Logger) ConvertUtils.buildTaskByNameQueryFilter(org.kie.server.services.jbpm.ConvertUtils.buildTaskByNameQueryFilter) VariableDesc(org.jbpm.services.api.model.VariableDesc) CorrelationKey(org.kie.internal.process.CorrelationKey) TaskInstance(org.kie.server.api.model.instance.TaskInstance) SearchQueryFilterSpec(org.kie.server.api.model.definition.SearchQueryFilterSpec) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) ConvertUtils.nullEmpty(org.kie.server.services.jbpm.ConvertUtils.nullEmpty) Collectors.toList(java.util.stream.Collectors.toList) AdvanceRuntimeDataService(org.jbpm.services.api.AdvanceRuntimeDataService) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) ConvertUtils.convertToUserTaskWithVariablesList(org.kie.server.services.jbpm.ConvertUtils.convertToUserTaskWithVariablesList) ContainerLocatorProvider(org.kie.server.services.impl.locator.ContainerLocatorProvider) SearchQueryFilterSpec(org.kie.server.api.model.definition.SearchQueryFilterSpec)

Example 2 with SearchQueryFilterSpec

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();
}
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 3 with SearchQueryFilterSpec

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);
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) HashMap(java.util.HashMap) QueryParam(org.kie.server.api.model.definition.QueryParam) SearchQueryFilterSpec(org.kie.server.api.model.definition.SearchQueryFilterSpec) CaseInstanceCustomVars(org.kie.server.api.model.cases.CaseInstanceCustomVars) CaseUserTaskWithVariables(org.kie.server.api.model.cases.CaseUserTaskWithVariables) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 4 with SearchQueryFilterSpec

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));
    }
}
Also used : CaseDefinitionList(org.kie.server.api.model.cases.CaseDefinitionList) TaskSummary(org.kie.api.task.model.TaskSummary) CaseInstanceCustomVarsList(org.kie.server.api.model.cases.CaseInstanceCustomVarsList) CaseUserTaskWithVariablesList(org.kie.server.api.model.cases.CaseUserTaskWithVariablesList) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieServerConstants(org.kie.server.api.KieServerConstants) CaseStage(org.kie.server.api.model.cases.CaseStage) ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) MarshallerHelper(org.kie.server.services.impl.marshal.MarshallerHelper) CaseFileDataItemList(org.kie.server.api.model.cases.CaseFileDataItemList) ConvertUtils.convertToServiceApiQueryParam(org.kie.server.services.casemgmt.ConvertUtils.convertToServiceApiQueryParam) CaseInstance(org.kie.server.api.model.cases.CaseInstance) ArrayList(java.util.ArrayList) CaseRuntimeDataService(org.jbpm.casemgmt.api.CaseRuntimeDataService) TASK_ATTR_OWNER(org.jbpm.casemgmt.api.AdvanceCaseRuntimeDataService.TASK_ATTR_OWNER) CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) TaskSummaryList(org.kie.server.api.model.instance.TaskSummaryList) Arrays.asList(java.util.Arrays.asList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) CaseStageList(org.kie.server.api.model.cases.CaseStageList) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) TASK_ATTR_NAME(org.jbpm.casemgmt.api.AdvanceCaseRuntimeDataService.TASK_ATTR_NAME) IdentityProvider(org.kie.internal.identity.IdentityProvider) CaseMilestone(org.kie.server.api.model.cases.CaseMilestone) ConvertUtils.convertToCaseInstanceCustomVarsList(org.kie.server.services.casemgmt.ConvertUtils.convertToCaseInstanceCustomVarsList) CaseMilestoneList(org.kie.server.api.model.cases.CaseMilestoneList) NodeInstance(org.kie.server.api.model.instance.NodeInstance) TASK_ATTR_STATUS(org.jbpm.casemgmt.api.AdvanceCaseRuntimeDataService.TASK_ATTR_STATUS) Collection(java.util.Collection) QueryContext(org.kie.api.runtime.query.QueryContext) SearchQueryFilterSpec(org.kie.server.api.model.definition.SearchQueryFilterSpec) AdvanceCaseRuntimeDataService(org.jbpm.casemgmt.api.AdvanceCaseRuntimeDataService) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) List(java.util.List) CaseAdHocFragmentList(org.kie.server.api.model.cases.CaseAdHocFragmentList) Collectors.toList(java.util.stream.Collectors.toList) CaseAdHocFragment(org.kie.server.api.model.cases.CaseAdHocFragment) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) Status(org.kie.api.task.model.Status) ContainerLocatorProvider(org.kie.server.services.impl.locator.ContainerLocatorProvider) SearchQueryFilterSpec(org.kie.server.api.model.definition.SearchQueryFilterSpec)

Aggregations

SearchQueryFilterSpec (org.kie.server.api.model.definition.SearchQueryFilterSpec)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)2 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)2 Test (org.junit.Test)2 QueryContext (org.kie.api.runtime.query.QueryContext)2 Status (org.kie.api.task.model.Status)2 TaskSummary (org.kie.api.task.model.TaskSummary)2 IdentityProvider (org.kie.internal.identity.IdentityProvider)2 KieServerConstants (org.kie.server.api.KieServerConstants)2 CaseInstance (org.kie.server.api.model.cases.CaseInstance)2 Arrays (java.util.Arrays)1 Map (java.util.Map)1 AdvanceCaseRuntimeDataService (org.jbpm.casemgmt.api.AdvanceCaseRuntimeDataService)1 TASK_ATTR_NAME (org.jbpm.casemgmt.api.AdvanceCaseRuntimeDataService.TASK_ATTR_NAME)1