Search in sources :

Example 26 with NodeList

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)

Example 27 with NodeList

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;
}
Also used : HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 28 with NodeList

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);
    }
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) 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)

Example 29 with NodeList

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;
}
Also used : HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 30 with NodeList

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);
    }
}
Also used : XPath(org.jaxen.XPath) AXIOMXPath(org.apache.axiom.om.xpath.AXIOMXPath) ServletException(javax.servlet.ServletException) HttpGetRequestProcessor(org.wso2.carbon.core.transports.HttpGetRequestProcessor) OMElement(org.apache.axiom.om.OMElement) List(java.util.List) SimpleNamespaceContext(org.jaxen.SimpleNamespaceContext) AXIOMXPath(org.apache.axiom.om.xpath.AXIOMXPath) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

NodeList (org.w3c.dom.NodeList)20 Element (org.w3c.dom.Element)12 Node (org.w3c.dom.Node)11 NodeList (org.wso2.ei.dashboard.core.rest.model.NodeList)10 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 List (java.util.List)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)5 JsonObject (com.google.gson.JsonObject)4 QName (javax.xml.namespace.QName)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)4 Document (org.w3c.dom.Document)4 NodeListInner (org.wso2.ei.dashboard.core.rest.model.NodeListInner)4 SAXException (org.xml.sax.SAXException)4 JsonElement (com.google.gson.JsonElement)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3