Search in sources :

Example 66 with Element

use of org.wso2.siddhi.query.api.annotation.Element in project carbon-business-process by wso2.

the class HTQueryBuildHelperImpl method getTaskDataById.

/**
 * @param taskId
 * @return all the task details for the given taskID
 * @throws IllegalAccessFault
 * @throws IllegalArgumentFault
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws URI.MalformedURIException
 */
public String[] getTaskDataById(String taskId) throws IllegalAccessFault, IllegalArgumentFault, IllegalStateFault, IllegalOperationFault, URI.MalformedURIException {
    String[] output = { "" };
    List<String> outputList = new ArrayList<>();
    TaskDAO task;
    URI uri = new URI(taskId);
    try {
        final Long validatedTaskId = validateTaskId(uri);
        task = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<TaskDAO>() {

            public TaskDAO call() throws Exception {
                HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
                HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
                TaskDAO task = daoConn.getTask(validatedTaskId);
                return task;
            }
        });
    } catch (Exception ex) {
        throw new IllegalAccessFault(ex);
    }
    GenericHumanRoleDAO.GenericHumanRoleType[] genericHumanRoleTypes = GenericHumanRoleDAO.GenericHumanRoleType.values();
    MessageDAO inputMessageDAO = task.getInputMessage();
    MessageDAO outputMessageDAO = task.getOutputMessage();
    String description = task.getTaskDescription("text/plain");
    String titleString = String.format("%1$-" + 25 + "s", "Task Name") + ":" + task.getName();
    outputList.add(titleString);
    for (int i = 0; i < genericHumanRoleTypes.length; i++) {
        List<OrganizationalEntityDAO> organizationalEntityDAOs = CommonTaskUtil.getOrgEntitiesForRole(task, genericHumanRoleTypes[i]);
        if (organizationalEntityDAOs.size() > 0) {
            String taskDataString = String.format("%1$-" + 25 + "s", genericHumanRoleTypes[i]) + ":";
            for (int j = 0; j < organizationalEntityDAOs.size(); j++) {
                taskDataString = taskDataString + organizationalEntityDAOs.get(j).getName() + " [" + organizationalEntityDAOs.get(j).getOrgEntityType() + "]  ";
            }
            outputList.add(taskDataString);
        }
    }
    if (description != null) {
        String taskDescriptionString = String.format("%1$-" + 25 + "s", "Task Description") + ":" + task.getTaskDescription("text/plain");
        outputList.add(taskDescriptionString);
    }
    Element inputBodyData = inputMessageDAO.getBodyData();
    if (inputBodyData != null) {
        String inputMsgStr = String.format("%1$-" + 25 + "s", "Task Input") + ":" + "\n" + DOMUtils.domToString(inputBodyData);
        outputList.add(inputMsgStr);
    }
    if (outputMessageDAO != null) {
        Element outputBodyData = outputMessageDAO.getBodyData();
        if (outputBodyData != null) {
            String outputMessageStr = String.format("%1$-" + 25 + "s", "Task Output") + ":" + "\n" + DOMUtils.domToString(outputBodyData);
            outputList.add(outputMessageStr);
        }
    }
    output = new String[outputList.size()];
    int i = 0;
    for (Object o : outputList) {
        output[i++] = o.toString();
    }
    return output;
}
Also used : IllegalAccessFault(org.wso2.carbon.humantask.client.api.IllegalAccessFault) HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) Element(org.w3c.dom.Element) URI(org.apache.axis2.databinding.types.URI) Callable(java.util.concurrent.Callable)

Example 67 with Element

use of org.wso2.siddhi.query.api.annotation.Element in project carbon-business-process by wso2.

the class TaskOperationsImpl method complete.

