use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.
the class UserTaskInstanceWithPotOwnerTest method testSearchTaskByPotOwnerMapper.
@Test
public void testSearchTaskByPotOwnerMapper() {
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());
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithPotOwnerQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_POTOWNER, wrongUser));
assertNotNull(taskInstanceLogs);
assertEquals(0, taskInstanceLogs.size());
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithPotOwnerQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_POTOWNER, correctUser));
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 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;
}
use of org.jbpm.kie.services.impl.query.SqlQueryDefinition 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;
}
use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetFilteredTaskInstancesAsBA.
@Test
public void testGetFilteredTaskInstancesAsBA() {
// let's grant managers role so process can be started
List<String> roles = new ArrayList<String>();
roles.add("managers");
identityProvider.setRoles(roles);
query = new SqlQueryDefinition("getTaskInstancesAdmin", dataSourceJNDIname, Target.FILTERED_BA_TASK);
query.setExpression("select 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.taskId, ti.workItemId, oe.id " + "from AuditTaskImpl ti left join PeopleAssignments_BAs ba on ti.taskId = ba.task_id left join " + "OrganizationalEntity oe on ba.entity_id = oe.id");
queryService.registerQuery(query);
List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
assertNotNull(queries);
assertEquals(1, queries.size());
QueryDefinition 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(), QueryParam.groupBy(COLUMN_TASKID));
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 testGetTaskInstancesWithVariables.
@Test
public void testGetTaskInstancesWithVariables() {
query = new SqlQueryDefinition("getAllTaskInputInstancesWithVariables", dataSourceJNDIname);
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(3, 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;
}
Aggregations