Search in sources :

Example 1 with UserTaskInstanceWithPotOwnerDesc

use of org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc 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;
}
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 2 with UserTaskInstanceWithPotOwnerDesc

use of org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc 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 3 with UserTaskInstanceWithPotOwnerDesc

use of org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc 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 4 with UserTaskInstanceWithPotOwnerDesc

use of org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc in project jbpm by kiegroup.

the class UserTaskInstanceWithModifVarsQueryMapper method map.

@Override
public List<UserTaskInstanceWithPotOwnerDesc> map(Object result) {
    if (result instanceof DataSet) {
        DataSet dataSetResult = (DataSet) result;
        List<UserTaskInstanceWithPotOwnerDesc> mappedResult = new ArrayList<UserTaskInstanceWithPotOwnerDesc>();
        if (dataSetResult != null) {
            Map<Long, UserTaskInstanceWithPotOwnerDesc> tmp = new HashMap<Long, UserTaskInstanceWithPotOwnerDesc>();
            for (int i = 0; i < dataSetResult.getRowCount(); i++) {
                Long taskId = getColumnLongValue(dataSetResult, COLUMN_TASKID, i);
                UserTaskInstanceWithPotOwnerDesc ut = tmp.get(taskId);
                if (ut == null) {
                    ut = buildInstance(dataSetResult, i);
                    mappedResult.add(ut);
                    tmp.put(taskId, ut);
                } else if (!tmp.get(taskId).getPotentialOwners().contains(getColumnStringValue(dataSetResult, COLUMN_POTOWNER, i))) {
                    ((org.jbpm.kie.services.impl.model.UserTaskInstanceWithPotOwnerDesc) ut).addPotOwner(getColumnStringValue(dataSetResult, COLUMN_POTOWNER, i));
                }
                String varName = getColumnStringValue(dataSetResult, COLUMN_TASK_VAR_NAME, i);
                String varValue = getColumnStringValue(dataSetResult, COLUMN_TASK_VAR_VALUE, i);
                if (getColumnIntValue(dataSetResult, COLUMN_TASK_VAR_TYPE, i) == 0) {
                    ((org.jbpm.kie.services.impl.model.UserTaskInstanceWithPotOwnerDesc) ut).addInputdata(varName, varValue);
                } else {
                    ((org.jbpm.kie.services.impl.model.UserTaskInstanceWithPotOwnerDesc) ut).addOutputdata(varName, varValue);
                }
            }
        }
        return mappedResult;
    }
    throw new IllegalArgumentException("Unsupported result for mapping " + result);
}
Also used : UserTaskInstanceWithPotOwnerDesc(org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc) DataSet(org.dashbuilder.dataset.DataSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 5 with UserTaskInstanceWithPotOwnerDesc

use of org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc in project jbpm by kiegroup.

the class UserTaskInstanceWithPotOwnerQueryMapper method map.

@Override
public List<UserTaskInstanceWithPotOwnerDesc> map(Object result) {
    if (result instanceof DataSet) {
        DataSet dataSetResult = (DataSet) result;
        List<UserTaskInstanceWithPotOwnerDesc> mappedResult = new ArrayList<UserTaskInstanceWithPotOwnerDesc>();
        if (dataSetResult != null) {
            Map<Long, UserTaskInstanceWithPotOwnerDesc> tmp = new HashMap<Long, UserTaskInstanceWithPotOwnerDesc>();
            for (int i = 0; i < dataSetResult.getRowCount(); i++) {
                Long taskId = getColumnLongValue(dataSetResult, COLUMN_TASKID, i);
                UserTaskInstanceWithPotOwnerDesc ut = tmp.get(taskId);
                if (ut == null) {
                    ut = buildInstance(dataSetResult, i);
                    mappedResult.add(ut);
                    tmp.put(taskId, ut);
                } else if (getColumnStringValue(dataSetResult, COLUMN_POTOWNER, i) != null) {
                    ((org.jbpm.kie.services.impl.model.UserTaskInstanceWithPotOwnerDesc) ut).addPotOwner(getColumnStringValue(dataSetResult, COLUMN_POTOWNER, i));
                }
            }
        }
        return mappedResult;
    }
    throw new IllegalArgumentException("Unsupported result for mapping " + result);
}
Also used : UserTaskInstanceWithPotOwnerDesc(org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc) DataSet(org.dashbuilder.dataset.DataSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Aggregations

HashMap (java.util.HashMap)5 UserTaskInstanceWithPotOwnerDesc (org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc)5 ArrayList (java.util.ArrayList)3 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)3 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)3 Test (org.junit.Test)3 QueryContext (org.kie.api.runtime.query.QueryContext)3 DataSet (org.dashbuilder.dataset.DataSet)2 UserTaskPotOwnerQueryBuilderFactory (org.jbpm.kie.services.impl.query.builder.UserTaskPotOwnerQueryBuilderFactory)1 QueryParamBuilderFactory (org.jbpm.services.api.query.QueryParamBuilderFactory)1