Search in sources :

Example 11 with HumanTaskBaseConfiguration

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

the class HTRenderingApiImpl method setTaskOutput.

public SetTaskOutputResponse setTaskOutput(URI taskIdentifier, SetOutputValuesType values) throws SetTaskOutputFaultException {
    // Retrieve task information
    TaskDAO htTaskDAO;
    try {
        htTaskDAO = getTaskDAO(taskIdentifier);
    } catch (Exception e) {
        log.error("Error occurred while retrieving task data", e);
        throw new SetTaskOutputFaultException(e);
    }
    QName taskName = QName.valueOf(htTaskDAO.getName());
    // Check hash map for output message template
    Element outputMsgTemplate = outputTemplates.get(taskName);
    if (outputMsgTemplate == null) {
        try {
            // generate output message template
            int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
            HumanTaskBaseConfiguration htConf = HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantID).getTaskConfiguration(taskName);
            TaskConfiguration taskConf = (TaskConfiguration) htConf;
            // retrieve response binding
            Service callbackService = (Service) taskConf.getResponseWSDL().getServices().get(taskConf.getCallbackServiceName());
            Port callbackPort = (Port) callbackService.getPorts().get(taskConf.getCallbackPortName());
            String callbackBinding = callbackPort.getBinding().getQName().getLocalPart();
            outputMsgTemplate = createSoapTemplate(taskConf.getResponseWSDL().getDocumentBaseURI(), taskConf.getResponsePortType().getLocalPart(), taskConf.getResponseOperation(), callbackBinding);
        } catch (Exception e) {
            log.error("Error occurred while output message template generation", e);
            throw new SetTaskOutputFaultException("Unable to generate output message", e);
        }
        // add to the template HashMap
        if (outputMsgTemplate != null) {
            outputTemplates.put(taskName, outputMsgTemplate);
        } else {
            log.error("Unable to create output message template");
            throw new SetTaskOutputFaultException("Unable to generate output message");
        }
    }
    // update template with new values
    try {
        // TODO improve this section with caching
        QName renderingType = new QName(htRenderingNS, "output", "wso2");
        String outputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
        SetOutputvalueType[] valueSet = values.getValue();
        if (outputRenderings != null && valueSet.length > 0) {
            Element outputRenderingsElement = DOMUtils.stringToDOM(outputRenderings);
            // update elements in the template to create output xml
            for (int i = 0; i < valueSet.length; i++) {
                Element outElement = getOutputElementById(valueSet[i].getId(), outputRenderingsElement);
                if (outElement != null) {
                    outputMsgTemplate = updateXmlByXpath(outputMsgTemplate, outElement.getElementsByTagNameNS(htRenderingNS, "xpath").item(0).getTextContent(), valueSet[i].getString(), outputRenderingsElement.getOwnerDocument());
                }
            }
        } else {
            log.error("Retrieving output renderings failed");
            throw new SetTaskOutputFaultException("Retrieving output renderings failed");
        }
        // TODO what is this NCName?
        taskOps.setOutput(taskIdentifier, new NCName("message"), DOMUtils.domToString(outputMsgTemplate));
    } catch (IllegalArgumentFault illegalArgumentFault) {
        // Error occurred while retrieving HT renderings and set output message
        throw new SetTaskOutputFaultException(illegalArgumentFault);
    } catch (SAXException e) {
        log.error("Error occured while parsing output renderings", e);
        throw new SetTaskOutputFaultException("Response message generation failed");
    } catch (XPathExpressionException e) {
        // Error occured while updating elements in the template to create output xml
        log.error("XPath evaluation failed", e);
        throw new SetTaskOutputFaultException("Internal Error Occurred");
    } catch (Exception e) {
        // Error occurred while updating template with new values
        log.error("Error occurred while updating template with new values", e);
        throw new SetTaskOutputFaultException("Internal Error Occurred");
    }
    SetTaskOutputResponse response = new SetTaskOutputResponse();
    response.setSuccess(true);
    return response;
}
Also used : QName(javax.xml.namespace.QName) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Element(org.w3c.dom.Element) Port(javax.wsdl.Port) SetTaskOutputResponse(org.wso2.carbon.humantask.rendering.api.SetTaskOutputResponse) TaskConfiguration(org.wso2.carbon.humantask.core.store.TaskConfiguration) Service(javax.wsdl.Service) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SetTaskOutputFaultException(org.wso2.carbon.humantask.rendering.api.SetTaskOutputFaultException) GetRenderingsFaultException(org.wso2.carbon.humantask.rendering.api.GetRenderingsFaultException) SAXException(org.xml.sax.SAXException) CompleteTaskFaultException(org.wso2.carbon.humantask.rendering.api.CompleteTaskFaultException) IOException(java.io.IOException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) NCName(org.apache.axis2.databinding.types.NCName) SAXException(org.xml.sax.SAXException) SetOutputvalueType(org.wso2.carbon.humantask.rendering.api.SetOutputvalueType) TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) IllegalArgumentFault(org.wso2.carbon.humantask.client.api.IllegalArgumentFault) SetTaskOutputFaultException(org.wso2.carbon.humantask.rendering.api.SetTaskOutputFaultException)

