Search in sources :

Example 21 with NodeList

use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.

the class AnalyticsPublisherExtensionOperation method fillDataArray.

private void fillDataArray(Object[] dataArray, List<AnalyticsKey> payloadAnalyticsKeyList, int startIndex, ExtensionContext context, Element element) throws FaultException {
    for (int i = 0; i < payloadAnalyticsKeyList.size(); i++) {
        AnalyticsKey analyticsKey = payloadAnalyticsKeyList.get(i);
        if (analyticsKey.getExpression() != null) {
            String expression = evaluateXPathExpression(context, analyticsKey.getExpression(), element);
            convertDataType(dataArray, (i + startIndex), analyticsKey, expression);
        } else if (analyticsKey.getVariable() != null && analyticsKey.getPart() == null) {
            if (analyticsKey.getQuery() == null) {
                String variable = context.readVariable(analyticsKey.getVariable()).getTextContent();
                convertDataType(dataArray, (i + startIndex), analyticsKey, variable);
            /* simple types should be specified for here */
            } else {
                String errMsg = "This functionality is currently not supported";
                log.error(errMsg);
                handleException(errMsg);
            }
        } else if (analyticsKey.getVariable() != null && analyticsKey.getPart() != null) {
            NodeList childNodes = context.readVariable(analyticsKey.getVariable()).getChildNodes();
            String result = null;
            String part = analyticsKey.getPart();
            for (int j = 0; j < childNodes.getLength(); j++) {
                Node item = childNodes.item(j);
                if (item != null && item.getNodeType() == Node.ELEMENT_NODE && item.getLocalName().equals(part)) {
                    /* remove the payload part */
                    result = DOMUtils.domToString(DOMUtils.getFirstChildElement(item));
                }
            }
            convertDataType(dataArray, (i + startIndex), analyticsKey, result);
            dataArray[i + startIndex] = result;
        }
    }
}
Also used : AnalyticsKey(org.wso2.carbon.bpel.core.ode.integration.config.analytics.AnalyticsKey) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Example 22 with NodeList

use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.

the class PeopleActivity method extractStandardElementType.

/**
 * In a peopleActivity element there can be exist only one standard element. eg - Standard Elements are 1. task 2.
 * localTask 3. remoteTask 4. remoteNotification etc.
 * <p/>
 * This method verify there's only one standard element exist and return the type of that standard element
 *
 * @return
 */
private String extractStandardElementType(Element parentElement) throws FaultException {
    NodeList taskList = parentElement.getChildNodes();
    String elementType = null;
    int standardElementCounter = 0;
    for (int i = 0; i < taskList.getLength(); i++) {
        if (taskList.item(i).getNodeType() == Node.ELEMENT_NODE) {
            try {
                elementType = getTypeOfStandardElement(taskList.item(i));
                standardElementCounter++;
                if (standardElementCounter > 1) {
                    throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "There is exist more than one standard child elements in " + BPEL4PeopleConstants.PEOPLE_ACTIVITY);
                }
            } catch (FaultException e) {
            // Do nothing
            }
        }
    }
    if (elementType != null) {
        return elementType;
    } else {
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "There is no standard child elements defined in " + BPEL4PeopleConstants.PEOPLE_ACTIVITY);
    }
}
Also used : FaultException(org.apache.ode.bpel.common.FaultException) NodeList(org.w3c.dom.NodeList) WSDL11Endpoint(org.apache.ode.bpel.epr.WSDL11Endpoint) UnifiedEndpoint(org.wso2.carbon.unifiedendpoint.core.UnifiedEndpoint)

Example 23 with NodeList

use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.

the class HTRenderingApiImpl method getRenderingOutputElements.

/**
 * Function to retrieve output rendering elements
 *
 * @param taskIdentifier interested task identifier
 * @return set of output renderings wrapped within OutputType
 * @throws IllegalArgumentFault        error occured while retrieving renderings from task definition
 * @throws IOException                 If an error occurred while reading from the input source
 * @throws SAXException                If the xml content in the input source is invalid
 * @throws IllegalOperationFault
 * @throws IllegalAccessFault
 * @throws IllegalStateFault
 * @throws XPathExpressionException    If error occurred while xpath evaluation
 * @throws GetRenderingsFaultException If unable to find unique id for the wso2:output rendering element
 */
