Search in sources :

Example 1 with ExpressionLanguageRuntime

use of org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime in project carbon-business-process by wso2.

the class CommonTaskUtil method calculateRole.

/**
 * Calculates the Role.
 *
 * @param evalCtx    : The evaluation context.
 * @param  roleExpression : the role expression
 * @param expressionLanguage : Expression language associated with the argument named "role"
 * @return : The task priority
 */
public static String calculateRole(EvaluationContext evalCtx, String roleExpression, String expressionLanguage) {
    ExpressionLanguageRuntime expLangRuntime = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getExpressionLanguageRuntime(expressionLanguage);
    String role = expLangRuntime.evaluateAsString(roleExpression, evalCtx);
    if (role == null) {
        log.warn(String.format("Role cannot be  null"));
    }
    return role;
}
Also used : ExpressionLanguageRuntime(org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)

Example 2 with ExpressionLanguageRuntime

use of org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime in project carbon-business-process by wso2.

the class XPathEvaluatorUtil method evaluatePresentationParamXPath.

public static void evaluatePresentationParamXPath(PresentationParameterDAO param, String expression, String expLang, EvaluationContext evalCtx) {
    ExpressionLanguageRuntime expLangRuntime = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getExpressionLanguageRuntime(expLang);
    PresentationParameterDAO.Type type = param.getType();
    if (type == PresentationParameterDAO.Type.XSD_BOOL) {
        Boolean result = expLangRuntime.evaluateAsBoolean(expression, evalCtx);
        param.setValue(result.toString());
    } else if (type == PresentationParameterDAO.Type.XSD_STRING) {
        String result = expLangRuntime.evaluateAsString(expression, evalCtx);
        param.setValue(result);
    } else if (type == PresentationParameterDAO.Type.XSD_INT) {
        Number result = expLangRuntime.evaluateAsNumber(expression, evalCtx);
        param.setValue(Integer.toString(result.intValue()));
    } else if (type == PresentationParameterDAO.Type.XSD_DECIMALE) {
        Number result = expLangRuntime.evaluateAsNumber(expression, evalCtx);
        param.setValue(BigDecimal.valueOf(result.doubleValue()).toString());
    } else if (type == PresentationParameterDAO.Type.XSD_DOUBLE) {
        Number result = expLangRuntime.evaluateAsNumber(expression, evalCtx);
        param.setValue(Double.toString(result.doubleValue()));
    }
}
Also used : PresentationParameterDAO(org.wso2.carbon.humantask.core.dao.PresentationParameterDAO) ExpressionLanguageRuntime(org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)

Example 3 with ExpressionLanguageRuntime

use of org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime in project carbon-business-process by wso2.

the class HumanTaskEngine method initExpressionLanguageRuntimes.

private void initExpressionLanguageRuntimes() {
    expressionLanguageRuntimeRegistry = new HashMap<String, ExpressionLanguageRuntime>();
    expressionLanguageRuntimeRegistry.put(XPathExpressionRuntime.ns, new XPathExpressionRuntime());
}
Also used : ExpressionLanguageRuntime(org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime) XPathExpressionRuntime(org.wso2.carbon.humantask.core.engine.runtime.xpath.XPathExpressionRuntime)

Example 4 with ExpressionLanguageRuntime

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

Example 5 with ExpressionLanguageRuntime

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

Aggregations

ExpressionLanguageRuntime (org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)6 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 OrganizationalEntityDAO (org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)1 PresentationParameterDAO (org.wso2.carbon.humantask.core.dao.PresentationParameterDAO)1 ExpressionEvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext)1 EvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext)1 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)1 XPathExpressionRuntime (org.wso2.carbon.humantask.core.engine.runtime.xpath.XPathExpressionRuntime)1 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)1 UserStoreException (org.wso2.carbon.user.core.UserStoreException)1