Search in sources :

Example 6 with EvaluationContext

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

the class JPATaskUtil method assignHumanRoles.

private static void assignHumanRoles(TaskDAO task, PeopleQueryEvaluator peopleQueryEvaluator, TGenericHumanRoleAssignment roleAssignment, GenericHumanRole.GenericHumanRoleType type, EvaluationContext evaluationContext) throws HumanTaskException {
    OrganizationalEntityProvider provider = OrganizationalEntityProviderFactory.getOrganizationalEntityProvider(roleAssignment.getFrom());
    List<OrganizationalEntityDAO> orgEntities = provider.getOrganizationalEntities(peopleQueryEvaluator, roleAssignment.getFrom(), evaluationContext);
    GenericHumanRole humanRole = new GenericHumanRole();
    humanRole.setType(type);
    humanRole.setOrgEntities(orgEntities);
    humanRole.setTask(task);
    for (OrganizationalEntityDAO oe : orgEntities) {
        oe.addGenericHumanRole(humanRole);
    }
    task.addHumanRole(humanRole);
}
Also used : OrganizationalEntityProvider(org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.OrganizationalEntityProvider)

Example 7 with EvaluationContext

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

the class JPATaskUtil method processGenericHumanRoles.

public static void processGenericHumanRoles(TaskDAO task, HumanTaskBaseConfiguration taskConfiguration, PeopleQueryEvaluator peopleQueryEvaluator, EvaluationContext evaluationContext) throws HumanTaskException {
    if (taskConfiguration.isTask()) {
        // Task
        TTask tTask = ((TaskConfiguration) taskConfiguration).getTask();
        // TODO move the reading of configuration file in to the TaskConfiguration class
        // Reading Excluded users
        TGenericHumanRoleAssignment[] tExcludedOwners = tTask.getPeopleAssignments().getExcludedOwnersArray();
        if (tExcludedOwners != null && tExcludedOwners.length > 0) {
            assignHumanRoles(task, peopleQueryEvaluator, tExcludedOwners[0], GenericHumanRoleDAO.GenericHumanRoleType.EXCLUDED_OWNERS, evaluationContext);
        }
        // Reading potential owners
        TPotentialOwnerAssignment[] tPotentialOwners = tTask.getPeopleAssignments().getPotentialOwnersArray();
        if (tPotentialOwners != null && tPotentialOwners.length > 0) {
            TPotentialOwnerAssignment tPotentialOwner = tPotentialOwners[0];
            OrganizationalEntityProvider provider = OrganizationalEntityProviderFactory.getOrganizationalEntityProvider(tPotentialOwner.getFrom());
            List<OrganizationalEntityDAO> orgEntities = provider.getOrganizationalEntities(peopleQueryEvaluator, tPotentialOwner.getFrom(), evaluationContext);
            if (tExcludedOwners != null && tExcludedOwners.length > 0) {
                GenericHumanRoleDAO excludedOwners = task.getGenericHumanRole(GenericHumanRoleDAO.GenericHumanRoleType.EXCLUDED_OWNERS);
                for (OrganizationalEntityDAO excludedEntity : excludedOwners.getOrgEntities()) {
                    for (OrganizationalEntityDAO ownerEntity : orgEntities) {
                        if (excludedEntity.getOrgEntityType() == ownerEntity.getOrgEntityType() && excludedEntity.getName().equals(ownerEntity.getName())) {
                            orgEntities.remove(ownerEntity);
                            break;
                        }
                    }
                }
            }
            GenericHumanRole potentialOwnersGHRole = new GenericHumanRole();
            potentialOwnersGHRole.setType(GenericHumanRole.GenericHumanRoleType.POTENTIAL_OWNERS);
            potentialOwnersGHRole.setOrgEntities(orgEntities);
            potentialOwnersGHRole.setTask(task);
            for (OrganizationalEntityDAO oe : orgEntities) {
                oe.addGenericHumanRole(potentialOwnersGHRole);
            }
            task.addHumanRole(potentialOwnersGHRole);
        }
        // Reading Stake holders
        TGenericHumanRoleAssignment[] tStakeHolders = tTask.getPeopleAssignments().getTaskStakeholdersArray();
        if (tStakeHolders != null && tStakeHolders.length > 0) {
            assignHumanRoles(task, peopleQueryEvaluator, tStakeHolders[0], GenericHumanRoleDAO.GenericHumanRoleType.STAKEHOLDERS, evaluationContext);
        }
        // Reading Business administrators
        TGenericHumanRoleAssignment[] tBusinessAdministrators = tTask.getPeopleAssignments().getBusinessAdministratorsArray();
        if (tBusinessAdministrators != null && tBusinessAdministrators.length > 0) {
            assignHumanRoles(task, peopleQueryEvaluator, tBusinessAdministrators[0], GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS, evaluationContext);
        }
    } else {
        // Notification
        TNotification tNotification = ((NotificationConfiguration) taskConfiguration).getNotificationDefinition();
        // Reading Notification recipients
        TGenericHumanRoleAssignment[] tRecipients = tNotification.getPeopleAssignments().getRecipientsArray();
        if (tRecipients != null && tRecipients.length > 0) {
            assignHumanRoles(task, peopleQueryEvaluator, tRecipients[0], GenericHumanRoleDAO.GenericHumanRoleType.NOTIFICATION_RECIPIENTS, evaluationContext);
        }
    }
}
Also used : OrganizationalEntityProvider(org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.OrganizationalEntityProvider) NotificationConfiguration(org.wso2.carbon.humantask.core.store.NotificationConfiguration) TaskConfiguration(org.wso2.carbon.humantask.core.store.TaskConfiguration)

