use of org.jbpm.services.api.query.model.QueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetProcessInstancesGroupWithoutInterval.
@Test
public void testGetProcessInstancesGroupWithoutInterval() {
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());
QueryParam[] parameters = QueryParam.getBuilder().append(QueryParam.groupBy(COLUMN_START)).get();
Collection<List<Object>> instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters);
assertNotNull(instances);
assertEquals(0, instances.size());
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
long processInstanceId2 = processService.startProcess(deploymentUnit.getIdentifier(), "org.jboss.qa.bpms.HumanTask");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
// expected date is day when processes started
String expectedDate = sdf.format(new Date());
instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters);
assertNotNull(instances);
assertEquals(1, instances.size());
// write document process
List<Object> result = instances.iterator().next();
assertNotNull(result);
assertEquals(1, result.size());
assertEquals(expectedDate, result.get(0));
processService.abortProcessInstance(processInstanceId2);
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.services.api.query.model.QueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetProcessInstancesGroupWithInterval.
@Test
public void testGetProcessInstancesGroupWithInterval() {
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());
QueryParam[] parameters = QueryParam.getBuilder().append(QueryParam.groupBy(COLUMN_START, QueryParam.DAY, 30)).get();
Collection<List<Object>> instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters);
assertNotNull(instances);
assertEquals(0, instances.size());
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
long processInstanceId2 = processService.startProcess(deploymentUnit.getIdentifier(), "org.jboss.qa.bpms.HumanTask");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// expected date is day when processes started
String expectedDate = sdf.format(new Date());
instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters);
assertNotNull(instances);
assertEquals(1, instances.size());
// write document process
List<Object> result = instances.iterator().next();
assertNotNull(result);
assertEquals(1, result.size());
assertEquals(expectedDate, result.get(0));
processService.abortProcessInstance(processInstanceId2);
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.services.api.query.model.QueryDefinition in project jbpm by kiegroup.
the class UserTaskAdminServiceImplTest method testGetTaskInstancesAsPotOwners.
@Test
public void testGetTaskInstancesAsPotOwners() {
String PO_TASK_QUERY = "select ti.taskId, ti.activationTime, ti.actualOwner, ti.createdBy, ti.createdOn, ti.deploymentId, " + "ti.description, ti.dueDate, ti.name, ti.parentId, ti.priority, ti.processId, ti.processInstanceId, " + "ti.processSessionId, ti.status, ti.workItemId, oe.id, eo.entity_id " + "from AuditTaskImpl ti " + "left join PeopleAssignments_PotOwners po on ti.taskId = po.task_id " + "left join OrganizationalEntity oe on po.entity_id = oe.id " + " left join PeopleAssignments_ExclOwners eo on ti.taskId = eo.task_id ";
SqlQueryDefinition query = new SqlQueryDefinition("getMyTaskInstances", "jdbc/testDS1", Target.PO_TASK);
query.setExpression(PO_TASK_QUERY);
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);
identityProvider.setName("notvalid");
List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(0, taskInstanceLogs.size());
identityProvider.setName("salaboy");
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
List<TaskSummary> taskSummaries = queryService.query(query.getName(), TaskSummaryQueryMapper.get(), new QueryContext());
assertNotNull(taskSummaries);
assertEquals(1, taskSummaries.size());
identityProvider.setName("Administrator");
userTaskAdminService.addPotentialOwners(taskSummaries.get(0).getId(), false, factory.newUser("john"));
identityProvider.setName("salaboy");
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
taskSummaries = queryService.query(query.getName(), TaskSummaryQueryMapper.get(), new QueryContext());
assertNotNull(taskSummaries);
assertEquals(1, taskSummaries.size());
QueryParam[] parameters = QueryParam.getBuilder().append(QueryParam.groupBy(COLUMN_NAME)).append(QueryParam.count(COLUMN_TASKID)).get();
Collection<List<Object>> instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters);
assertNotNull(instances);
assertEquals(1, instances.size());
List<Object> result = instances.iterator().next();
assertNotNull(result);
assertEquals(2, result.size());
// here we have count set to 2 because group by is on name and thus it returns duplicates
assertTrue(result.get(1) instanceof Number);
assertEquals(2, ((Number) result.get(1)).intValue());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.services.api.query.model.QueryDefinition in project jbpm by kiegroup.
the class UserTaskAdminServiceImplTest method testGetTaskInstancesAsPotOwnersMultipleInstances.
@Test
public void testGetTaskInstancesAsPotOwnersMultipleInstances() {
String PO_TASK_QUERY = "select ti.taskId, ti.activationTime, ti.actualOwner, ti.createdBy, ti.createdOn, ti.deploymentId, " + "ti.description, ti.dueDate, ti.name, ti.parentId, ti.priority, ti.processId, ti.processInstanceId, " + "ti.processSessionId, ti.status, ti.workItemId, oe.id, eo.entity_id " + "from AuditTaskImpl ti " + "left join PeopleAssignments_PotOwners po on ti.taskId = po.task_id " + "left join OrganizationalEntity oe on po.entity_id = oe.id " + " left join PeopleAssignments_ExclOwners eo on ti.taskId = eo.task_id ";
SqlQueryDefinition query = new SqlQueryDefinition("getMyTaskInstances", "jdbc/testDS1", Target.PO_TASK);
query.setExpression(PO_TASK_QUERY);
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);
Long processInstanceId2 = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
assertNotNull(processInstanceId);
assertNotNull(processInstanceId2);
identityProvider.setName("notvalid");
List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(0, taskInstanceLogs.size());
identityProvider.setName("salaboy");
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(2, taskInstanceLogs.size());
identityProvider.setName("Administrator");
userTaskAdminService.addPotentialOwners(taskInstanceLogs.get(0).getTaskId(), false, factory.newUser("john"));
identityProvider.setName("salaboy");
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(2, taskInstanceLogs.size());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
processService.abortProcessInstance(processInstanceId2);
processInstanceId2 = null;
}
use of org.jbpm.services.api.query.model.QueryDefinition in project jbpm by kiegroup.
the class QueryServiceImpl method init.
public void init() {
if (dataSetDefRegistry == null && dataSetManager == null && providerRegistry == null) {
dataSetDefRegistry = DataSetCore.get().getDataSetDefRegistry();
dataSetManager = DataSetCore.get().getDataSetManager();
providerRegistry = DataSetCore.get().getDataSetProviderRegistry();
providerRegistry.registerDataProvider(SQLDataSetProvider.get());
dataSetDefRegistry.addListener(new PersistDataSetListener(commandService));
}
// load previously registered query definitions
if (commandService != null) {
List<QueryDefinitionEntity> queries = commandService.execute(new QueryNameCommand<List<QueryDefinitionEntity>>("getQueryDefinitions"));
for (QueryDefinitionEntity entity : queries) {
QueryDefinition definition = entity.toQueryDefinition();
try {
registerQuery(definition);
} catch (QueryAlreadyRegisteredException e) {
logger.debug("Query {} already registered, skipping...", definition.getName());
}
}
}
}
Aggregations