Search in sources :

Example 11 with OrganizationalEntityDAO

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

the class JobProcessorImpl method executeDeadline.

private void executeDeadline(long taskId, String name) throws HumanTaskException {
    // TODO what if two deadlines fired at the same time???
    // TODO do the needful for deadlines. i.e create notifications and re-assign
    log.info("ON DEADLINE: " + " : now: " + new Date());
    TaskDAO task = HumanTaskServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection().getTask(taskId);
    // Setting the tenant id and tenant domain
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(task.getTenantId());
    String tenantDomain = null;
    try {
        tenantDomain = HumanTaskServiceComponent.getRealmService().getTenantManager().getDomain(task.getTenantId());
    } catch (UserStoreException e) {
        log.error(" Cannot find the tenant domain " + e.toString());
    }
    if (tenantDomain == null) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    }
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
    TaskConfiguration taskConf = (TaskConfiguration) HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(task.getTenantId()).getTaskConfiguration(QName.valueOf(task.getName()));
    TDeadline deadline = taskConf.getDeadline(name);
    EvaluationContext evalCtx = new ExpressionEvaluationContext(task, taskConf);
    List<TEscalation> validEscalations = new ArrayList<TEscalation>();
    boolean reassingnmentAdded = false;
    for (TEscalation escalation : deadline.getEscalationArray()) {
        if (!escalation.isSetCondition()) {
            // We only need the first Re-assignment and we ignore all other re-assignments
            if (escalation.isSetReassignment() && !reassingnmentAdded) {
                reassingnmentAdded = true;
            } else if (escalation.isSetReassignment()) {
                continue;
            }
            validEscalations.add(escalation);
            continue;
        }
        if (evaluateCondition(escalation.getCondition().newCursor().getTextValue(), escalation.getCondition().getExpressionLanguage() == null ? taskConf.getExpressionLanguage() : escalation.getCondition().getExpressionLanguage(), evalCtx)) {
            if (escalation.isSetReassignment() && !reassingnmentAdded) {
                reassingnmentAdded = true;
            } else if (escalation.isSetReassignment()) {
                continue;
            }
            validEscalations.add(escalation);
        }
    }
    // We may do this in the above for loop as well
    for (TEscalation escalation : validEscalations) {
        if (log.isDebugEnabled()) {
            log.debug("Escalation: " + escalation.getName());
        }
        if (escalation.isSetLocalNotification() || escalation.isSetNotification()) {
            QName qName;
            if (escalation.isSetLocalNotification()) {
                qName = escalation.getLocalNotification().getReference();
            } else {
                qName = new QName(taskConf.getName().getNamespaceURI(), escalation.getNotification().getName());
            }
            HumanTaskBaseConfiguration notificationConfiguration = HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(task.getTenantId()).getActiveTaskConfiguration(qName);
            if (notificationConfiguration == null) {
                log.error("Fatal Error, notification definition not found for name " + qName.toString());
                return;
            }
            TaskCreationContext taskContext = new TaskCreationContext();
            taskContext.setTaskConfiguration(notificationConfiguration);
            taskContext.setTenantId(task.getTenantId());
            taskContext.setPeopleQueryEvaluator(HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getPeopleQueryEvaluator());
            Map<String, Element> tempBodyParts = new HashMap<String, Element>();
            Map<String, Element> tempHeaderParts = new HashMap<String, Element>();
            QName tempName = null;
            TToParts toParts = escalation.getToParts();
            if (toParts == null) {
                // get the input message of the task
                MessageDAO msg = task.getInputMessage();
                tempName = msg.getName();
                for (Map.Entry<String, Element> partEntry : msg.getBodyParts().entrySet()) {
                    tempBodyParts.put(partEntry.getKey(), partEntry.getValue());
                }
                for (Map.Entry<String, Element> partEntry : msg.getHeaderParts().entrySet()) {
                    tempHeaderParts.put(partEntry.getKey(), partEntry.getValue());
                }
                taskContext.setMessageBodyParts(tempBodyParts);
                taskContext.setMessageHeaderParts(tempHeaderParts);
                taskContext.setMessageName(tempName);
            } else {
                for (TToPart toPart : toParts.getToPartArray()) {
                    if (!notificationConfiguration.isValidPart(toPart.getName())) {
                        // This validation should be done at the deployment time
                        String errMsg = "The part: " + toPart.getName() + " is not available" + " in the corresponding WSDL message";
                        log.error(errMsg);
                        throw new RuntimeException(errMsg);
                    }
                    String expLang = toPart.getExpressionLanguage() == null ? taskConf.getExpressionLanguage() : toPart.getExpressionLanguage();
                    Node nodePart = HumanTaskServerHolder.getInstance().getHtServer().getTaskEngine().getExpressionLanguageRuntime(expLang).evaluateAsPart(toPart.newCursor().getTextValue(), toPart.getName(), evalCtx);
                    tempBodyParts.put(toPart.getName(), (Element) nodePart);
                }
            }
            taskContext.setMessageBodyParts(tempBodyParts);
            taskContext.setMessageHeaderParts(tempHeaderParts);
            taskContext.setMessageName(tempName);
            HumanTaskServerHolder.getInstance().getHtServer().getTaskEngine().getDaoConnectionFactory().getConnection().createTask(taskContext);
        } else {
            // if re-assignment
            if (escalation.getReassignment().getPotentialOwners().isSetFrom()) {
                escalation.getReassignment().getPotentialOwners().getFrom().getArgumentArray();
                String roleName = null;
                for (TArgument argument : escalation.getReassignment().getPotentialOwners().getFrom().getArgumentArray()) {
                    if ("role".equals(argument.getName())) {
                        roleName = argument.newCursor().getTextValue().trim();
                    }
                }
                if (roleName == null) {
                    String errMsg = "Value for argument name 'role' is expected.";
                    log.error(errMsg);
                    throw new Scheduler.JobProcessorException(errMsg);
                }
                if (!isExistingRole(roleName, task.getTenantId())) {
                    log.warn("Role name " + roleName + " does not exist for tenant id" + task.getTenantId());
                }
                List<OrganizationalEntityDAO> orgEntities = new ArrayList<OrganizationalEntityDAO>();
                OrganizationalEntityDAO orgEntity = HumanTaskServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection().createNewOrgEntityObject(roleName, OrganizationalEntityDAO.OrganizationalEntityType.GROUP);
                orgEntities.add(orgEntity);
                task.replaceOrgEntitiesForLogicalPeopleGroup(GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS, orgEntities);
            } else {
                String errMsg = "From element is expected inside the assignment";
                log.error(errMsg);
                throw new Scheduler.JobProcessorException(errMsg);
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) TaskConfiguration(org.wso2.carbon.humantask.core.store.TaskConfiguration) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) ExpressionEvaluationContext(org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext) QName(javax.xml.namespace.QName) ExpressionEvaluationContext(org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext) EvaluationContext(org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext)

Example 12 with OrganizationalEntityDAO

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

the class OperationAuthorizationUtil method isExcludedEntity.

private static boolean isExcludedEntity(TaskDAO task, OrganizationalEntityDAO validatee, PeopleQueryEvaluator pqe) {
    GenericHumanRoleDAO excludedOwners = task.getGenericHumanRole(GenericHumanRoleDAO.GenericHumanRoleType.EXCLUDED_OWNERS);
    if (excludedOwners != null) {
        for (OrganizationalEntityDAO entityForRole : getGroupOrganizationalEntities(excludedOwners)) {
            if (OrganizationalEntityDAO.OrganizationalEntityType.GROUP.equals(entityForRole.getOrgEntityType())) {
                String roleName = entityForRole.getName();
                List<String> userListForRole = pqe.getUserNameListForRole(roleName);
                if (userListForRole.contains(validatee.getName())) {
                    log.error("User " + validatee.getName() + " is in EXCLUDED_OWNERS role");
                    return true;
                }
            }
        }
        List<OrganizationalEntityDAO> orgEntities = getUserOrganizationalEntities(excludedOwners);
        Collections.sort(orgEntities, PeopleQueryComparators.peopleNameComparator());
        if (Collections.binarySearch(orgEntities, validatee, PeopleQueryComparators.peopleNameComparator()) >= 0) {
            log.error("User " + validatee.getName() + " is in EXCLUDED_OWNERS role");
            return true;
        }
    }
    return false;
}
Also used : OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) GenericHumanRoleDAO(org.wso2.carbon.humantask.core.dao.GenericHumanRoleDAO)