private OutputType getRenderingOutputElements(URI taskIdentifier) throws IllegalArgumentFault, IOException, SAXException, IllegalOperationFault, IllegalAccessFault, IllegalStateFault, XPathExpressionException, GetRenderingsFaultException {
    QName renderingType = new QName(htRenderingNS, "output", "wso2");
    String outputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
    // create output element
    OutputType renderingOutputs = null;
    // check availability of output renderings
    if (outputRenderings != null && outputRenderings.length() > 0) {
        // parse output renderings
        Element outputRenderingsElement = DOMUtils.stringToDOM(outputRenderings);
        // retrieve output rendering elements
        NodeList outputElementList = outputRenderingsElement.getElementsByTagNameNS(htRenderingNS, "element");
        if (outputElementList != null && outputElementList.getLength() > 0) {
            int outputElementNum = outputElementList.getLength();
            OutputElementType[] outputElements = new OutputElementType[outputElementNum];
            // TODO get task output message from the cache
            // (if not in the cache) retrieve saved output using HumanTaskClientAPI
            String savedOutputMsg = (String) taskOps.getOutput(taskIdentifier, null);
            // Element to hold parsed saved output message
            Element savedOutputElement = null;
            if (savedOutputMsg != null && savedOutputMsg.length() > 0) {
                savedOutputElement = DOMUtils.stringToDOM(savedOutputMsg);
            }
            for (int i = 0; i < outputElementNum; i++) {
                Element tempElement = (Element) outputElementList.item(i);
                if (tempElement.hasAttribute("id")) {
                    // Retrieve element data
                    String elementID = tempElement.getAttribute("id");
                    String label = tempElement.getElementsByTagNameNS(htRenderingNS, "label").item(0).getTextContent();
                    String xpath = tempElement.getElementsByTagNameNS(htRenderingNS, "xpath").item(0).getTextContent();
                    String defaultValue = tempElement.getElementsByTagNameNS(htRenderingNS, "default").item(0).getTextContent();
                    // set the readOnly attribute if Exists, default false
                    String readOnly = "false";
                    if (tempElement.hasAttribute("readOnly")) {
                        readOnly = tempElement.getAttribute("readOnly");
                    }
                    // set element data in the response message
                    outputElements[i] = new OutputElementType();
                    // set ID
                    outputElements[i].setId(elementID);
                    // set label
                    outputElements[i].setLabel(label);
                    // set xpath
                    outputElements[i].setXpath(xpath);
                    // set value
                    Element valueElement = (Element) tempElement.getElementsByTagNameNS(htRenderingNS, "value").item(0);
                    outputElements[i].setValue(createOutRenderElementValue(valueElement));
                    if (readOnly.equals("true")) {
                        outputElements[i].setReadOnly(true);
                    } else {
                        outputElements[i].setReadOnly(false);
                    }
                    if (savedOutputElement != null) {
                        // resolve default value
                        String savedOutMessageValue = evaluateXPath(xpath, savedOutputElement, outputRenderingsElement.getOwnerDocument());
                        if (savedOutMessageValue == null) {
                            outputElements[i].set_default(defaultValue);
                        } else {
                            outputElements[i].set_default(savedOutMessageValue);
                        }
                    } else {
                        // add default value specified in the HT rendering definition
                        outputElements[i].set_default(defaultValue);
                    }
                } else {
                    // no unique id for the element
                    log.error("Unable to find unique id for the wso2:output rendering element");
                    throw new GetRenderingsFaultException("Unable to find unique id for the wso2:output rendering element");
                }
            }
            renderingOutputs = new OutputType();
            renderingOutputs.setElement(outputElements);
        }
    }
    return renderingOutputs;
}
Also used : OutputElementType(org.wso2.carbon.humantask.rendering.api.OutputElementType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) GetRenderingsFaultException(org.wso2.carbon.humantask.rendering.api.GetRenderingsFaultException) OutputType(org.wso2.carbon.humantask.rendering.api.OutputType)

Example 24 with NodeList

use of org.wso2.ei.dashboard.core.rest.model.NodeList 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;
}
Also used : OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) ExpressionLanguageRuntime(org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)

Example 25 with NodeList

use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-business-process by wso2.

the class LiteralBasedOrgEntityProvider method addOrgEntityForUserNode.

public static void addOrgEntityForUserNode(Node userNode, PeopleQueryEvaluator pqe, List<OrganizationalEntityDAO> orgEntityList) {
    NodeList childNodes = userNode.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 userOrgEntityForUser = pqe.createUserOrgEntityForName(username);
                    orgEntityList.add(userOrgEntityForUser);
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)

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