Example 8 with EvaluationContext

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

the class XPathExpressionRuntime method evaluateAsPart.

/**
 * Evaluate the expression returns an OMElement
 *
 * @param exp      Expresion
 * @param partName Name of the part
 * @param evalCtx  EvaluationContext
 * @return Part as an Node
 */
@Override
public Node evaluateAsPart(String exp, String partName, EvaluationContext evalCtx) {
    Document document = DOMUtils.newDocument();
    Node node = document.createElement(partName);
    List<Node> nodeList = evaluate(exp, evalCtx);
    if (nodeList.size() == 0) {
        String errMsg = "0 nodes selected for the expression: " + exp;
        log.error(errMsg);
        throw new HumanTaskRuntimeException(errMsg);
    } else if (nodeList.size() > 1) {
        String errMsg = "More than one nodes are selected for the expression: " + exp;
        log.error(errMsg);
        throw new HumanTaskRuntimeException(errMsg);
    }
    Node partNode = nodeList.get(0);
    replaceElement((Element) node, (Element) partNode);
    return node;
}
Also used : HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 9 with EvaluationContext

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

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

the class CommonTaskUtil method calculateTaskPriority.

/**
 * Calculates the task priority.
 *
 * @param taskConfig : The task's configuration
 * @param evalCtx    : The evaluation context.
 * @return : The task priority
 */
public static int calculateTaskPriority(HumanTaskBaseConfiguration taskConfig, EvaluationContext evalCtx) {
    TPriorityExpr priorityDef = taskConfig.getPriorityExpression();
    int taskPriorityInt = HumanTaskConstants.DEFAULT_TASK_PRIORITY;
    if (priorityDef != null) {
        String expLang = priorityDef.getExpressionLanguage() == null ? taskConfig.getExpressionLanguage() : priorityDef.getExpressionLanguage();
        ExpressionLanguageRuntime expLangRuntime = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getExpressionLanguageRuntime(expLang);
        Number priority = expLangRuntime.evaluateAsNumber(priorityDef.newCursor().getTextValue().trim(), evalCtx);
        if (priority.intValue() > 10 || priority.intValue() < 0) {
            log.warn(String.format("Ignoring the task priority value :[%d] The task priority has to be with 0 and 10. Setting to default:[%d].", priority.intValue(), HumanTaskConstants.DEFAULT_TASK_PRIORITY));
        } else {
            taskPriorityInt = priority.intValue();
        }
    }
    return taskPriorityInt;
}
Also used : ExpressionLanguageRuntime(org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)

Aggregations

ExpressionLanguageRuntime (org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)5 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)5 ArrayList (java.util.ArrayList)3 Node (org.w3c.dom.Node)3 OrganizationalEntityDAO (org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)3 ExpressionEvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext)3 EvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext)3 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 OrganizationalEntityProvider (org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.OrganizationalEntityProvider)2 TaskConfiguration (org.wso2.carbon.humantask.core.store.TaskConfiguration)2 List (java.util.List)1 QName (javax.xml.namespace.QName)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XPathEvaluator (net.sf.saxon.xpath.XPathEvaluator)1 XPathFactoryImpl (net.sf.saxon.xpath.XPathFactoryImpl)1 TArgument (org.wso2.carbon.humantask.TArgument)1 TLiteral (org.wso2.carbon.humantask.TLiteral)1 PresentationParameterDAO (org.wso2.carbon.humantask.core.dao.PresentationParameterDAO)1 Deadline (org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Deadline)1