Search in sources :

Example 86 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class UserTaskInstanceWithPotOwnerTest method testSearchTaskByPotOwnerQueryParamBuilder.

@Test
public void testSearchTaskByPotOwnerQueryParamBuilder() {
    query = new SqlQueryDefinition("jbpmHumanTasksPO", dataSourceJNDIname);
    query.setExpression("select t.actualowner_id as actualowner, t.CREATEDBY_ID as createdby, t.CREATEDON as CREATEDON, t.EXPIRATIONTIME as expirationDate, " + "t.id as TASKID, t.name as NAME, t.priority as PRIORITY, t.PROCESSINSTANCEID as PROCESSINSTANCEID, t.PROCESSID as PROCESSID, t.STATUS as STATUS,  " + "po.entity_id as POTOWNER, t.FORMNAME AS FORMNAME, p.processinstancedescription as PROCESSINSTANCEDESCRIPTION, t.subject as SUBJECT, t.deploymentid as DEPLOYMENTID " + "from TASK t " + "inner join PEOPLEASSIGNMENTS_POTOWNERS po on t.id=po.task_id " + "inner join PROCESSINSTANCELOG p on t.processinstanceid = p.processinstanceid");
    queryService.registerQuery(query);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approval_document", "initial content");
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
    assertNotNull(processInstanceId);
    List<UserTaskInstanceWithPotOwnerDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithPotOwnerQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    assertNotNull(taskInstanceLogs.get(0).getProcessInstanceDescription());
    QueryParamBuilderFactory qbFactory = new UserTaskPotOwnerQueryBuilderFactory();
    assertTrue(qbFactory.accept("potOwnerBuilder"));
    List<String> potOwners = new ArrayList<String>();
    potOwners.add("salaboy");
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("potOwner", potOwners);
    QueryParamBuilder<?> paramBuilder = qbFactory.newInstance(parameters);
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithPotOwnerQueryMapper.get(), new QueryContext(), paramBuilder);
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    potOwners = new ArrayList<String>();
    potOwners.add("wrongPotOwner");
    parameters = new HashMap<String, Object>();
    parameters.put("potOwner", potOwners);
    paramBuilder = qbFactory.newInstance(parameters);
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithPotOwnerQueryMapper.get(), new QueryContext(), paramBuilder);
    assertNotNull(taskInstanceLogs);
    assertEquals(0, taskInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : UserTaskPotOwnerQueryBuilderFactory(org.jbpm.kie.services.impl.query.builder.UserTaskPotOwnerQueryBuilderFactory) UserTaskInstanceWithPotOwnerDesc(org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QueryContext(org.kie.api.runtime.query.QueryContext) QueryParamBuilderFactory(org.jbpm.services.api.query.QueryParamBuilderFactory) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 87 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class UserTaskInstanceWithPotOwnerTest method testSearchTaskWithModifVarsMapper.

@Test
public void testSearchTaskWithModifVarsMapper() {
    query = new SqlQueryDefinition("jbpmGetTaskWithPO", dataSourceJNDIname);
    query.setExpression("select t.id as TASKID, t.name as NAME,  t.FORMNAME AS FORMNAME, t.subject as SUBJECT, " + "t.actualowner_id as ACTUALOWNER, po.entity_id as POTOWNER, p.processinstancedescription as PROCESSINSTANCEDESCRIPTION, t.CREATEDON as CREATEDON, " + "t.CREATEDBY_ID as CREATEDBY, t.EXPIRATIONTIME as EXPIRATIONTIME, " + "(select max(logtime) from taskevent where processinstanceid = t.processinstanceid and taskid = t.id) as lastmodificationdate, " + "(select userid from taskevent where logtime = (select max(logtime) from taskevent where processinstanceid = t.processinstanceid and taskid = t.id)) as lastmodificationuser, " + "t.priority as PRIORITY, t.STATUS as STATUS, t.PROCESSINSTANCEID as PROCESSINSTANCEID, t.PROCESSID as PROCESSID, " + "t.deploymentid as DEPLOYMENTID, d.name as TVNAME, d.type as TVTYPE, d.value as TVVALUE " + "from TASK t " + "inner join PEOPLEASSIGNMENTS_POTOWNERS po on t.id=po.task_id " + "inner join PROCESSINSTANCELOG p on t.processinstanceid = p.processinstanceid " + "inner join TASKVARIABLEIMPL d on t.id=d.taskid");
    queryService.registerQuery(query);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approval_document", "initial content");
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
    assertNotNull(processInstanceId);
    List<UserTaskInstanceWithPotOwnerDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithModifVarsQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithModifVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_POTOWNER, wrongUser));
    assertNotNull(taskInstanceLogs);
    assertEquals(0, taskInstanceLogs.size());
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithModifVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_POTOWNER, correctUser));
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithModifVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_POTOWNER, correctUser));
    assertNotNull(taskInstanceLogs.get(0).getLastModificationUser());
    assertNotNull(taskInstanceLogs.get(0).getProcessInstanceDescription());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : UserTaskInstanceWithPotOwnerDesc(org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc) HashMap(java.util.HashMap) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryContext(org.kie.api.runtime.query.QueryContext) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 88 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class ProcessServiceImplTest method testStartProcessCallActivityCheckNodes.

