Search in sources :

Example 1 with HumanTaskIllegalStateException

use of org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException 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 HumanTaskIllegalStateException

use of org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException in project carbon-business-process by wso2.

the class Activate method checkPreConditions.

/**
 * Checks the Pre-conditions before executing the task operation.
 */
@Override
protected void checkPreConditions() {
    checkForValidTask();
    TaskDAO task = getTask();
    if (task.getActivationTime() == null) {
        throw new HumanTaskRuntimeException(String.format("The task[id:%d] does not have a defined activation time.", task.getId()));
    }
    if (task.getActivationTime().before(new Date())) {
        throw new HumanTaskRuntimeException(String.format("The task[id:%d] activation time has already expired.", task.getId()));
    }
    if (CommonTaskUtil.getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS).size() < 1) {
        throw new HumanTaskIllegalStateException(String.format("The are no matching users for the " + "task's[id:%d] potential owners", task.getId()));
    }
}
Also used : TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) Date(java.util.Date)

Example 3 with HumanTaskIllegalStateException

use of org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException in project carbon-business-process by wso2.

the class Exit method checkState.

/**
 * Perform the state checks before executing the task operation.
 */
@Override
protected void checkState() {
    TaskDAO task = getTask();
    boolean isInFinalState = false;
    if (TaskStatus.EXITED.equals(task.getStatus()) || TaskStatus.ERROR.equals(task.getStatus()) || TaskStatus.FAILED.equals(task.getStatus()) || TaskStatus.OBSOLETE.equals(task.getStatus()) || TaskStatus.COMPLETED.equals(task.getStatus())) {
        isInFinalState = true;
    }
    if (isInFinalState) {
        String errMsg = String.format("User[%s] cannot perform [%s] operation on task[%d] as the task is in state[%s]. " + "[%s] operation can be performed only on tasks not in states[%s,%s,%s,%s,%s]", getOperationInvoker().getName(), Exit.class, task.getId(), task.getStatus(), Exit.class, TaskStatus.EXITED, TaskStatus.ERROR, TaskStatus.FAILED, TaskStatus.OBSOLETE, TaskStatus.COMPLETED);
        log.error(errMsg);
        throw new HumanTaskIllegalStateException(errMsg);
    }
}
Also used : TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)

Example 4 with HumanTaskIllegalStateException

use of org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException in project carbon-business-process by wso2.

the class Exit method checkPostConditions.

/**
 * Checks the post-conditions after executing the task operation.
 */
@Override
protected void checkPostConditions() {
    TaskDAO task = getTask();
    if (!TaskStatus.EXITED.equals(task.getStatus())) {
        String errMsg = String.format("The task[id:%d] did not exit successfully as " + "it's state is still in [%s]", task.getId(), task.getStatus());
        log.error(errMsg);
        throw new HumanTaskIllegalStateException(errMsg);
    }
}
Also used : TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)

Aggregations

TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)4 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)3 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)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 TaskStatus (org.wso2.carbon.humantask.core.dao.TaskStatus)1 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)1