Search in sources :

Example 31 with IllegalAccessFault

use of org.wso2.carbon.humantask.client.api.IllegalAccessFault 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)

Aggregations

HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)23 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)23 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)23 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)23 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)23 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)23 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)23 UserStoreException (org.wso2.carbon.user.core.UserStoreException)23 Element (org.w3c.dom.Element)8 HumanTaskCommand (org.wso2.carbon.humantask.core.engine.HumanTaskCommand)5 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)4 HumanTaskDAOConnection (org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection)3 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)3 QName (javax.xml.namespace.QName)2 URI (org.apache.axis2.databinding.types.URI)2 NodeList (org.w3c.dom.NodeList)2 IllegalAccessFault (org.wso2.carbon.humantask.client.api.IllegalAccessFault)2 Complete (org.wso2.carbon.humantask.core.engine.commands.Complete)2 Start (org.wso2.carbon.humantask.core.engine.commands.Start)2 Callable (java.util.concurrent.Callable)1