@Test
public void testStartProcessCallActivityCheckNodes() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    assertNotNull(processService);
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "ParentProcess");
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(processInstanceId);
    assertNotNull(pi);
    Collection<ProcessInstanceDesc> children = runtimeDataService.getProcessInstancesByParent(processInstanceId, null, new QueryContext());
    assertNotNull(children);
    assertEquals(1, children.size());
    ProcessInstanceDesc childInstance = children.iterator().next();
    assertNotNull(childInstance);
    assertEquals("org.jbpm.signal", childInstance.getProcessId());
    Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstanceDesc activeNode = activeNodes.iterator().next();
    assertNotNull(activeNode);
    assertEquals("SubProcessNode", activeNode.getNodeType());
    assertEquals(childInstance.getId(), activeNode.getReferenceId());
    processService.signalProcessInstance(childInstance.getId(), "MySignal", null);
    children = runtimeDataService.getProcessInstancesByParent(processInstanceId, Arrays.asList(2, 3), new QueryContext());
    assertNotNull(children);
    assertEquals(1, children.size());
    childInstance = children.iterator().next();
    assertNotNull(childInstance);
    assertEquals("org.jbpm.signal", childInstance.getProcessId());
    pi = processService.getProcessInstance(processInstanceId);
    assertNull(pi);
    Collection<NodeInstanceDesc> completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstanceId, new QueryContext());
    assertNotNull(completedNodes);
    assertEquals(3, completedNodes.size());
    NodeInstanceDesc completedNode = completedNodes.stream().filter(n -> n.getNodeType().equals("SubProcessNode")).findFirst().orElse(null);
    assertNotNull(completedNode);
    assertEquals("SubProcessNode", completedNode.getNodeType());
    assertEquals(childInstance.getId(), completedNode.getReferenceId());
}
Also used : ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 89 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class ProcessServiceImplWithDeploymentIdTest method testStartProcessAndCompleteWorkItem.

@Test
public void testStartProcessAndCompleteWorkItem() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
    assertTrue(isDeployed);
    assertNotNull(processService);
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(deploymentUnit.getIdentifier(), processInstanceId);
    assertNotNull(pi);
    Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    assertEquals("Write a Document", activeNodes.iterator().next().getName());
    Map<String, Object> outcome = new HashMap<String, Object>();
    outcome.put("Result", "here is my first document");
    processService.completeWorkItem(deploymentUnit.getIdentifier(), processInstanceId, activeNodes.iterator().next().getWorkItemId(), outcome);
    activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(2, activeNodes.size());
    Object variableValue = processService.getProcessInstanceVariable(deploymentUnit.getIdentifier(), processInstanceId, "approval_document");
    assertNotNull(variableValue);
    assertTrue(variableValue instanceof String);
    assertEquals("here is my first document", variableValue);
    processService.abortProcessInstance(deploymentUnit.getIdentifier(), processInstanceId);
    pi = processService.getProcessInstance(deploymentUnit.getIdentifier(), processInstanceId);
    assertNull(pi);
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 90 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class ProcessServiceImplWithDeploymentIdTest method testStartProcessAndGetWorkItem.

@Test
public void testStartProcessAndGetWorkItem() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
    assertTrue(isDeployed);
    assertNotNull(processService);
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(deploymentUnit.getIdentifier(), processInstanceId);
    assertNotNull(pi);
    Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    assertEquals("Write a Document", activeNodes.iterator().next().getName());
    WorkItem wi = processService.getWorkItem(deploymentUnit.getIdentifier(), processInstanceId, activeNodes.iterator().next().getWorkItemId());
    assertNotNull(wi);
    assertEquals("Human Task", wi.getName());
    assertEquals("Write a Document", wi.getParameter("NodeName"));
    processService.abortProcessInstance(deploymentUnit.getIdentifier(), processInstanceId);
    pi = processService.getProcessInstance(deploymentUnit.getIdentifier(), processInstanceId);
    assertNull(pi);
}
Also used : ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) WorkItem(org.kie.api.runtime.process.WorkItem) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

QueryContext (org.kie.api.runtime.query.QueryContext)315 Test (org.junit.Test)299 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)131 HashMap (java.util.HashMap)115 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)109 ArrayList (java.util.ArrayList)99 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)67 RequestInfo (org.kie.api.executor.RequestInfo)53 TaskSummary (org.kie.api.task.model.TaskSummary)53 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)51 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)49 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)45 CommandContext (org.kie.api.executor.CommandContext)39 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)37 UserImpl (org.jbpm.services.task.impl.model.UserImpl)37 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)36 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)34 QueryFilter (org.kie.internal.query.QueryFilter)30 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)29 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)29