Search in sources :

Example 6 with HumanTaskException

use of org.wso2.carbon.humantask.core.engine.HumanTaskException 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 7 with HumanTaskException

use of org.wso2.carbon.humantask.core.engine.HumanTaskException 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 8 with HumanTaskException

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

the class TransformerUtils method generateAttachmentDAOFromID.

/**
 * Generate an {@code AttachmentDAO} for a given attachment-id
 *
 * @param task task to be associated with the particular attachment
 * @param attachmentID id of the attachment, so this will be used to extract attachment information from the
 * attachment-mgt OSGi service
 *
 * @return reference to the created {@code AttachmentDAO}
 * @throws HumanTaskException If if was failed to retrieve data from the attachment-mgt OSGi service
 */
public static AttachmentDAO generateAttachmentDAOFromID(TaskDAO task, String attachmentID) throws HumanTaskException {
    try {
        org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment attachment = HumanTaskServerHolder.getInstance().getAttachmentService().getAttachmentService().getAttachmentInfo(attachmentID);
        AttachmentDAO dao = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createAttachment();
        // Constructing the attachment DAO from the DTO
        dao.setName(attachment.getName());
        dao.setContentType(attachment.getContentType());
        dao.setTask((Task) task);
        String attachmentURL = attachment.getUrl().toString();
        // Extracting the attachment uri
        String attachmentUniqueID = attachmentURL.substring(attachmentURL.lastIndexOf("/") + 1);
        dao.setValue(attachmentUniqueID);
        dao.setAttachedAt(attachment.getCreatedTime().getTime());
        OrganizationalEntityDAO orgEntityDAO = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createNewOrgEntityObject(attachment.getCreatedBy(), OrganizationalEntityDAO.OrganizationalEntityType.USER);
        dao.setAttachedBy((OrganizationalEntity) orgEntityDAO);
        // TODO : "AccessType is not supported by Attachment-Mgt DTOs. So using a dummy value: " + HumanTaskConstants.DEFAULT_ATTACHMENT_ACCESS_TYPE);
        dao.setAccessType(HumanTaskConstants.DEFAULT_ATTACHMENT_ACCESS_TYPE);
        return dao;
    } catch (AttachmentMgtException e) {
        String errorMsg = "Attachment Data retrieval operation failed for attachment id:" + attachmentID + ". " + "Reason:";
        log.error(e.getLocalizedMessage(), e);
        throw new HumanTaskException(errorMsg + e.getLocalizedMessage(), e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) org.wso2.carbon.humantask.client.api.types(org.wso2.carbon.humantask.client.api.types) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException)

Example 9 with HumanTaskException

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

the class HumanTaskDAOConnectionImpl method createTask.

public TaskDAO createTask(TaskCreationContext creationContext) throws HumanTaskException {
    HumanTaskBuilderImpl taskBuilder = new HumanTaskBuilderImpl();
    if (log.isDebugEnabled()) {
        log.debug("Creating task instance for task " + creationContext.getTaskConfiguration().getName());
    }
    MessageDAO inputMessage = createMessage(creationContext);
    inputMessage.setMessageType(MessageDAO.MessageType.INPUT);
    taskBuilder.addTaskCreationContext(creationContext).addInputMessage(inputMessage);
    TaskDAO task = taskBuilder.build();
    entityManager.persist(task);
    try {
        creationContext.injectExpressionEvaluationContext(task);
        JPATaskUtil.processGenericHumanRoles(task, creationContext.getTaskConfiguration(), creationContext.getPeopleQueryEvaluator(), creationContext.getEvalContext());
        JPATaskUtil.processPresentationElements(task, creationContext.getTaskConfiguration(), creationContext);
        if (task.getType().equals(TaskType.TASK)) {
            CommonTaskUtil.nominate(task, creationContext.getPeopleQueryEvaluator());
        } else if (task.getType().equals(TaskType.NOTIFICATION)) {
            task.setStatus(TaskStatus.READY);
            notificationScheduler = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getNotificationScheduler();
            notificationScheduler.checkForNotificationTasks(creationContext.getTaskConfiguration(), creationContext, task);
        }
        task.setPriority(CommonTaskUtil.calculateTaskPriority(creationContext.getTaskConfiguration(), creationContext.getEvalContext()));
        CommonTaskUtil.setTaskToMessage(task);
        if (TaskType.TASK.equals(task.getType())) {
            CommonTaskUtil.processDeadlines(task, (TaskConfiguration) creationContext.getTaskConfiguration(), creationContext.getEvalContext());
            CommonTaskUtil.scheduleDeadlines(task);
        }
        // Setting HumanTask context override attributes
        CommonTaskUtil.setTaskOverrideContextAttributes(task, creationContext.getMessageHeaderParts());
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getEventProcessor().processEvent(CommonTaskUtil.createNewTaskEvent(task));
    } catch (HumanTaskRuntimeException ex) {
        String errorMsg = "Error occurred after task creation for Task ID: " + task.getId() + ". Cause: " + ex.getMessage();
        log.error(errorMsg);
        task.setStatus(TaskStatus.ERROR);
        throw ex;
    }
    return task;
}
Also used : HumanTaskBuilderImpl(org.wso2.carbon.humantask.core.dao.jpa.openjpa.util.HumanTaskBuilderImpl) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 10 with HumanTaskException

use of org.wso2.carbon.humantask.core.engine.HumanTaskException 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)

Aggregations

HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)4 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)4 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)3 OrganizationalEntityProvider (org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.OrganizationalEntityProvider)2 HumanTaskBaseConfiguration (org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)2 TaskConfiguration (org.wso2.carbon.humantask.core.store.TaskConfiguration)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TransactionManager (javax.transaction.TransactionManager)1 QName (javax.xml.namespace.QName)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)1 TArgument (org.wso2.carbon.humantask.TArgument)1 org.wso2.carbon.humantask.client.api.types (org.wso2.carbon.humantask.client.api.types)1 InvalidJobsInDbException (org.wso2.carbon.humantask.core.api.scheduler.InvalidJobsInDbException)1 InvalidUpdateRequestException (org.wso2.carbon.humantask.core.api.scheduler.InvalidUpdateRequestException)1 HumanTaskDAOConnection (org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection)1 OrganizationalEntityDAO (org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)1 TaskCreationContext (org.wso2.carbon.humantask.core.dao.TaskCreationContext)1