Search in sources :

Example 1 with EvaluationContext

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

the class XPathExpressionRuntime method evaluate.

private Object evaluate(String exp, EvaluationContext evalCtx, QName type) {
    try {
        XPathFactory xpf = new XPathFactoryImpl();
        JaxpFunctionResolver funcResolve = new JaxpFunctionResolver(evalCtx);
        xpf.setXPathFunctionResolver(funcResolve);
        XPathEvaluator xpe = (XPathEvaluator) xpf.newXPath();
        xpe.setXPathFunctionResolver(funcResolve);
        xpe.setBackwardsCompatible(true);
        xpe.setNamespaceContext(evalCtx.getNameSpaceContextOfTask());
        XPathExpression xpathExpression = xpe.compile(exp);
        Node contextNode = evalCtx.getRootNode() == null ? DOMUtils.newDocument() : evalCtx.getRootNode();
        Object evalResult = xpathExpression.evaluate(contextNode, type);
        if (evalResult != null && log.isDebugEnabled()) {
            log.debug("Expression " + exp + " generate result " + evalResult + " - type=" + evalResult.getClass().getName());
            if (evalCtx.getRootNode() != null) {
                log.debug("Was using context node " + DOMUtils.domToString(evalCtx.getRootNode()));
            }
        }
        return evalResult;
    } catch (XPathFactoryConfigurationException e) {
        log.error("Exception occurred while creating XPathFactory.", e);
        throw new XPathProcessingException("Exception occurred while creating XPathFactory.", e);
    } catch (XPathExpressionException e) {
        String msg = "Error evaluating XPath expression: " + exp;
        log.error(msg, e);
        throw new XPathProcessingException(msg, e);
    } catch (ParserConfigurationException e) {
        String msg = "XML Parsing error.";
        log.error(msg, e);
        throw new XPathProcessingException(msg, e);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new XPathProcessingException(e.getMessage(), e);
    }
}
Also used : XPathFactoryImpl(net.sf.saxon.xpath.XPathFactoryImpl) XPathEvaluator(net.sf.saxon.xpath.XPathEvaluator) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with EvaluationContext

use of org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext 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 3 with EvaluationContext

use of org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext 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 4 with EvaluationContext

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

the class LiteralBasedOrgEntityProvider method getOrganizationalEntities.

public List<OrganizationalEntityDAO> getOrganizationalEntities(PeopleQueryEvaluator peopleQueryEvaluator, TFrom tFrom, EvaluationContext evaluationContext) {
    TLiteral literal = tFrom.getLiteral();
    List<OrganizationalEntityDAO> orgEntityList = new ArrayList<OrganizationalEntityDAO>();
    Element domNode = (Element) literal.getDomNode();
    if (domNode != null) {
        NodeList orgEntityNodes = domNode.getElementsByTagNameNS(HumanTaskConstants.organizationalEntityQname.getNamespaceURI(), HumanTaskConstants.organizationalEntityQname.getLocalPart());
        // There should be only one organizational Entity
        if (orgEntityNodes.getLength() == 1) {
            Node orgEntityNode = orgEntityNodes.item(0);
            addOrgEntitiesForOrganizationEntityNode(orgEntityNode, peopleQueryEvaluator, orgEntityList);
        } else {
            NodeList elements = domNode.getElementsByTagNameNS(HumanTaskConstants.userQname.getNamespaceURI(), HumanTaskConstants.userQname.getLocalPart());
            if (elements.getLength() == 1) {
                // There should only be one user element
                CommonTaskUtil.addOrgEntityForUserNode(elements.item(0), peopleQueryEvaluator, orgEntityList);
            }
        }
    }
    return orgEntityList;
}
Also used : TLiteral(org.wso2.carbon.humantask.TLiteral) OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Example 5 with EvaluationContext

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

the class LogicalPeopleGroupBasedOrgEntityProvider method getOrganizationalEntities.

public List<OrganizationalEntityDAO> getOrganizationalEntities(PeopleQueryEvaluator peopleQueryEvaluator, TFrom tFrom, EvaluationContext evaluationContext) throws HumanTaskException {
    String roleName = null;
    for (TArgument tArgument : tFrom.getArgumentArray()) {
        String expressionLanguage = (tArgument.getExpressionLanguage() == null) ? tFrom.getExpressionLanguage() : tArgument.getExpressionLanguage();
        if (expressionLanguage == null) {
            expressionLanguage = HumanTaskConstants.WSHT_EXP_LANG_XPATH20;
        }
        // TODO what about expression language
        if ("role".equals(tArgument.getName())) {
            roleName = tArgument.newCursor().getTextValue();
            if (roleName != null && roleName.contains("htd:getInput")) {
                roleName = CommonTaskUtil.calculateRole(evaluationContext, roleName, expressionLanguage);
            }
            break;
        }
    }
    if (roleName == null || StringUtils.isEmpty(roleName)) {
        throw new HumanTaskRuntimeException("The role name cannot be empty: " + tFrom.toString());
    } else {
        roleName = roleName.trim();
    }
    List<OrganizationalEntityDAO> orgEnties = new ArrayList<OrganizationalEntityDAO>();
    orgEnties.add(peopleQueryEvaluator.createGroupOrgEntityForRole(roleName));
    return orgEnties;
}
Also used : OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) ArrayList(java.util.ArrayList) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) TArgument(org.wso2.carbon.humantask.TArgument)

Aggregations

ExpressionLanguageRuntime (org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)5 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)5 ArrayList (java.util.ArrayList)3 Node (org.w3c.dom.Node)3 OrganizationalEntityDAO (org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)3 ExpressionEvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext)3 EvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext)3 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 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 QName (javax.xml.namespace.QName)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XPathEvaluator (net.sf.saxon.xpath.XPathEvaluator)1 XPathFactoryImpl (net.sf.saxon.xpath.XPathFactoryImpl)1 TArgument (org.wso2.carbon.humantask.TArgument)1 TLiteral (org.wso2.carbon.humantask.TLiteral)1 PresentationParameterDAO (org.wso2.carbon.humantask.core.dao.PresentationParameterDAO)1 Deadline (org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Deadline)1