use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.
the class LiteralBasedOrgEntityProvider method addOrgEntitiesForOrganizationEntityNode.
public static void addOrgEntitiesForOrganizationEntityNode(Node orgEntityNode, PeopleQueryEvaluator pqe, List<OrganizationalEntityDAO> orgEntityList) {
// Org entity node should contain either a user elements or group elements
if (orgEntityNode.getNodeType() == Node.ELEMENT_NODE) {
NodeList userList = ((Element) orgEntityNode).getElementsByTagNameNS(HumanTaskConstants.userQname.getNamespaceURI(), HumanTaskConstants.userQname.getLocalPart());
for (int j = 0; j < userList.getLength(); j++) {
Node item = userList.item(j);
NodeList childNodes = item.getChildNodes();
if (childNodes.getLength() == 1) {
Node textNode = childNodes.item(0);
if (textNode != null && textNode.getNodeType() == Node.TEXT_NODE) {
String username = textNode.getNodeValue();
if (username != null) {
username = username.trim();
if (username.length() > 0) {
OrganizationalEntityDAO userOrgEntityForName = pqe.createUserOrgEntityForName(username);
orgEntityList.add(userOrgEntityForName);
}
}
}
}
}
NodeList groupList = ((Element) orgEntityNode).getElementsByTagNameNS(HumanTaskConstants.groupQname.getNamespaceURI(), HumanTaskConstants.groupQname.getLocalPart());
for (int j = 0; j < groupList.getLength(); j++) {
Node item = groupList.item(j);
NodeList childNodes = item.getChildNodes();
if (childNodes.getLength() == 1) {
Node textNode = childNodes.item(0);
if (textNode != null && textNode.getNodeType() == Node.TEXT_NODE) {
String groupName = textNode.getNodeValue();
if (groupName != null) {
groupName = groupName.trim();
if (groupName.length() > 0) {
OrganizationalEntityDAO groupOrgEntityForName = pqe.createGroupOrgEntityForRole(groupName);
orgEntityList.add(groupOrgEntityForName);
}
}
}
}
}
}
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.
the class XPathExpressionRuntime method evaluateAsPart.
/**
* Evaluate the expression returns an OMElement
*
* @param exp Expresion
* @param partName Name of the part
* @param evalCtx EvaluationContext
* @return Part as an Node
*/
@Override
public Node evaluateAsPart(String exp, String partName, EvaluationContext evalCtx) {
Document document = DOMUtils.newDocument();
Node node = document.createElement(partName);
List<Node> nodeList = evaluate(exp, evalCtx);
if (nodeList.size() == 0) {
String errMsg = "0 nodes selected for the expression: " + exp;
log.error(errMsg);
throw new HumanTaskRuntimeException(errMsg);
} else if (nodeList.size() > 1) {
String errMsg = "More than one nodes are selected for the expression: " + exp;
log.error(errMsg);
throw new HumanTaskRuntimeException(errMsg);
}
Node partNode = nodeList.get(0);
replaceElement((Element) node, (Element) partNode);
return node;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.
the class CommonTaskUtil method setTaskOverrideContextAttributes.
public static void setTaskOverrideContextAttributes(TaskDAO task, Map<String, Element> headerElements) {
// TODO fix this for remaining properties.
try {
if (headerElements != null) {
Element contextRequest = headerElements.get(HumanTaskConstants.HT_CONTEXT_REQUEST);
if (contextRequest != null) {
if (!TaskType.NOTIFICATION.equals(task.getType())) {
// Notification can't be skipped.
NodeList nodeList = contextRequest.getElementsByTagNameNS(HumanTaskConstants.HT_CONTEXT_NAMESPACE, HumanTaskConstants.HT_CONTEXT_IS_SKIPABLE);
if (nodeList != null && nodeList.getLength() > 0) {
Node isSkipable = nodeList.item(0);
task.setSkipable(Boolean.parseBoolean(isSkipable.getTextContent()));
}
}
NodeList nodeList = contextRequest.getElementsByTagNameNS(HumanTaskConstants.HT_CONTEXT_NAMESPACE, HumanTaskConstants.HT_CONTEXT_PRIORITY);
if (nodeList != null && nodeList.getLength() > 0) {
Node priority = nodeList.item(0);
task.setPriority(Integer.parseInt(priority.getTextContent()));
}
}
}
} catch (Exception e) {
log.error("Error while setting override attributes to task", e);
}
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.
the class JaxpFunctionResolver method generateFrequencyMap.
/**
* Generates a HashMap containing string items and it's frequency in a given NodeList
* logic : create a HashMap where key:textContent value:frequency of the textContent in the list
* @param list : NodeList
* @return : Map<String,Integer> map of string occurrence frequencies
*/
private Map<String, Integer> generateFrequencyMap(ArrayList list) throws HumanTaskRuntimeException {
Map<String, Integer> frequencyMap = new HashMap<String, Integer>();
for (int i = 0; i < list.size(); i++) {
try {
String item = ((Element) list.get(i)).getTextContent();
if (frequencyMap.containsKey(item)) {
int frequency = frequencyMap.get(item) + 1;
frequencyMap.put(item, frequency);
} else {
frequencyMap.put(item, 1);
}
} catch (DOMException e) {
throw new HumanTaskRuntimeException("Invalid arguments:" + list, e);
} catch (ClassCastException e) {
throw new HumanTaskRuntimeException("Invalid arguments:" + list, e);
}
}
return frequencyMap;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-mediation by wso2.
the class NHttpGetProcessor method populateGetRequestProcessors.
private void populateGetRequestProcessors() throws AxisFault {
try {
OMElement docEle = XMLUtils.toOM(ServerConfiguration.getInstance().getDocumentElement());
if (docEle != null) {
SimpleNamespaceContext nsCtx = new SimpleNamespaceContext();
nsCtx.addNamespace("wsas", ServerConstants.CARBON_SERVER_XML_NAMESPACE);
XPath xp = new AXIOMXPath("//wsas:HttpGetRequestProcessors/wsas:Processor");
xp.setNamespaceContext(nsCtx);
List nodeList = xp.selectNodes(docEle);
for (Object aNodeList : nodeList) {
OMElement processorEle = (OMElement) aNodeList;
OMElement itemEle = processorEle.getFirstChildWithName(ITEM_QN);
if (itemEle == null) {
throw new ServletException("Required element, 'Item' not found!");
}
OMElement classEle = processorEle.getFirstChildWithName(CLASS_QN);
org.wso2.carbon.core.transports.HttpGetRequestProcessor processor;
if (classEle == null) {
throw new ServletException("Required element, 'Class' not found!");
} else {
processor = (org.wso2.carbon.core.transports.HttpGetRequestProcessor) Class.forName(classEle.getText().trim()).newInstance();
}
getRequestProcessors.put(itemEle.getText().trim(), processor);
}
}
} catch (Exception e) {
handleException("Error populating GetRequestProcessors", e);
}
}
Aggregations