Search in sources :

Example 16 with PeopleQueryEvaluator

use of org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator in project carbon-business-process by wso2.

the class LiteralBasedOrgEntityProvider method addOrgEntitiesForOrganizationEntityNode.

public static void addOrgEntitiesForOrganizationEntityNode(Node orgEntityNode, PeopleQueryEvaluator pqe, List<OrganizationalEntityDAO> orgEntityList) {
    // Org entity node should contain either a user elements or group elements
    if (orgEntityNode.getNodeType() == Node.ELEMENT_NODE) {
        NodeList userList = ((Element) orgEntityNode).getElementsByTagNameNS(HumanTaskConstants.userQname.getNamespaceURI(), HumanTaskConstants.userQname.getLocalPart());
        for (int j = 0; j < userList.getLength(); j++) {
            Node item = userList.item(j);
            NodeList childNodes = item.getChildNodes();
            if (childNodes.getLength() == 1) {
                Node textNode = childNodes.item(0);
                if (textNode != null && textNode.getNodeType() == Node.TEXT_NODE) {
                    String username = textNode.getNodeValue();
                    if (username != null) {
                        username = username.trim();
                        if (username.length() > 0) {
                            OrganizationalEntityDAO userOrgEntityForName = pqe.createUserOrgEntityForName(username);
                            orgEntityList.add(userOrgEntityForName);
                        }
                    }
                }
            }
        }
        NodeList groupList = ((Element) orgEntityNode).getElementsByTagNameNS(HumanTaskConstants.groupQname.getNamespaceURI(), HumanTaskConstants.groupQname.getLocalPart());
        for (int j = 0; j < groupList.getLength(); j++) {
            Node item = groupList.item(j);
            NodeList childNodes = item.getChildNodes();
            if (childNodes.getLength() == 1) {
                Node textNode = childNodes.item(0);
                if (textNode != null && textNode.getNodeType() == Node.TEXT_NODE) {
                    String groupName = textNode.getNodeValue();
                    if (groupName != null) {
                        groupName = groupName.trim();
                        if (groupName.length() > 0) {
                            OrganizationalEntityDAO groupOrgEntityForName = pqe.createGroupOrgEntityForRole(groupName);
                            orgEntityList.add(groupOrgEntityForName);
                        }
                    }
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)

Example 17 with PeopleQueryEvaluator

use of org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator in project carbon-business-process by wso2.

the class HumanTaskJPQLQueryBuilder method getNameListForUser.

private List<String> getNameListForUser(String userName, boolean includeUserName) {
    List<String> roleNameList = new ArrayList<String>();
    if (includeUserName) {
        roleNameList.add(userName);
    }
    PeopleQueryEvaluator peopleQueryEvaluator = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getPeopleQueryEvaluator();
    roleNameList.addAll(peopleQueryEvaluator.getRoleNameListForUser(userName));
    return roleNameList;
}
Also used : ArrayList(java.util.ArrayList) PeopleQueryEvaluator(org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)

Example 18 with PeopleQueryEvaluator

use of org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator in project carbon-business-process by wso2.

the class HumanTaskEngine method createTask.

// create task logic.
private TaskDAO createTask(WSDLAwareMessage message, HumanTaskBaseConfiguration taskConfiguration, int tenantId) throws HumanTaskException {
    TaskCreationContext creationContext = new TaskCreationContext();
    creationContext.setTaskConfiguration(taskConfiguration);
    creationContext.setTenantId(tenantId);
    creationContext.setMessageBodyParts(message.getBodyPartElements());
    creationContext.setMessageHeaderParts(message.getHeaderPartElements());
    creationContext.setPeopleQueryEvaluator(peopleQueryEvaluator);
    TaskDAO task = getDaoConnectionFactory().getConnection().createTask(creationContext);
    creationContext.injectExpressionEvaluationContext(task);
    return task;
}
Also used : TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) TaskCreationContext(org.wso2.carbon.humantask.core.dao.TaskCreationContext)

Example 19 with PeopleQueryEvaluator

use of org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator in project carbon-business-process by wso2.

the class Nominate method checkPreConditions.

/**
 * Checks the Pre-conditions before executing the task operation.
 */
@Override
protected void checkPreConditions() {
    PeopleQueryEvaluator pqe = getEngine().getPeopleQueryEvaluator();
    pqe.checkOrgEntitiesExist(nominees);
    // Check for Excluded Owners.
    GenericHumanRoleDAO excludedOwnerRoles = getTask().getGenericHumanRole(GenericHumanRoleDAO.GenericHumanRoleType.EXCLUDED_OWNERS);
    if (excludedOwnerRoles != null) {
        List<OrganizationalEntityDAO> excludedOrgEntities = excludedOwnerRoles.getOrgEntities();
        // Case 1 : Matching Excluded OrgEntity List.
        for (OrganizationalEntityDAO nominee : nominees) {
            for (OrganizationalEntityDAO excludedOrgEntity : excludedOrgEntities) {
                if (nominee.getOrgEntityType() == excludedOrgEntity.getOrgEntityType() && nominee.getName().equals(excludedOrgEntity.getName())) {
                    String errMsg = String.format("The task nomination failed. One nominee is in the excluded Owner List for task " + getTask().getId() + ".");
                    log.error(errMsg);
                    throw new HumanTaskIllegalArgumentException(errMsg);
                }
            }
        }
        // Case 2: Checking OrgEntity Users in Excluded OrgEntity Groups.
        for (OrganizationalEntityDAO nominee : nominees) {
            if (nominee.getOrgEntityType() == OrganizationalEntityDAO.OrganizationalEntityType.USER) {
                List<String> roleNameListForUser = getEngine().getPeopleQueryEvaluator().getRoleNameListForUser(nominee.getName());
                for (OrganizationalEntityDAO excludedOrgEntity : excludedOrgEntities) {
                    if (excludedOrgEntity.getOrgEntityType() == OrganizationalEntityDAO.OrganizationalEntityType.GROUP && roleNameListForUser.contains(excludedOrgEntity.getName())) {
                        String errMsg = String.format("The task nomination failed. One nominee is in an excluded Owner Group for task " + getTask().getId() + ".");
                        log.error(errMsg);
                        throw new HumanTaskIllegalArgumentException(errMsg);
                    }
                }
            }
        }
    }
}
Also used : HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) PeopleQueryEvaluator(org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)

Aggregations

PeopleQueryEvaluator (org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)9 OrganizationalEntityDAO (org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)8 ArrayList (java.util.ArrayList)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)4 GenericHumanRoleDAO (org.wso2.carbon.humantask.core.dao.GenericHumanRoleDAO)3 Element (org.w3c.dom.Element)2 OrganizationalEntityProvider (org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.OrganizationalEntityProvider)2 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)2 List (java.util.List)1 TArgument (org.wso2.carbon.humantask.TArgument)1 TLiteral (org.wso2.carbon.humantask.TLiteral)1 TaskCreationContext (org.wso2.carbon.humantask.core.dao.TaskCreationContext)1 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)1 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)1 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)1 HumanTaskServerException (org.wso2.carbon.humantask.core.engine.HumanTaskServerException)1 ExpressionLanguageRuntime (org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)1 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)1