Search in sources :

Example 11 with TaskConfiguration

use of org.wso2.carbon.humantask.core.store.TaskConfiguration 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 12 with TaskConfiguration

use of org.wso2.carbon.humantask.core.store.TaskConfiguration in project carbon-business-process by wso2.

the class CommonTaskUtil method getRendering.

/**
 * Returns rendering elements for given rendering type.
 *
 * @param task              : TaskDAO
 * @param taskConfiguration : HumanTask base configuration
 * @param renderingType     : QName of the rendering type.
 * @return
 */
public static String getRendering(TaskDAO task, HumanTaskBaseConfiguration taskConfiguration, QName renderingType) {
    String htdPrefix = taskConfiguration.getNamespaceContext().getPrefix(HumanTaskConstants.HTD_NAMESPACE) + ":";
    EvaluationContext evalCtx = new ExpressionEvaluationContext(task, taskConfiguration);
    if (renderingType != null) {
        String expressionLanguage = taskConfiguration.getExpressionLanguage();
        ExpressionLanguageRuntime expLangRuntime = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getExpressionLanguageRuntime(expressionLanguage);
        TRendering rendering = taskConfiguration.getRendering(renderingType);
        if (rendering != null) {
            // Replace Presentation params with values.
            // Do not trim, to avoid malformed html. Renderings elements can contains html elements.
            String processedString = replaceUsingPresentationParams(task.getPresentationParameters(), rendering.xmlText());
            // Evaluating xpaths with $ $ marks..
            try {
                if (processedString.contains("$htd")) {
                    String[] split = processedString.split("\\$");
                    if (split != null && split.length > 0) {
                        StringBuilder sm = new StringBuilder();
                        // Assume xpath replaced initially, to avoid adding $ to start of the xml.
                        // TODO : Improve this logic.
                        boolean xpathReplaced = true;
                        for (String s : split) {
                            if (s.startsWith(htdPrefix)) {
                                String value = expLangRuntime.evaluateAsString(s, evalCtx);
                                sm.append(value);
                                xpathReplaced = true;
                            } else {
                                if (xpathReplaced == true) {
                                    // xpath replaced.
                                    sm.append(s);
                                } else {
                                    // This is not a xpath. Adding $ and split content back.
                                    sm.append("$").append(s);
                                }
                                xpathReplaced = false;
                            }
                        }
                        processedString = sm.toString();
                    }
                }
            } catch (Exception ex) {
                log.error("Error while evaluating rendering xpath. Please review xpath and deploy " + task.getDefinitionName() + "task again.", ex);
            }
            return processedString;
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Rendering type " + renderingType + " Not found for task definition " + taskConfiguration.getName());
            }
        }
    }
    return "";
}
Also used : ExpressionEvaluationContext(org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext) ExpressionEvaluationContext(org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext) EvaluationContext(org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext) ExpressionLanguageRuntime(org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime) 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 13 with TaskConfiguration

use of org.wso2.carbon.humantask.core.store.TaskConfiguration in project carbon-business-process by wso2.

the class HumanTaskPackageManagementSkeleton method getTaskInfo.

public TaskInfoType getTaskInfo(QName taskId) throws PackageManagementException {
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    TaskInfoType taskInfo = null;
    HumanTaskBaseConfiguration taskConf = HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantId).getTaskConfiguration(taskId);
    if (taskConf != null) {
        taskInfo = new TaskInfoType();
        taskInfo.setTaskId(taskConf.getName());
        taskInfo.setPackageName(taskConf.getPackageName());
        if (TaskPackageStatus.ACTIVE.equals(taskConf.getPackageStatus())) {
            taskInfo.setStatus(TaskStatusType.ACTIVE);
        } else if (TaskPackageStatus.RETIRED.equals(taskConf.getPackageStatus())) {
            taskInfo.setStatus(TaskStatusType.INACTIVE);
        } else if (TaskPackageStatus.UNDEPLOYING.equals(taskConf.getPackageStatus())) {
            taskInfo.setStatus(TaskStatusType.UNDEPLOYING);
        }
        taskInfo.setDeploymentError(taskConf.getDeploymentError());
        taskInfo.setErroneous(taskConf.isErroneous());
        if (taskConf instanceof TaskConfiguration) {
            taskInfo.setTaskType(TaskType.TASK);
        } else if (taskConf instanceof NotificationConfiguration) {
            taskInfo.setTaskType(TaskType.NOTIFICATION);
        }
        taskInfo.setDefinitionInfo(fillTaskDefinitionInfo(taskConf));
    }
    return taskInfo;
}
Also used : NotificationConfiguration(org.wso2.carbon.humantask.core.store.NotificationConfiguration) TaskConfiguration(org.wso2.carbon.humantask.core.store.TaskConfiguration) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)

