use of org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime in project carbon-business-process by wso2.
the class ExpressionBasedOrgEntityProvider method getOrganizationalEntities.
public List<OrganizationalEntityDAO> getOrganizationalEntities(PeopleQueryEvaluator peopleQueryEvaluator, TFrom tFrom, EvaluationContext evaluationContext) {
String expression = tFrom.newCursor().getTextValue().trim();
log.debug("Evaluating expression " + expression + " for ExpressionBasedOrgEntityProvider");
String expLang = (tFrom.getExpressionLanguage() == null) ? HumanTaskConstants.WSHT_EXP_LANG_XPATH20 : tFrom.getExpressionLanguage();
ExpressionLanguageRuntime expLangRuntime = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getExpressionLanguageRuntime(expLang);
List list = expLangRuntime.evaluate(expression, evaluationContext);
List<OrganizationalEntityDAO> orgEntityList = new ArrayList<OrganizationalEntityDAO>();
if (list.isEmpty() || list.size() > 1) {
log.debug(" Organizational Entities evaluated to null or multiple list");
return orgEntityList;
}
// Returned list should evaluate to an organizationalEntity or a user
for (Object item : list) {
if (item instanceof NodeList) {
for (int i = 0; i < ((NodeList) item).getLength(); i++) {
Node node = ((NodeList) item).item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getLocalName().equals(HumanTaskConstants.userQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.userQname.getNamespaceURI())) {
CommonTaskUtil.addOrgEntityForUserNode(node, peopleQueryEvaluator, orgEntityList);
} else if (node.getLocalName().equals(HumanTaskConstants.groupQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.groupQname.getNamespaceURI())) {
CommonTaskUtil.addOrgEntityForGroupNode(node, peopleQueryEvaluator, orgEntityList);
} else if (node.getLocalName().equals("wrapper")) {
// Expression evaluator wraps the string with wrapper element name
CommonTaskUtil.addOrgEntityForUserNode(node, peopleQueryEvaluator, orgEntityList);
} else if (node.getLocalName().equals(HumanTaskConstants.organizationalEntityQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.organizationalEntityQname.getNamespaceURI())) {
// This is an organizational Entity node, hence parse it as org entity
// Most probably this logic wont be required
CommonTaskUtil.addOrgEntitiesForOrganizationEntityNode(node, peopleQueryEvaluator, orgEntityList);
}
} else if (node.getNodeType() == Node.TEXT_NODE) {
String nodeValue = node.getNodeValue().trim();
if (nodeValue.length() > 0) {
OrganizationalEntityDAO userOrgEntityForName = peopleQueryEvaluator.createUserOrgEntityForName(nodeValue);
if (userOrgEntityForName != null) {
orgEntityList.add(userOrgEntityForName);
}
}
}
}
}
}
return orgEntityList;
}
Aggregations