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);
}
}
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;
}
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()));
}
}
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;
}
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;
}
Aggregations