Example 14 with TaskConfiguration

use of org.wso2.carbon.humantask.core.store.TaskConfiguration 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 15 with TaskConfiguration

use of org.wso2.carbon.humantask.core.store.TaskConfiguration in project carbon-business-process by wso2.

the class HumanTaskStore method deploy.

private void deploy(HumanTaskBaseConfiguration taskConfig) throws HumanTaskDeploymentException {
    if (taskConfig != null) {
        /**
         * Creating AxisService for HI
         */
        if (log.isDebugEnabled()) {
            log.debug("Deploying task " + taskConfig.getName());
        }
        AxisService axisService;
        Definition wsdlDef = taskConfig.getWSDL();
        if (taskConfig instanceof TaskConfiguration) {
            // to get the task id as response
            wsdlDef.getPortType(taskConfig.getPortType()).getOperation(taskConfig.getOperation(), null, null).setStyle(OperationType.REQUEST_RESPONSE);
        } else {
            // ONE_WAY no feed back for NOTIFICATIONS
            wsdlDef.getPortType(taskConfig.getPortType()).getOperation(taskConfig.getOperation(), null, null).setStyle(OperationType.ONE_WAY);
        }
        WSDL11ToAxisServiceBuilder serviceBuilder = createAxisServiceBuilder(taskConfig, wsdlDef);
        try {
            axisService = createAxisService(serviceBuilder, taskConfig);
            ServiceConfigurationUtil.configureService(axisService, taskConfig.getEndpointConfiguration(taskConfig.getServiceName().getLocalPart(), taskConfig.getPortName()), getConfigContext());
            ArrayList<AxisService> serviceList = new ArrayList<AxisService>();
            serviceList.add(axisService);
            DeploymentEngine.addServiceGroup(createServiceGroupForService(axisService), serviceList, null, null, getTenantAxisConfig());
            if (log.isDebugEnabled()) {
                log.debug(" Published axis2 service " + axisService.getName() + " for task " + taskConfig.getName());
            }
        } catch (AxisFault axisFault) {
            String errMsg = "Error populating the service";
            log.error(errMsg);
            throw new HumanTaskDeploymentException(errMsg, axisFault);
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisService(org.apache.axis2.description.AxisService) Definition(javax.wsdl.Definition) ArrayList(java.util.ArrayList) WSDL11ToAxisServiceBuilder(org.apache.axis2.description.WSDL11ToAxisServiceBuilder) HumanTaskDeploymentException(org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException)

Aggregations

QName (javax.xml.namespace.QName)7 HumanTaskBaseConfiguration (org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)7 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)6 TaskConfiguration (org.wso2.carbon.humantask.core.store.TaskConfiguration)6 Element (org.w3c.dom.Element)4 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)4 ExpressionEvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext)3 EvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext)3 NotificationConfiguration (org.wso2.carbon.humantask.core.store.NotificationConfiguration)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 NodeList (org.w3c.dom.NodeList)2 OutputEventAdapterConfiguration (org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration)2 OutputEventAdapterException (org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException)2 TNotification (org.wso2.carbon.humantask.TNotification)2 TTask (org.wso2.carbon.humantask.TTask)2 HumanTaskDeploymentException (org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException)2 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)2 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)2 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)2