Example 13 with OrganizationalEntityDAO

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

the class OperationAuthorizationUtil method authoriseUser.

/**
 * @param task             : The task against which the user being validated.
 * @param validatee        : The OrganizationalEntityDAO being validated.
 * @param allowedRoleTypes : The allowed role types for the validatee object.
 * @param pqe              : PeopleQueryEvaluator for people queries.
 * @return : true if the user is in the specified roles for the given task. false otherwise.
 */
public static boolean authoriseUser(TaskDAO task, OrganizationalEntityDAO validatee, List<GenericHumanRoleDAO.GenericHumanRoleType> allowedRoleTypes, PeopleQueryEvaluator pqe) {
    List<GenericHumanRoleDAO> humanRolesInTask = task.getHumanRoles();
    if (isExcludedEntity(task, validatee, pqe)) {
        return false;
    }
    for (GenericHumanRoleDAO role : humanRolesInTask) {
        if (allowedRoleTypes.contains(role.getType())) {
            // check for groups
            for (OrganizationalEntityDAO entityForRole : getGroupOrganizationalEntities(role)) {
                if (OrganizationalEntityDAO.OrganizationalEntityType.GROUP.equals(entityForRole.getOrgEntityType())) {
                    String roleName = entityForRole.getName();
                    List<String> userListForRole = pqe.getUserNameListForRole(roleName);
                    if (userListForRole.contains(validatee.getName())) {
                        return true;
                    }
                }
            }
            // check for users
            // TODO validate user existance in the user store.
            List<OrganizationalEntityDAO> orgEntities = getUserOrganizationalEntities(role);
            Collections.sort(orgEntities, PeopleQueryComparators.peopleNameComparator());
            if (Collections.binarySearch(orgEntities, validatee, PeopleQueryComparators.peopleNameComparator()) >= 0) {
                return true;
            }
        }
    }
    return false;
}
Also used : OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) GenericHumanRoleDAO(org.wso2.carbon.humantask.core.dao.GenericHumanRoleDAO)

