Search in sources :

Example 16 with SqlQueryDefinition

use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.

the class QueryServiceEJBIntegrationTest method testGetProcessInstancesByState.

@Test
public void testGetProcessInstancesByState() {
    query = new SqlQueryDefinition("getAllProcessInstances", "java:jboss/datasources/ExampleDS");
    query.setExpression("select * from processinstancelog");
    queryService.registerQuery(query);
    Collection<ProcessInstanceDesc> instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(instances);
    assertEquals(0, instances.size());
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    // search for aborted only
    instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_STATUS, 3));
    assertNotNull(instances);
    assertEquals(0, instances.size());
    // aborted and active
    instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_STATUS, 3, 1));
    assertNotNull(instances);
    assertEquals(1, instances.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
    // aborted only
    instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_STATUS, 3));
    assertNotNull(instances);
    assertEquals(1, instances.size());
    assertEquals(3, (int) instances.iterator().next().getState());
}
Also used : SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) Test(org.junit.Test)

Example 17 with SqlQueryDefinition

use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.

the class QueryServiceEJBIntegrationTest method testGetTaskInstancesWithVariables.

@Test
public void testGetTaskInstancesWithVariables() {
    query = new SqlQueryDefinition("getAllTaskInputInstancesWithVariables", "java:jboss/datasources/ExampleDS");
    query.setExpression("select ti.*, tv.name tvname, tv.value tvvalue from AuditTaskImpl ti " + "inner join (select tv.taskId, tv.name, tv.value from TaskVariableImpl tv where tv.type = 0 ) tv " + "on (tv.taskId = ti.taskId)");
    queryService.registerQuery(query);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approval_document", "initial content");
    params.put("approval_translatedDocument", "translated content");
    params.put("approval_reviewComment", "reviewed content");
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
    assertNotNull(processInstanceId);
    List<UserTaskInstanceWithVarsDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    UserTaskInstanceWithVarsDesc instance = taskInstanceLogs.get(0);
    assertEquals(5, instance.getVariables().size());
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_TASK_VAR_NAME, "Comment"), QueryParam.equalsTo(COLUMN_TASK_VAR_VALUE, "Write a Document"));
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    instance = taskInstanceLogs.get(0);
    assertEquals(1, instance.getVariables().size());
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_TASK_VAR_NAME, "Comment"), QueryParam.equalsTo(COLUMN_TASK_VAR_VALUE, "Wrong Comment"));
    assertNotNull(taskInstanceLogs);
    assertEquals(0, taskInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : HashMap(java.util.HashMap) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) UserTaskInstanceWithVarsDesc(org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc) QueryContext(org.kie.api.runtime.query.QueryContext) Test(org.junit.Test)

Example 18 with SqlQueryDefinition

use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.

the class QueryServiceEJBIntegrationTest method testGetTaskInstancesAsBA.

@Test
public void testGetTaskInstancesAsBA() {
    query = new SqlQueryDefinition("getBATaskInstances", "java:jboss/datasources/ExampleDS", Target.BA_TASK);
    query.setExpression("select ti.*, oe.id OEID from AuditTaskImpl ti," + "PeopleAssignments_BAs bas, " + "OrganizationalEntity oe " + "where ti.taskId = bas.task_id and bas.entity_id = oe.id ");
    queryService.registerQuery(query);
    List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
    assertNotNull(queries);
    assertEquals(1, queries.size());
    QueryDefinition registeredQuery = queries.get(0);
    assertNotNull(registeredQuery);
    assertEquals(query.getName(), registeredQuery.getName());
    assertEquals(query.getSource(), registeredQuery.getSource());
    assertEquals(query.getExpression(), registeredQuery.getExpression());
    assertEquals(query.getTarget(), registeredQuery.getTarget());
    registeredQuery = queryService.getQuery(query.getName());
    assertNotNull(registeredQuery);
    assertEquals(query.getName(), registeredQuery.getName());
    assertEquals(query.getSource(), registeredQuery.getSource());
    assertEquals(query.getExpression(), registeredQuery.getExpression());
    assertEquals(query.getTarget(), registeredQuery.getTarget());
    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<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(0, taskInstanceLogs.size());
    identityProvider.setName("Administrator");
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    identityProvider.setName("salaboy");
    identityProvider.setRoles(Arrays.asList("Administrators"));
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryDefinition(org.jbpm.services.api.query.model.QueryDefinition) HashMap(java.util.HashMap) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryContext(org.kie.api.runtime.query.QueryContext) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) Test(org.junit.Test)

