Search in sources :

Example 16 with TaskDAO

use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.

the class Skip method execute.

public void execute() {
    authorise();
    TaskDAO task = getTask();
    checkPreConditions();
    checkState();
    task.skip();
    sendSkipProtocolMessage(task);
    processTaskEvent();
    checkPostConditions();
}
Also used : TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO)

Example 17 with TaskDAO

use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.

the class HumanTaskBuilderImpl method build.

/**
 * Builds the Task from the given input.
 *
 * @return : The created task object.
 */
public TaskDAO build() {
    validateParams();
    TaskDAO task;
    HumanTaskBaseConfiguration taskConfiguration = creationContext.getTaskConfiguration();
    int tenantId = creationContext.getTenantId();
    if (creationContext.getTaskConfiguration().isTask()) {
        task = new Task(taskConfiguration.getName(), TaskType.TASK, tenantId);
    } else {
        task = new Task(taskConfiguration.getName(), TaskType.NOTIFICATION, tenantId);
    }
    task.setInputMessage(this.inputMessage);
    task.setSkipable(false);
    task.setEscalated(false);
    task.setStatus(TaskStatus.CREATED);
    task.setActivationTime(new Date());
    task.setTaskVersion(taskConfiguration.getVersion());
    task.setTaskPackageName(taskConfiguration.getPackageName());
    task.setDefinitionName(taskConfiguration.getDefinitionName());
    if (creationContext.getTaskConfiguration().isTask()) {
        // Setting the attachments to the task
        try {
            task.setAttachments(TransformerUtils.generateAttachmentDAOListFromIDs(task, creationContext.getAttachmentIDs()));
        } catch (HumanTaskException e) {
            log.error(e.getLocalizedMessage(), e);
        }
    }
    // Setting the attachments to the task
    try {
        task.setAttachments(TransformerUtils.generateAttachmentDAOListFromIDs(task, creationContext.getAttachmentIDs()));
    } catch (HumanTaskException e) {
        log.error(e.getLocalizedMessage(), e);
    }
    return task;
}
Also used : Task(org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task) TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration) Date(java.util.Date) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException)

Example 18 with TaskDAO

use of org.wso2.carbon.humantask.core.dao.TaskDAO 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 19 with TaskDAO

use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.

the class HTRenderingApiImpl method getTaskDAO.

/**
 * Function to retrieve task DAO
 *
 * @param taskIdURI task ID
 * @return task DAO
 * @throws Exception
 * @throws IllegalArgumentException
 */
private TaskDAO getTaskDAO(URI taskIdURI) throws IllegalArgumentException, HumanTaskIllegalAccessException, Exception {
    final Long taskId = validateTaskId(taskIdURI);
    TaskDAO 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(taskId);
            validateTaskTenant(task);
            return task;
        }
    });
    return task;
}
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) 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)

Example 20 with TaskDAO

use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.

the class JPATaskUtil method assignHumanRoles.

private static void assignHumanRoles(TaskDAO task, PeopleQueryEvaluator peopleQueryEvaluator, TGenericHumanRoleAssignment roleAssignment, GenericHumanRole.GenericHumanRoleType type, EvaluationContext evaluationContext) throws HumanTaskException {
    OrganizationalEntityProvider provider = OrganizationalEntityProviderFactory.getOrganizationalEntityProvider(roleAssignment.getFrom());
    List<OrganizationalEntityDAO> orgEntities = provider.getOrganizationalEntities(peopleQueryEvaluator, roleAssignment.getFrom(), evaluationContext);
    GenericHumanRole humanRole = new GenericHumanRole();
    humanRole.setType(type);
    humanRole.setOrgEntities(orgEntities);
    humanRole.setTask(task);
    for (OrganizationalEntityDAO oe : orgEntities) {
        oe.addGenericHumanRole(humanRole);
    }
    task.addHumanRole(humanRole);
}
Also used : OrganizationalEntityProvider(org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.OrganizationalEntityProvider)

Aggregations

TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)27 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)16 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)7 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)7 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)7 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)7 UserStoreException (org.wso2.carbon.user.core.UserStoreException)7 Element (org.w3c.dom.Element)6 HumanTaskDAOConnection (org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection)6 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)6 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)6 QName (javax.xml.namespace.QName)5 HumanTaskBaseConfiguration (org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)5 TaskConfiguration (org.wso2.carbon.humantask.core.store.TaskConfiguration)5 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)4 URI (org.apache.axis2.databinding.types.URI)3 NodeList (org.w3c.dom.NodeList)3 PeopleQueryEvaluator (org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)3 ExpressionEvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext)3 EvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext)3