Example 14 with OrganizationalEntityDAO

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

the class TaskOperationsImpl method nominate.

/**
 * Nominate an organization entity to process the task. (An Administrative Operation)
 * @param taskIdURI : task identifier
 * @param nomineeOrgEntity : TOrganizationalEntity
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void nominate(final URI taskIdURI, final TOrganizationalEntity nomineeOrgEntity) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                List<OrganizationalEntityDAO> nominees = TransformerUtils.transformOrganizationalEntityList(nomineeOrgEntity);
                Nominate nominateCommand = new Nominate(getCaller(), taskId, nominees);
                nominateCommand.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : Nominate(org.wso2.carbon.humantask.core.engine.commands.Nominate) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 15 with OrganizationalEntityDAO

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

the class TaskOperationsImpl method delegate.

/**
 * Assign the task to one user and set the task to state Reserved.
 * @param taskId : task identifier
 * @param delegatee : organizational entity (htt:tOrganizationalEntity)
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws RecipientNotAllowedException
 * @throws IllegalAccessFault
 */
public void delegate(final URI taskId, final TOrganizationalEntity delegatee) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, RecipientNotAllowedException, IllegalAccessFault {
    try {
        validateTaskId(taskId);
        if (delegatee == null) {
            throw new IllegalArgumentFault("The delegatee cannot be null!");
        }
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                List<OrganizationalEntityDAO> orgEntities = TransformerUtils.transformOrganizationalEntityList(delegatee);
                if (orgEntities.size() > 1) {
                    throw new IllegalArgumentFault("There can be only 1 delegatee of type user!");
                }
                Delegate delegateCommand = new Delegate(getCaller(), new Long(taskId.toString()), orgEntities.get(0));
                delegateCommand.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : Delegate(org.wso2.carbon.humantask.core.engine.commands.Delegate) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Aggregations

OrganizationalEntityDAO (org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)10 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)10 ArrayList (java.util.ArrayList)7 Node (org.w3c.dom.Node)5 GenericHumanRoleDAO (org.wso2.carbon.humantask.core.dao.GenericHumanRoleDAO)5 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)5 Element (org.w3c.dom.Element)4 NodeList (org.w3c.dom.NodeList)4 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)4 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)4 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)4 UserStoreException (org.wso2.carbon.user.core.UserStoreException)4 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)3 PeopleQueryEvaluator (org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)3 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)3 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)3 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 Callable (java.util.concurrent.Callable)1