Search in sources :

Example 1 with TaskStatus

use of org.wso2.carbon.humantask.core.dao.TaskStatus in project carbon-business-process by wso2.

the class TaskOperationServiceImpl method simpleQuery.

public TTaskSimpleQueryResultSet simpleQuery(final TSimpleQueryInput tSimpleQueryInput) throws IllegalStateFault, IllegalArgumentFault {
    final int[] taskCount = new int[1];
    try {
        List<TaskDAO> matchingTasks = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<List<TaskDAO>>() {

            public List<TaskDAO> call() throws Exception {
                HumanTaskDAOConnection daoConn = HumanTaskServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection();
                SimpleQueryCriteria queryCriteria = TransformerUtils.transformSimpleTaskQuery(tSimpleQueryInput);
                queryCriteria.setCallerTenantId(CarbonContext.getThreadLocalCarbonContext().getTenantId());
                queryCriteria.setCaller(getCaller());
                // queryCriteria.setPageSize(HumanTaskConstants.ITEMS_PER_PAGE);
                TStatus[] statuses = tSimpleQueryInput.getStatus();
                Set<TaskStatus> statusSet = new HashSet<TaskStatus>();
                if (statuses != null && statuses.length > 0) {
                    for (TStatus status : statuses) {
                        try {
                            TaskStatus taskStatus = TaskStatus.valueOf(status.getTStatus().toUpperCase());
                            statusSet.add(taskStatus);
                        } catch (IllegalArgumentException ex) {
                            new IllegalArgumentFault(" Invalid Status ");
                        }
                    }
                }
                if (!statusSet.isEmpty()) {
                    queryCriteria.setStatuses(new ArrayList(statusSet));
                }
                if (statuses != null && statuses.length > 0) {
                    for (TStatus status : statuses) {
                        try {
                            TaskStatus taskStatus = TaskStatus.valueOf(status.getTStatus().toUpperCase());
                            statusSet.add(taskStatus);
                        } catch (IllegalArgumentException ex) {
                            new IllegalArgumentFault("Invalid Status");
                        }
                    }
                }
                if (!statusSet.isEmpty()) {
                    queryCriteria.setStatuses(new ArrayList(statusSet));
                }
                taskCount[0] = daoConn.getTasksCount(queryCriteria);
                if (log.isDebugEnabled()) {
                    log.debug("No of tasks in the db : " + taskCount[0]);
                }
                return daoConn.searchTasks(queryCriteria);
            }
        });
        int taskListSize = matchingTasks.size();
        int pageSize = tSimpleQueryInput.getPageSize() > 0 ? tSimpleQueryInput.getPageSize() : HumanTaskConstants.ITEMS_PER_PAGE;
        int pages = (int) Math.ceil((double) taskCount[0] / pageSize);
        if (log.isDebugEnabled()) {
            log.debug("No of task pages : " + pages + " with " + pageSize + " tasks per page");
        }
        TaskDAO[] instanceArray = matchingTasks.toArray(new TaskDAO[taskListSize]);
        TTaskSimpleQueryResultSet resultSet = new TTaskSimpleQueryResultSet();
        resultSet.setPages(pages);
        for (int i = 0; i < taskListSize; i++) {
            resultSet.addRow(TransformerUtils.transformToSimpleQueryRow(instanceArray[i]));
        }
        return resultSet;
    } catch (HumanTaskIllegalStateException ex) {
        log.error(ex);
        throw new IllegalStateFault(ex);
    } catch (Exception ex) {
        log.error(ex);
        throw new IllegalArgumentFault(ex);
    }
}
Also used : IllegalStateFault(org.wso2.carbon.humantask.client.api.IllegalStateFault) TTaskSimpleQueryResultSet(org.wso2.carbon.humantask.client.api.types.TTaskSimpleQueryResultSet) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) TaskStatus(org.wso2.carbon.humantask.core.dao.TaskStatus) TTaskSimpleQueryResultSet(org.wso2.carbon.humantask.client.api.types.TTaskSimpleQueryResultSet) TStatus(org.wso2.carbon.humantask.client.api.types.TStatus) TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) ArrayList(java.util.ArrayList) List(java.util.List) HumanTaskDAOConnection(org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection) IllegalArgumentFault(org.wso2.carbon.humantask.client.api.IllegalArgumentFault) SimpleQueryCriteria(org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria)

Example 2 with TaskStatus

use of org.wso2.carbon.humantask.core.dao.TaskStatus in project carbon-business-process by wso2.

the class TransformerUtils method transformToSimpleQueryRow.