/**
 * Execution of the task finished successfully.
 * @param taskIdURI : task identifier
 * @param outputStr : task outcome (String)
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void complete(final URI taskIdURI, final String outputStr) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                Element output = DOMUtils.stringToDOM(outputStr);
                Complete completeCommand = new Complete(getCaller(), taskId, output);
                completeCommand.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : Complete(org.wso2.carbon.humantask.core.engine.commands.Complete) Element(org.w3c.dom.Element) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 68 with Element

use of org.wso2.siddhi.query.api.annotation.Element in project carbon-business-process by wso2.

the class TaskOperationsImpl method setOutput.

/**
 * Set the data for the part of the task's output message.
 *
 * @param taskIdURI : task identifier
 * @param ncName    : PartName
 * @param o
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void setOutput(URI taskIdURI, NCName ncName, Object o) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        if (ncName != null && o != null) {
            final String outputName = ncName.toString();
            final Element outputData = DOMUtils.stringToDOM((String) o);
            HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

                public Object call() throws Exception {
                    SetOutput setOutputCommand = new SetOutput(getCaller(), taskId, outputName, outputData);
                    setOutputCommand.execute();
                    return null;
                }
            });
        } else {
            log.error("The output data for setOutput operation cannot be empty");
            throw new IllegalArgumentFault("The output data cannot be empty!");
        }
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : Element(org.w3c.dom.Element) SetOutput(org.wso2.carbon.humantask.core.engine.commands.SetOutput) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 69 with Element

use of org.wso2.siddhi.query.api.annotation.Element in project carbon-business-process by wso2.

the class XMLDocument method set.

/**
 * Function to set/replace/update an object (String / Element) to matching the xPath provided. (In case new element
 * is added, this api will clone it and merge the new node to the target location pointed by xPath and return the new cloned node)
 *
 * @param xPathStr xPath to the location object need to set
 * @param obj      String or Node
 * @return returns the node get updated when the set object is String, or returns newly added Node in case object is Element
 * @throws XPathExpressionException If expression cannot be evaluated
 * @throws BPMNXmlException         is thrown due to : Provided XPath and object does not match, provided object is not a Node or String
 *                                  result is NodeList, not a Text node or Element
 */