Example 19 with SqlQueryDefinition

use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.

the class QueryServiceImplTest method testGetProcessInstances.

@Test
public void testGetProcessInstances() {
    query = new SqlQueryDefinition("getAllProcessInstances", dataSourceJNDIname);
    query.setExpression("select * from processinstancelog");
    queryService.registerQuery(query);
    List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
    assertNotNull(queries);
    assertEquals(1, queries.size());
    QueryDefinition registeredQuery = queries.get(0);
    assertNotNull(registeredQuery);
    assertEquals(query.getName(), registeredQuery.getName());
    assertEquals(query.getSource(), registeredQuery.getSource());
    assertEquals(query.getExpression(), registeredQuery.getExpression());
    assertEquals(query.getTarget(), registeredQuery.getTarget());
    registeredQuery = queryService.getQuery(query.getName());
    assertNotNull(registeredQuery);
    assertEquals(query.getName(), registeredQuery.getName());
    assertEquals(query.getSource(), registeredQuery.getSource());
    assertEquals(query.getExpression(), registeredQuery.getExpression());
    assertEquals(query.getTarget(), registeredQuery.getTarget());
    Collection<ProcessInstanceDesc> instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(instances);
    assertEquals(0, instances.size());
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(instances);
    assertEquals(1, instances.size());
    assertEquals(1, (int) instances.iterator().next().getState());
    // search using named mapper to refer to query mappers by name
    instances = queryService.query(query.getName(), new NamedQueryMapper<Collection<ProcessInstanceDesc>>("ProcessInstances"), new QueryContext());
    assertNotNull(instances);
    assertEquals(1, instances.size());
    assertEquals(1, (int) instances.iterator().next().getState());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
    instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(COLUMN_PROCESSNAME, false));
    assertNotNull(instances);
    assertEquals(1, instances.size());
    assertEquals(3, (int) instances.iterator().next().getState());
}
Also used : SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryDefinition(org.jbpm.services.api.query.model.QueryDefinition) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) NamedQueryMapper(org.jbpm.services.api.query.NamedQueryMapper) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 20 with SqlQueryDefinition

use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.

the class QueryServiceImplTest method testGetTaskInstances.

@Test
public void testGetTaskInstances() {
    query = new SqlQueryDefinition("getAllTaskInstances", dataSourceJNDIname);
    query.setExpression("select ti.* from AuditTaskImpl ti ");
    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<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : HashMap(java.util.HashMap) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)38 Test (org.junit.Test)37 QueryContext (org.kie.api.runtime.query.QueryContext)37 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)29 AdvancedQueryContext (org.kie.api.runtime.query.AdvancedQueryContext)23 HashMap (java.util.HashMap)22 QueryDefinition (org.jbpm.services.api.query.model.QueryDefinition)20 ArrayList (java.util.ArrayList)11 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)11 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)9 List (java.util.List)7 UserTaskInstanceWithVarsDesc (org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc)4 QueryParam (org.jbpm.services.api.query.model.QueryParam)4 Date (java.util.Date)3 ProcessInstanceWithVarsDesc (org.jbpm.services.api.model.ProcessInstanceWithVarsDesc)3 UserTaskInstanceWithPotOwnerDesc (org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc)3 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)3 TaskSummary (org.kie.api.task.model.TaskSummary)3 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)3 SimpleDateFormat (java.text.SimpleDateFormat)2