// /**
// * @param matchingTasks :
// * @return :
// */
// public static TTaskSimpleQueryResultSet createSimpleQueryResultSet(
// List<TaskDAO> matchingTasks) {
// 
// TTaskSimpleQueryResultSet resultSet = new TTaskSimpleQueryResultSet();
// 
// for (TaskDAO matchingTask : matchingTasks) {
// resultSet.addRow(transformToSimpleQueryRow(matchingTask));
// }
// 
// return resultSet;
// }
/**
 * @param matchingTask :
 * @return :
 */
public static TTaskSimpleQueryResultRow transformToSimpleQueryRow(TaskDAO matchingTask) {
    TTaskSimpleQueryResultRow row = new TTaskSimpleQueryResultRow();
    row.setName(QName.valueOf(matchingTask.getDefinitionName()));
    row.setTaskType(matchingTask.getType().toString());
    try {
        row.setId(new URI(matchingTask.getId().toString()));
    } catch (URI.MalformedURIException e) {
        throw new HumanTaskRuntimeException("The task id :[" + matchingTask.getId() + "] is invalid", e);
    }
    Calendar createdTime = Calendar.getInstance();
    createdTime.setTime(matchingTask.getCreatedOn());
    row.setCreatedTime(createdTime);
    // set the task priority.
    TPriority priority = new TPriority();
    priority.setTPriority(BigInteger.valueOf(matchingTask.getPriority()));
    row.setPriority(priority);
    // set the task status
    TStatus taskStatus = new TStatus();
    taskStatus.setTStatus(matchingTask.getStatus().toString());
    row.setStatus(taskStatus);
    row.setPresentationSubject((transformPresentationSubject(CommonTaskUtil.getDefaultPresentationSubject(matchingTask))));
    row.setPresentationName(transformPresentationName(CommonTaskUtil.getDefaultPresentationName(matchingTask)));
    return row;
}
Also used : Calendar(java.util.Calendar) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) URI(org.apache.axis2.databinding.types.URI)

Example 3 with TaskStatus

use of org.wso2.carbon.humantask.core.dao.TaskStatus in project carbon-business-process by wso2.

the class HumanTaskJPQLQueryBuilder method buildAssignedToMeQuery.

// Creates the JPQL query to list tasks assigned for the particular user.
private Query buildAssignedToMeQuery() {
    boolean hasStatus = false;
    List<TaskStatus> statuses = queryCriteria.getStatuses();
    if (statuses != null && !statuses.isEmpty()) {
        hasStatus = true;
    }
    boolean hasTaskName = false;
    if (!StringUtils.isEmpty(queryCriteria.getTaskName())) {
        hasTaskName = true;
    }
    Query assignedToMeQuery = em.createQuery(SELECT_DISTINCT_TASKS + JOIN_HUMAN_ROLES_JOIN_ORG_ENTITIES + " oe.name = :name " + AND + HR_TYPE_ROLE_TYPE + AND + T_TENANT_ID_TENANT_ID + AND + T_TYPE_TASK_TYPE + (hasTaskName ? AND + FILTER_BY_TASKNAME : "") + AND + T_STATUS_IN_TASK_STATUSES + generateOrderedByQuery()).setMaxResults(queryCriteria.getPageSize()).setFirstResult(queryCriteria.getPageSize() * queryCriteria.getPageNumber());
    assignedToMeQuery.setParameter(TENANT_ID, queryCriteria.getCallerTenantId());
    assignedToMeQuery.setParameter("name", queryCriteria.getCaller());
    assignedToMeQuery.setParameter(TASK_TYPE, TaskType.TASK);
    assignedToMeQuery.setParameter(ROLE_TYPE, GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER);
    if (hasStatus) {
        assignedToMeQuery.setParameter(TASK_STATUSES, statuses);
    } else {
        List<TaskStatus> statusList = Arrays.asList(TaskStatus.RESERVED, TaskStatus.IN_PROGRESS, TaskStatus.SUSPENDED);
        assignedToMeQuery.setParameter(TASK_STATUSES, statusList);
    }
    if (hasTaskName) {
        assignedToMeQuery.setParameter(TASK_NAME, queryCriteria.getTaskName());
    }
    return assignedToMeQuery;
}
Also used : Query(javax.persistence.Query) TaskStatus(org.wso2.carbon.humantask.core.dao.TaskStatus)

Example 4 with TaskStatus

use of org.wso2.carbon.humantask.core.dao.TaskStatus in project carbon-business-process by wso2.

the class HumanTaskJPQLQueryBuilder method buildAdministrableTasksCountQuery.

