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