Search in sources :

Example 11 with IllegalArgumentFault

use of org.wso2.carbon.humantask.client.api.IllegalArgumentFault in project carbon-business-process by wso2.

the class TaskOperationsImpl method deleteComment.

/**
 * Deletes the identified comment.
 * @param taskIdURI : task identifier
 * @param commentId : comment identifier
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void deleteComment(final URI taskIdURI, final URI commentId) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                DeleteComment deleteComment = new DeleteComment(getCaller(), taskId, new Long(commentId.toString()));
                deleteComment.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : DeleteComment(org.wso2.carbon.humantask.core.engine.commands.DeleteComment) 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 12 with IllegalArgumentFault

use of org.wso2.carbon.humantask.client.api.IllegalArgumentFault in project carbon-business-process by wso2.

the class TaskOperationsImpl method addAttachment.

/**
 * Add attachment to a task. Returns an identifier for the attachment.
 * @param taskIdentifier : task identifier
 * @param name : attachment name
 * @param accessType : access type
 * @param contentType : content type
 * @param attachment : attachment ID (String)
 * @return
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public boolean addAttachment(URI taskIdentifier, String name, String accessType, String contentType, Object attachment) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    final Long taskId = validateTaskId(taskIdentifier);
    final String attachmentID = (String) attachment;
    try {
        Boolean isAdded = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Boolean>() {

            public Boolean call() throws Exception {
                HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
                HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
                TaskDAO taskDAO = daoConn.getTask(taskId);
                validateTaskTenant(taskDAO);
                try {
                    boolean isAdded = taskDAO.addAttachment(TransformerUtils.generateAttachmentDAOFromID(taskDAO, attachmentID));
                    if (!isAdded) {
                        throw new HumanTaskException("Attachment with id: " + attachmentID + "was not associated " + "task with id:" + taskId);
                    }
                    return isAdded;
                } catch (HumanTaskException ex) {
                    String errMsg = "getAttachmentInfos operation failed. Reason: ";
                    log.error(errMsg + ex.getLocalizedMessage(), ex);
                    throw ex;
                }
            }
        });
        return isAdded;
    } catch (Exception ex) {
        handleException(ex);
    }
    return false;
}
Also used : HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) HumanTaskDAOConnection(org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection) 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) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException)

Example 13 with IllegalArgumentFault

use of org.wso2.carbon.humantask.client.api.IllegalArgumentFault in project carbon-business-process by wso2.

the class TaskOperationsImpl method deleteOutput.

/**
 * Deletes the output data of the task.
 * @param taskIdURI : task identifier
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void deleteOutput(final URI taskIdURI) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                DeleteOutput deleteOutput = new DeleteOutput(getCaller(), taskId);
                deleteOutput.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : DeleteOutput(org.wso2.carbon.humantask.core.engine.commands.DeleteOutput) 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 14 with IllegalArgumentFault

use of org.wso2.carbon.humantask.client.api.IllegalArgumentFault in project carbon-business-process by wso2.

the class HTRenderingApiImpl method setTaskOutput.

public SetTaskOutputResponse setTaskOutput(URI taskIdentifier, SetOutputValuesType values) throws SetTaskOutputFaultException {
    // Retrieve task information
    TaskDAO htTaskDAO;
    try {
        htTaskDAO = getTaskDAO(taskIdentifier);
    } catch (Exception e) {
        log.error("Error occurred while retrieving task data", e);
        throw new SetTaskOutputFaultException(e);
    }
    QName taskName = QName.valueOf(htTaskDAO.getName());
    // Check hash map for output message template
    Element outputMsgTemplate = outputTemplates.get(taskName);
    if (outputMsgTemplate == null) {
        try {
            // generate output message template
            int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
            HumanTaskBaseConfiguration htConf = HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantID).getTaskConfiguration(taskName);
            TaskConfiguration taskConf = (TaskConfiguration) htConf;
            // retrieve response binding
            Service callbackService = (Service) taskConf.getResponseWSDL().getServices().get(taskConf.getCallbackServiceName());
            Port callbackPort = (Port) callbackService.getPorts().get(taskConf.getCallbackPortName());
            String callbackBinding = callbackPort.getBinding().getQName().getLocalPart();
            outputMsgTemplate = createSoapTemplate(taskConf.getResponseWSDL().getDocumentBaseURI(), taskConf.getResponsePortType().getLocalPart(), taskConf.getResponseOperation(), callbackBinding);
        } catch (Exception e) {
            log.error("Error occurred while output message template generation", e);
            throw new SetTaskOutputFaultException("Unable to generate output message", e);
        }
        // add to the template HashMap
        if (outputMsgTemplate != null) {
            outputTemplates.put(taskName, outputMsgTemplate);
        } else {
            log.error("Unable to create output message template");
            throw new SetTaskOutputFaultException("Unable to generate output message");
        }
    }
    // update template with new values
    try {
        // TODO improve this section with caching
        QName renderingType = new QName(htRenderingNS, "output", "wso2");
        String outputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
        SetOutputvalueType[] valueSet = values.getValue();
        if (outputRenderings != null && valueSet.length > 0) {
            Element outputRenderingsElement = DOMUtils.stringToDOM(outputRenderings);
            // update elements in the template to create output xml
            for (int i = 0; i < valueSet.length; i++) {
                Element outElement = getOutputElementById(valueSet[i].getId(), outputRenderingsElement);
                if (outElement != null) {
                    outputMsgTemplate = updateXmlByXpath(outputMsgTemplate, outElement.getElementsByTagNameNS(htRenderingNS, "xpath").item(0).getTextContent(), valueSet[i].getString(), outputRenderingsElement.getOwnerDocument());
                }
            }
        } else {
            log.error("Retrieving output renderings failed");
            throw new SetTaskOutputFaultException("Retrieving output renderings failed");
        }
        // TODO what is this NCName?
        taskOps.setOutput(taskIdentifier, new NCName("message"), DOMUtils.domToString(outputMsgTemplate));
    } catch (IllegalArgumentFault illegalArgumentFault) {
        // Error occurred while retrieving HT renderings and set output message
        throw new SetTaskOutputFaultException(illegalArgumentFault);
    } catch (SAXException e) {
        log.error("Error occured while parsing output renderings", e);
        throw new SetTaskOutputFaultException("Response message generation failed");
    } catch (XPathExpressionException e) {
        // Error occured while updating elements in the template to create output xml
        log.error("XPath evaluation failed", e);
        throw new SetTaskOutputFaultException("Internal Error Occurred");
    } catch (Exception e) {
        // Error occurred while updating template with new values
        log.error("Error occurred while updating template with new values", e);
        throw new SetTaskOutputFaultException("Internal Error Occurred");
    }
    SetTaskOutputResponse response = new SetTaskOutputResponse();
    response.setSuccess(true);
    return response;
}
Also used : QName(javax.xml.namespace.QName) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Element(org.w3c.dom.Element) Port(javax.wsdl.Port) SetTaskOutputResponse(org.wso2.carbon.humantask.rendering.api.SetTaskOutputResponse) TaskConfiguration(org.wso2.carbon.humantask.core.store.TaskConfiguration) Service(javax.wsdl.Service) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SetTaskOutputFaultException(org.wso2.carbon.humantask.rendering.api.SetTaskOutputFaultException) GetRenderingsFaultException(org.wso2.carbon.humantask.rendering.api.GetRenderingsFaultException) SAXException(org.xml.sax.SAXException) CompleteTaskFaultException(org.wso2.carbon.humantask.rendering.api.CompleteTaskFaultException) IOException(java.io.IOException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) NCName(org.apache.axis2.databinding.types.NCName) SAXException(org.xml.sax.SAXException) SetOutputvalueType(org.wso2.carbon.humantask.rendering.api.SetOutputvalueType) TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) IllegalArgumentFault(org.wso2.carbon.humantask.client.api.IllegalArgumentFault) SetTaskOutputFaultException(org.wso2.carbon.humantask.rendering.api.SetTaskOutputFaultException)

Example 15 with IllegalArgumentFault

use of org.wso2.carbon.humantask.client.api.IllegalArgumentFault in project carbon-business-process by wso2.

the class HTRenderingApiImpl method getRenderingInputElements.

/**
 * @param taskIdentifier : interested task identifier
 * @return set of input renderings wrapped within InputType
 * @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 content in the input source is invalid
 */