Example 12 with HumanTaskBaseConfiguration

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

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

the class HumanTaskStore method removeMatchingPackageAfterTaskObsoletion.

private boolean removeMatchingPackageAfterTaskObsoletion(String packageName) {
    final HumanTaskEngine taskEngine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
    boolean matchingPackagesFound = false;
    final int tId = this.tenantId;
    List<HumanTaskBaseConfiguration> matchingTaskConfigurations = new ArrayList<HumanTaskBaseConfiguration>();
    for (final HumanTaskBaseConfiguration configuration : this.getTaskConfigurations()) {
        if (configuration.getPackageName().equals(packageName)) {
            matchingTaskConfigurations.add(configuration);
            try {
                taskEngine.getScheduler().execTransaction(new Callable<Object>() {

                    public Object call() throws Exception {
                        taskEngine.getDaoConnectionFactory().getConnection().obsoleteTasks(configuration.getName().toString(), tId);
                        return null;
                    }
                });
            } catch (Exception e) {
                String errMsg = "Error occurred while making tasks obsolete";
                log.error(errMsg);
                throw new HumanTaskRuntimeException(errMsg, e);
            }
            // we don't want the associated service once the task configuration is removed!
            removeAxisServiceForTaskConfiguration(configuration);
            matchingPackagesFound = true;
        }
    }
    // remove the task configurations with the matching package name.
    for (HumanTaskBaseConfiguration removableConfiguration : matchingTaskConfigurations) {
        this.getTaskConfigurations().remove(removableConfiguration);
    }
    return matchingPackagesFound;
}
Also used : HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) ArrayList(java.util.ArrayList) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskDeploymentException(org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 14 with HumanTaskBaseConfiguration

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

the class HumanTaskStore method validateServiceCreationForTaskConfig.

/**
 * When wsdl errors are there in the package, we use a dummy service creation step to validate all required parts
 * are available in the wsdl
 * @param taskConfig Task configuration object for this task package
 * @throws HumanTaskDeploymentException HumanTaskDeployment Exception is thrown when an error happens
 */
private void validateServiceCreationForTaskConfig(HumanTaskBaseConfiguration taskConfig) throws HumanTaskDeploymentException {
    try {
        WSDL11ToAxisServiceBuilder serviceBuilder = createAxisServiceBuilder(taskConfig, taskConfig.getWSDL());
        serviceBuilder.populateService();
    } catch (AxisFault e) {
        String errorMsg = "Error validating wsdl " + e.getMessage();
        throw new HumanTaskDeploymentException(errorMsg, e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) WSDL11ToAxisServiceBuilder(org.apache.axis2.description.WSDL11ToAxisServiceBuilder) HumanTaskDeploymentException(org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException)

Example 15 with HumanTaskBaseConfiguration

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

HumanTaskBaseConfiguration (org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)10 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)7 QName (javax.xml.namespace.QName)6 TaskConfiguration (org.wso2.carbon.humantask.core.store.TaskConfiguration)5 Element (org.w3c.dom.Element)4 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)4 HumanTaskDeploymentException (org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException)4 ArrayList (java.util.ArrayList)3 AxisFault (org.apache.axis2.AxisFault)3 AxisService (org.apache.axis2.description.AxisService)3 WSDL11ToAxisServiceBuilder (org.apache.axis2.description.WSDL11ToAxisServiceBuilder)3 NotificationConfiguration (org.wso2.carbon.humantask.core.store.NotificationConfiguration)3 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)3 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 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)2 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)2 ExpressionEvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext)2