Search in sources :

Example 26 with TaskDAO

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

the class GetInput method execute.

@Override
public void execute() {
    authorise();
    TaskDAO task = getTask();
    checkPreConditions();
    checkState();
    if (StringUtils.isNotEmpty(partName)) {
        inputElement = CommonTaskUtil.getMessagePart(task.getInputMessage(), partName);
    } else {
        inputElement = (Element) task.getInputMessage().getBodyData().getFirstChild().getFirstChild();
    }
    checkPostConditions();
}
Also used : TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO)

Example 27 with TaskDAO

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

the class CommonTaskUtil method setTaskOverrideContextAttributes.

public static void setTaskOverrideContextAttributes(TaskDAO task, Map<String, Element> headerElements) {
    // TODO fix this for remaining properties.
    try {
        if (headerElements != null) {
            Element contextRequest = headerElements.get(HumanTaskConstants.HT_CONTEXT_REQUEST);
            if (contextRequest != null) {
                if (!TaskType.NOTIFICATION.equals(task.getType())) {
                    // Notification can't be skipped.
                    NodeList nodeList = contextRequest.getElementsByTagNameNS(HumanTaskConstants.HT_CONTEXT_NAMESPACE, HumanTaskConstants.HT_CONTEXT_IS_SKIPABLE);
                    if (nodeList != null && nodeList.getLength() > 0) {
                        Node isSkipable = nodeList.item(0);
                        task.setSkipable(Boolean.parseBoolean(isSkipable.getTextContent()));
                    }
                }
                NodeList nodeList = contextRequest.getElementsByTagNameNS(HumanTaskConstants.HT_CONTEXT_NAMESPACE, HumanTaskConstants.HT_CONTEXT_PRIORITY);
                if (nodeList != null && nodeList.getLength() > 0) {
                    Node priority = nodeList.item(0);
                    task.setPriority(Integer.parseInt(priority.getTextContent()));
                }
            }
        }
    } catch (Exception e) {
        log.error("Error while setting override attributes to task", e);
    }
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 28 with TaskDAO

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

the class CommonTaskUtil method processDeadlines.

/**
 * Process the deadlines for the given task.
 *
 * @param task : The task object.
 * @param taskConf : The task configuration for this task.
 * @param evalContext : The task's eval context.
 */
public static void processDeadlines(TaskDAO task, TaskConfiguration taskConf, EvaluationContext evalContext) {
    // TODO is it possible to process deadlines once per a task definition and set the duration per a task instance?
    TDeadlines deadlines = taskConf.getDeadlines();
    if (deadlines != null) {
        TDeadline[] startDeadlines = deadlines.getStartDeadlineArray();
        TDeadline[] completionDeadlines = deadlines.getCompletionDeadlineArray();
        for (TDeadline deadline : startDeadlines) {
            DeadlineDAO startDeadline = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createDeadline();
            startDeadline.setStatus(TaskStatus.IN_PROGRESS);
            startDeadline.setName((deadline.getName() == null ? "startDeadline" : deadline.getName()));
            startDeadline.setTask(task);
            startDeadline.setDeadlineDate(calculateDeadline(task, deadline, taskConf, evalContext).getTime());
            task.addDeadline(startDeadline);
        }
        for (TDeadline deadline : completionDeadlines) {
            Deadline completionDeadline = new Deadline();
            completionDeadline.setStatus(TaskStatus.COMPLETED);
            completionDeadline.setName((deadline.getName() == null ? "completionDeadline" : deadline.getName()));
            completionDeadline.setTask(task);
            completionDeadline.setDeadlineDate(calculateDeadline(task, deadline, taskConf, evalContext).getTime());
            task.addDeadline(completionDeadline);
        }
    }
}
Also used : Deadline(org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Deadline)

Example 29 with TaskDAO

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

the class CommonTaskUtil method getAssignableUserNameList.

/**
 * Returns the list of assignable user name list.
 *
 * @param task               : The task object.
 * @param excludeActualOwner : Whether to exclude the actual owner from the returned list.
 * @return : the list of assignable user name list.
 */
public static List<String> getAssignableUserNameList(TaskDAO task, boolean excludeActualOwner) {
    List<String> allPotentialOwners = new ArrayList<String>();
    GenericHumanRoleDAO ghr = task.getGenericHumanRole(GenericHumanRole.GenericHumanRoleType.POTENTIAL_OWNERS);
    RegistryService registryService = HumanTaskServiceComponent.getRegistryService();
    for (OrganizationalEntityDAO orgEntity : ghr.getOrgEntities()) {
        if (OrganizationalEntityDAO.OrganizationalEntityType.GROUP.equals(orgEntity.getOrgEntityType())) {
            String roleName = orgEntity.getName();
            UserRealm userRealm;
            try {
                userRealm = registryService.getUserRealm(task.getTenantId());
                String[] assignableUsersArray = userRealm.getUserStoreManager().getUserListOfRole(roleName);
                allPotentialOwners.addAll(Arrays.asList(assignableUsersArray));
            } catch (RegistryException e) {
                throw new HumanTaskRuntimeException("Cannot locate user realm for tenant id " + task.getTenantId());
            } catch (UserStoreException e) {
                throw new HumanTaskRuntimeException("Error retrieving the UserStoreManager " + task.getTenantId(), e);
            }
        } else if (OrganizationalEntityDAO.OrganizationalEntityType.USER.equals(orgEntity.getOrgEntityType())) {
            allPotentialOwners.add(orgEntity.getName());
        }
    }
    OrganizationalEntityDAO actualOwner = getActualOwner(task);
    if (excludeActualOwner && actualOwner != null) {
        allPotentialOwners.remove(actualOwner.getName());
    }
    return allPotentialOwners;
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) UserStoreException(org.wso2.carbon.user.core.UserStoreException) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 30 with TaskDAO

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

the class CommonTaskUtil method hasPotentialOwners.

/**
 * Checks whether the given TaskDAO has potential owners.
 *
 * @param task : The task to be checked for potential owners.
 * @return : true if the task has potential owners.
 */
public static boolean hasPotentialOwners(TaskDAO task) {
    PeopleQueryEvaluator pqe = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getPeopleQueryEvaluator();
    boolean hasPotentialOwners = false;
    for (GenericHumanRoleDAO humanRoleDAO : task.getHumanRoles()) {
        if (GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS.equals(humanRoleDAO.getType()) && humanRoleDAO.getOrgEntities() != null && humanRoleDAO.getOrgEntities().size() > 0) {
            try {
                pqe.checkOrgEntitiesExist(humanRoleDAO.getOrgEntities());
                hasPotentialOwners = true;
            } catch (HumanTaskRuntimeException ex) {
                hasPotentialOwners = false;
            }
        }
    }
    return hasPotentialOwners;
}
Also used : PeopleQueryEvaluator(org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Aggregations

TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)27 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)16 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)7 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)7 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)7 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)7 UserStoreException (org.wso2.carbon.user.core.UserStoreException)7 Element (org.w3c.dom.Element)6 HumanTaskDAOConnection (org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection)6 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)6 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)6 QName (javax.xml.namespace.QName)5 HumanTaskBaseConfiguration (org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)5 TaskConfiguration (org.wso2.carbon.humantask.core.store.TaskConfiguration)5 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)4 URI (org.apache.axis2.databinding.types.URI)3 NodeList (org.w3c.dom.NodeList)3 PeopleQueryEvaluator (org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)3 ExpressionEvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext)3 EvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext)3