private InputType getRenderingInputElements(URI taskIdentifier) throws IllegalArgumentFault, IOException, SAXException, IllegalOperationFault, IllegalAccessFault, IllegalStateFault, XPathExpressionException {
    // TODO Chaching : check cache against task id for input renderings
    QName renderingType = new QName(htRenderingNS, "input", "wso2");
    String inputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
    // Create input element
    InputType renderingInputs = null;
    // check availability of input renderings
    if (inputRenderings != null && inputRenderings.length() > 0) {
        // parse input renderings
        Element inputRenderingsElement = DOMUtils.stringToDOM(inputRenderings);
        // retrieve input elements
        NodeList inputElementList = inputRenderingsElement.getElementsByTagNameNS(htRenderingNS, "element");
        Element taskInputMsgElement = DOMUtils.stringToDOM((String) taskOps.getInput(taskIdentifier, null));
        if (inputElementList != null && inputElementList.getLength() > 0) {
            // hold number of input element
            int inputElementNum = inputElementList.getLength();
            InputElementType[] inputElements = new InputElementType[inputElementNum];
            for (int i = 0; i < inputElementNum; i++) {
                Element tempElement = (Element) inputElementList.item(i);
                String label = tempElement.getElementsByTagNameNS(htRenderingNS, "label").item(0).getTextContent();
                String value = tempElement.getElementsByTagNameNS(htRenderingNS, "value").item(0).getTextContent();
                // if the value starts with '/' then considered as an xpath and evaluate over received Input Message
                if (value.startsWith("/") && taskInputMsgElement != null) {
                    // value represents xpath. evaluate against the input message
                    String xpathValue = evaluateXPath(value, taskInputMsgElement, inputRenderingsElement.getOwnerDocument());
                    if (xpathValue != null) {
                        value = xpathValue;
                    }
                }
                inputElements[i] = new InputElementType();
                inputElements[i].setLabel(label);
                inputElements[i].setValue(value);
            }
            renderingInputs = new InputType();
            renderingInputs.setElement(inputElements);
        // TODO cache renderingInputs against task instance id
        }
    }
    return renderingInputs;
}
Also used : InputElementType(org.wso2.carbon.humantask.rendering.api.InputElementType) InputType(org.wso2.carbon.humantask.rendering.api.InputType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList)

Aggregations

HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)25 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)24 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)24 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)24 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)24 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)24 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)24 UserStoreException (org.wso2.carbon.user.core.UserStoreException)24 Element (org.w3c.dom.Element)9 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)5 HumanTaskCommand (org.wso2.carbon.humantask.core.engine.HumanTaskCommand)5 QName (javax.xml.namespace.QName)4 HumanTaskDAOConnection (org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection)4 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)4 HumanTaskBaseConfiguration (org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)3 URI (org.apache.axis2.databinding.types.URI)2 NodeList (org.w3c.dom.NodeList)2 IllegalArgumentFault (org.wso2.carbon.humantask.client.api.IllegalArgumentFault)2 Complete (org.wso2.carbon.humantask.core.engine.commands.Complete)2 IOException (java.io.IOException)1