public Node set(String xPathStr, Object obj) throws XPathExpressionException, BPMNXmlException {
    NodeList evalResult = (NodeList) Utils.evaluateXPath(this.doc, xPathStr, XPathConstants.NODESET);
    if (evalResult.getLength() == 1) {
        Node targetNode = evalResult.item(0);
        if (obj instanceof String && targetNode instanceof Text) {
            // if string is provided, assume that user
            // need to replace the node value
            targetNode.setNodeValue((String) obj);
            // return updated Text Node
            return targetNode;
        } else if ((obj instanceof Integer || obj instanceof Byte || obj instanceof Character || obj instanceof Short || obj instanceof Long || obj instanceof Float || obj instanceof Double || obj instanceof Boolean) && targetNode instanceof Text) {
            // need to replace the node value
            targetNode.setNodeValue(obj.toString());
            // return updated Text Node
            return targetNode;
        } else if (obj instanceof Element && targetNode instanceof Element && targetNode.getParentNode() != null) {
            // if the user provides Node object,
            // assume that need to replace the target node
            Node targetParent = targetNode.getParentNode();
            Node nextSibling = targetNode.getNextSibling();
            // remove the target node
            targetParent.removeChild(targetNode);
            // add new node
            Node newNode = doc.importNode((Node) obj, true);
            if (nextSibling != null) {
                // If next sibling exists we have to put the new node before it
                targetParent.insertBefore(newNode, nextSibling);
            } else {
                targetParent.appendChild(newNode);
            }
            // return new node
            return newNode;
        } else {
            // provided XPath and object to set does not match
            throw new BPMNXmlException("Provided XPath and provided object does not match");
        }
    } else if (evalResult.getLength() > 0) {
        throw new BPMNXmlException("Error in provided xPath. Evaluation result is NodeList, not a Text node or Element");
    } else {
        throw new BPMNXmlException("Error in provided xPath. Evaluation result is not a Text node or Element");
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) BPMNXmlException(org.wso2.carbon.bpmn.core.types.datatypes.xml.BPMNXmlException)

Example 70 with Element

use of org.wso2.siddhi.query.api.annotation.Element in project carbon-business-process by wso2.

the class ProcessManagementServiceSkeleton method fillPartnerLinks.

// private java.lang.String[] getServiceLocationForProcess(QName processId)
// throws ProcessManagementException {
// AxisConfiguration axisConf = getConfigContext().getAxisConfiguration();
// Map<String, AxisService> services = axisConf.getServices();
// ArrayList<String> serviceEPRs = new ArrayList<String>();
// 
// for (AxisService service : services.values()) {
// Parameter pIdParam = service.getParameter(BPELConstants.PROCESS_ID);
// if (pIdParam != null) {
// if (pIdParam.getValue().equals(processId)) {
// serviceEPRs.addAll(Arrays.asList(service.getEPRs()));
// }
// }
// }
// 
// if (serviceEPRs.size() > 0) {
// return serviceEPRs.toArray(new String[serviceEPRs.size()]);
// }
// 
// String errMsg = "Cannot find service for process: " + processId;
// log.error(errMsg);
// throw new ProcessManagementException(errMsg);
// }
private void fillPartnerLinks(ProcessInfoType pInfo, TDeployment.Process processInfo) throws ProcessManagementException {
    if (processInfo.getProvideList() != null) {
        EndpointReferencesType eprsType = new EndpointReferencesType();
        for (TProvide provide : processInfo.getProvideList()) {
            String plinkName = provide.getPartnerLink();
            TService service = provide.getService();
            /* NOTE:Service cannot be null for provider partner link*/
            if (service == null) {
                String errorMsg = "Error in <provide> element for process " + processInfo.getName() + " partnerlink" + plinkName + " did not identify an endpoint";
                log.error(errorMsg);
                throw new ProcessManagementException(errorMsg);
            }
            if (log.isDebugEnabled()) {
                log.debug("Processing <provide> element for process " + processInfo.getName() + ": partnerlink " + plinkName + " --> " + service.getName() + " : " + service.getPort());
            }
            QName serviceName = service.getName();
            EndpointRef_type0 eprType = new EndpointRef_type0();
            eprType.setPartnerLink(plinkName);
            eprType.setService(serviceName);
            ServiceLocation sLocation = new ServiceLocation();
            try {
                String url = Utils.getTryitURL(serviceName.getLocalPart(), getConfigContext());
                sLocation.addServiceLocation(url);
                String[] wsdls = Utils.getWsdlInformation(serviceName.getLocalPart(), getConfigContext().getAxisConfiguration());
                if (wsdls.length == 2) {
                    if (wsdls[0].endsWith("?wsdl")) {
                        sLocation.addServiceLocation(wsdls[0]);
                    } else {
                        sLocation.addServiceLocation(wsdls[1]);
                    }
                }
            } catch (AxisFault axisFault) {
                String errMsg = "Error while getting try-it url for the service: " + serviceName;
                log.error(errMsg, axisFault);
                throw new ProcessManagementException(errMsg, axisFault);
            }
            eprType.setServiceLocations(sLocation);
            eprsType.addEndpointRef(eprType);
        }
        pInfo.setEndpoints(eprsType);
    }
// if (processInfo.getInvokeList() != null) {
// for (TInvoke invoke : processInfo.getInvokeList()) {
// String plinkName = invoke.getPartnerLink();
// TService service = invoke.getService();
// /* NOTE:Service can be null for partner links*/
// if (service == null) {
// continue;
// }
// if (log.isDebugEnabled()) {
// log.debug("Processing <invoke> element for process " + processInfo.getName() + ": partnerlink" +
// plinkName + " -->" + service);
// }
// 
// QName serviceName = service.getName();
// }
// }
}
Also used : AxisFault(org.apache.axis2.AxisFault) QName(javax.xml.namespace.QName) ServiceLocation(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ServiceLocation) EndpointReferencesType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.EndpointReferencesType) EndpointRef_type0(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.EndpointRef_type0) TProvide(org.apache.ode.bpel.dd.TProvide) TService(org.apache.ode.bpel.dd.TService) ProcessManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.ProcessManagementException)

Aggregations

Test (org.testng.annotations.Test)87 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)82 Query (org.wso2.siddhi.query.api.execution.query.Query)81 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)79 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)79 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)79 Event (org.wso2.siddhi.core.event.Event)77 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)76 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)73 Element (org.w3c.dom.Element)34 OMElement (org.apache.axiom.om.OMElement)25 QName (javax.xml.namespace.QName)15 SVGCoordinates (org.wso2.carbon.bpel.ui.bpel2svg.SVGCoordinates)14 ActivityInterface (org.wso2.carbon.bpel.ui.bpel2svg.ActivityInterface)13 NodeList (org.w3c.dom.NodeList)12 Element (org.wso2.siddhi.query.api.annotation.Element)12 Node (org.w3c.dom.Node)11 ArrayList (java.util.ArrayList)9 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)8 HashMap (java.util.HashMap)7