private Query buildAdministrableTasksCountQuery() {
    boolean hasStatus = false;
    List<TaskStatus> statuses = queryCriteria.getStatuses();
    if (statuses != null && !statuses.isEmpty()) {
        hasStatus = true;
    }
    boolean hasTaskName = false;
    if (!StringUtils.isEmpty(queryCriteria.getTaskName())) {
        hasTaskName = true;
    }
    Query administrableTasksQuery = em.createQuery(SELECT_DISTINCT_TASKS_COUNT + JOIN_HUMAN_ROLES_JOIN_ORG_ENTITIES + OE_NAME_IN_NAMES + AND + HR_TYPE_ROLE_TYPE + (hasTaskName ? AND + FILTER_BY_TASKNAME : "") + AND + T_TYPE_TASK_TYPE + AND + T_TENANT_ID_TENANT_ID + (hasStatus ? AND + T_STATUS_IN_TASK_STATUSES : ""));
    List<String> rolesAndNamesList = getNameListForUser(queryCriteria.getCaller(), true);
    administrableTasksQuery.setParameter(NAMES, rolesAndNamesList);
    administrableTasksQuery.setParameter(TENANT_ID, queryCriteria.getCallerTenantId());
    administrableTasksQuery.setParameter(ROLE_TYPE, GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS);
    administrableTasksQuery.setParameter(TASK_TYPE, TaskType.TASK);
    if (hasStatus) {
        administrableTasksQuery.setParameter(TASK_STATUSES, statuses);
    }
    if (hasTaskName) {
        administrableTasksQuery.setParameter(TASK_NAME, queryCriteria.getTaskName());
    }
    return administrableTasksQuery;
}
Also used : Query(javax.persistence.Query) TaskStatus(org.wso2.carbon.humantask.core.dao.TaskStatus)

Example 5 with TaskStatus

use of org.wso2.carbon.humantask.core.dao.TaskStatus in project carbon-business-process by wso2.

the class HumanTaskJPQLQueryBuilder method buildAssignedToMeCountQuery.

// Creates the JPQL query to list tasks assigned for the particular user.
private Query buildAssignedToMeCountQuery() {
    boolean hasStatus = false;
    List<TaskStatus> statuses = queryCriteria.getStatuses();
    if (statuses != null && !statuses.isEmpty()) {
        hasStatus = true;
    }
    boolean hasTaskName = false;
    if (!StringUtils.isEmpty(queryCriteria.getTaskName())) {
        hasTaskName = true;
    }
    Query assignedToMeQuery = em.createQuery(SELECT_DISTINCT_TASKS_COUNT + JOIN_HUMAN_ROLES_JOIN_ORG_ENTITIES + " oe.name = :name " + AND + HR_TYPE_ROLE_TYPE + AND + T_TENANT_ID_TENANT_ID + AND + T_TYPE_TASK_TYPE + (hasTaskName ? AND + FILTER_BY_TASKNAME : "") + AND + T_STATUS_IN_TASK_STATUSES);
    assignedToMeQuery.setParameter(TENANT_ID, queryCriteria.getCallerTenantId());
    assignedToMeQuery.setParameter("name", queryCriteria.getCaller());
    assignedToMeQuery.setParameter(TASK_TYPE, TaskType.TASK);
    assignedToMeQuery.setParameter(ROLE_TYPE, GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER);
    if (hasStatus) {
        assignedToMeQuery.setParameter(TASK_STATUSES, statuses);
    } else {
        List<TaskStatus> statusList = Arrays.asList(TaskStatus.RESERVED, TaskStatus.IN_PROGRESS, TaskStatus.SUSPENDED);
        assignedToMeQuery.setParameter(TASK_STATUSES, statusList);
    }
    if (hasTaskName) {
        assignedToMeQuery.setParameter(TASK_NAME, queryCriteria.getTaskName());
    }
    return assignedToMeQuery;
}
Also used : Query(javax.persistence.Query) TaskStatus(org.wso2.carbon.humantask.core.dao.TaskStatus)

Aggregations

TaskStatus (org.wso2.carbon.humantask.core.dao.TaskStatus)14 Query (javax.persistence.Query)11 ArrayList (java.util.ArrayList)2 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)2 Calendar (java.util.Calendar)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 URI (org.apache.axis2.databinding.types.URI)1 IllegalArgumentFault (org.wso2.carbon.humantask.client.api.IllegalArgumentFault)1 IllegalStateFault (org.wso2.carbon.humantask.client.api.IllegalStateFault)1 TStatus (org.wso2.carbon.humantask.client.api.types.TStatus)1 TTaskSimpleQueryResultSet (org.wso2.carbon.humantask.client.api.types.TTaskSimpleQueryResultSet)1 HumanTaskDAOConnection (org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection)1 SimpleQueryCriteria (org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria)1 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)1