Search in sources :

Example 31 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class CommonTaskUtil method populateTaskEventInfo.

/**
 * Create the TaskEventInfo object from the EventDAO and the TaskDAO.
 * @param eventDAO : The event
 * @param taskDAO : The related task dao.
 *
 * @return : The new TaskEventInfo object.
 */
public static TaskEventInfo populateTaskEventInfo(EventDAO eventDAO, TaskDAO taskDAO) {
    TaskEventInfo eventInfo = new TaskEventInfo();
    eventInfo.setTimestamp(eventDAO.getTimeStamp());
    eventInfo.setEventInitiator(eventDAO.getUser());
    eventInfo.setEventType(eventDAO.getType());
    eventInfo.setNewState(eventDAO.getNewState());
    eventInfo.setOldState(eventDAO.getOldState());
    eventInfo.setTaskInfo(populateTaskInfo(taskDAO));
    return eventInfo;
}
Also used : TaskEventInfo(org.wso2.carbon.humantask.core.api.event.TaskEventInfo)

Example 32 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class NotificationScheduler method publishEmailNotifications.

/**
 * Publish Email notifications by extracting the information from the incoming message rendering tags
 * <htd:renderings>
 *  <htd:rendering type="wso2:email" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
 *     <wso2:to name="to" type="xsd:string">wso2bpsemail@wso2.com</wso2:to>
 *     <wso2:subject name="subject" type="xsd:string">email subject to user</wso2:subject>
 *     <wso2:body name="body" type="xsd:string">Hi email notifications</wso2:body>
 *  </htd:rendering>
 *  <htd:rendering type="wso2:sms" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
 *      <wso2:receiver name="receiver" type="xsd:string">94777459299</wso2:receiver>
 *      <wso2:body name="body" type="xsd:string">Hi $firstname$</wso2:body>
 *  </htd:rendering>
 *</htd:renderings>
 *
 * @param  task TaskDAO object for this notification task instance
 * @param taskConfiguration task configuration instance for this notification task definition
 */
public void publishEmailNotifications(TaskDAO task, HumanTaskBaseConfiguration taskConfiguration) throws IOException, SAXException, ParserConfigurationException {
    String rendering = CommonTaskUtil.getRendering(task, taskConfiguration, new QName(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.RENDERING_TYPE_EMAIL));
    if (rendering != null) {
        Map<String, String> dynamicPropertiesForEmail = new HashMap<String, String>();
        Element root = DOMUtils.stringToDOM(rendering);
        if (root != null) {
            String emailBody = null;
            String mailSubject = null;
            String mailTo = null;
            String contentType = null;
            NodeList mailToList = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_TO_TAG);
            if (log.isDebugEnabled()) {
                log.debug("Parsing Email notification rendering element to for notification id " + task.getId());
            }
            if (mailToList != null && mailToList.getLength() > 0) {
                mailTo = mailToList.item(0).getTextContent();
            } else {
                log.warn("Email to address not specified for email notification with notification id " + task.getId());
            }
            NodeList mailSubjectList = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_SUBJECT_TAG);
            if (log.isDebugEnabled()) {
                log.debug("Paring Email notification rendering element subject " + task.getId());
            }
            if (mailSubjectList != null && mailSubjectList.getLength() > 0) {
                mailSubject = mailSubjectList.item(0).getTextContent();
            } else {
                log.warn("Email subject not specified for email notification with notification id " + task.getId());
            }
            NodeList mailContentType = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_CONTENT_TYPE_TAG);
            if (log.isDebugEnabled()) {
                log.debug("Paring Email notification rendering element contentType " + task.getId());
            }
            if (mailContentType != null && mailContentType.getLength() > 0) {
                contentType = mailContentType.item(0).getTextContent();
            } else {
                contentType = HumanTaskConstants.CONTENT_TYPE_TEXT_PLAIN;
                log.warn("Email contentType not specified for email notification with notification id " + task.getId() + ". Using text/plain.");
            }
            if (log.isDebugEnabled()) {
                log.debug("Parsing Email notification rendering element body tag for notification id " + task.getId());
            }
            NodeList emailBodyList = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_OR_SMS_BODY_TAG);
            if (emailBodyList != null && emailBodyList.getLength() > 0) {
                emailBody = emailBodyList.item(0).getTextContent();
            } else {
                log.warn("Email notification message body not specified for notification with id " + task.getId());
            }
            dynamicPropertiesForEmail.put(HumanTaskConstants.ARRAY_EMAIL_ADDRESS, mailTo);
            dynamicPropertiesForEmail.put(HumanTaskConstants.ARRAY_EMAIL_SUBJECT, mailSubject);
            dynamicPropertiesForEmail.put(HumanTaskConstants.ARRAY_EMAIL_TYPE, contentType);
            String adaptorName = getAdaptorName(task.getName(), HumanTaskConstants.RENDERING_TYPE_EMAIL);
            if (!emailAdapterNames.contains(adaptorName)) {
                OutputEventAdapterConfiguration outputEventAdapterConfiguration = createOutputEventAdapterConfiguration(adaptorName, HumanTaskConstants.RENDERING_TYPE_EMAIL, HumanTaskConstants.EMAIL_MESSAGE_FORMAT);
                try {
                    HumanTaskServiceComponent.getOutputEventAdapterService().create(outputEventAdapterConfiguration);
                    emailAdapterNames.add(adaptorName);
                } catch (OutputEventAdapterException e) {
                    log.error("Unable to create Output Event Adapter : " + adaptorName, e);
                }
            }
            HumanTaskServiceComponent.getOutputEventAdapterService().publish(adaptorName, dynamicPropertiesForEmail, emailBody);
        // emailAdapter.publish(emailBody, dynamicPropertiesForEmail);
        }
    } else {
        log.warn("Email Rendering type not found for task definition with task id " + task.getId());
    }
}
Also used : OutputEventAdapterException(org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) OutputEventAdapterConfiguration(org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration)

Example 33 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class NotificationScheduler method publishSMSNotifications.

/**
 * Publish SMS notifications by extracting the information from the incoming message rendering tags
 * <htd:renderings>
 *  <htd:rendering type="wso2:email" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
 *     <wso2:to name="to" type="xsd:string">wso2bpsemail@wso2.com</wso2:to>
 *     <wso2:subject name="subject" type="xsd:string">email subject to user</wso2:subject>
 *     <wso2:body name="body" type="xsd:string">Hi email notifications</wso2:body>
 *  </htd:rendering>
 *  <htd:rendering type="wso2:sms" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
 *      <wso2:receiver name="receiver" type="xsd:string">94777459299</wso2:receiver>
 *      <wso2:body name="body" type="xsd:string">Hi $firstname$</wso2:body>
 *  </htd:rendering>
 * </htd:renderings>
 * @param task Task Dao Object for this notification task
 * @param taskConfiguration task Configuration for this notification task instance
 */
public void publishSMSNotifications(TaskDAO task, HumanTaskBaseConfiguration taskConfiguration) throws IOException, SAXException, ParserConfigurationException {
    String renderingSMS = CommonTaskUtil.getRendering(task, taskConfiguration, new QName(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.RENDERING_TYPE_SMS));
    if (renderingSMS != null) {
        Map<String, String> dynamicPropertiesForSms = new HashMap<String, String>();
        Element rootSMS = DOMUtils.stringToDOM(renderingSMS);
        if (rootSMS != null) {
            String smsReceiver = null;
            String smsBody = null;
            if (log.isDebugEnabled()) {
                log.debug("Parsing SMS notification rendering element 'receiver' for notification id " + task.getId());
            }
            NodeList smsReceiverList = rootSMS.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.SMS_RECEIVER_TAG);
            if (smsReceiverList != null && smsReceiverList.getLength() > 0) {
                smsReceiver = smsReceiverList.item(0).getTextContent();
            } else {
                log.warn("SMS notification rendering element 'receiver' not specified for notification with id " + task.getId());
            }
            NodeList smsBodyList = rootSMS.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_OR_SMS_BODY_TAG);
            if (log.isDebugEnabled()) {
                log.debug("Parsing SMS notification rendering element 'body' for notification id " + task.getId());
            }
            if (smsBodyList != null && smsBodyList.getLength() > 0) {
                smsBody = smsBodyList.item(0).getTextContent();
            } else {
                log.warn("SMS notification rendering element 'body' not specified for notification with id " + task.getId());
            }
            dynamicPropertiesForSms.put(HumanTaskConstants.ARRAY_SMS_NO, smsReceiver);
            String adaptorName = getAdaptorName(task.getName(), HumanTaskConstants.RENDERING_TYPE_SMS);
            if (!smsAdapterNames.contains(adaptorName)) {
                OutputEventAdapterConfiguration outputEventAdapterConfiguration = createOutputEventAdapterConfiguration(adaptorName, HumanTaskConstants.RENDERING_TYPE_SMS, HumanTaskConstants.SMS_MESSAGE_FORMAT);
                try {
                    HumanTaskServiceComponent.getOutputEventAdapterService().create(outputEventAdapterConfiguration);
                    smsAdapterNames.add(adaptorName);
                } catch (OutputEventAdapterException e) {
                    log.error("Unable to create Output Event Adapter : " + adaptorName, e);
                }
            }
            HumanTaskServiceComponent.getOutputEventAdapterService().publish(adaptorName, dynamicPropertiesForSms, smsBody);
        // smsAdapter.publish(smsBody, dynamicPropertiesForSms);
        }
    } else {
        log.warn("SMS Rendering type not found for task definition with task id " + task.getId());
    }
}
Also used : OutputEventAdapterException(org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) OutputEventAdapterConfiguration(org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration)

Example 34 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class SimpleScheduler method updateJob.

/**
 * Update the schedule time for a job
 *
 * @param taskId        Task ID
 * @param scheduledTime Time to be updated
 * @param name          Name of the task
 */
public void updateJob(Long taskId, String name, Long scheduledTime) throws InvalidJobsInDbException, InvalidUpdateRequestException {
    long now = System.currentTimeMillis();
    if (now > scheduledTime) {
        String errMessage = "Current time: " + now + " > request time: " + scheduledTime;
        throw new InvalidUpdateRequestException(errMessage);
    }
    boolean immediate = scheduledTime <= now + immediateInterval;
    boolean nearfuture = !immediate && scheduledTime <= now + nearFutureInterval;
    Long jobId = getConnection().updateJob(taskId, name, immediate, nearfuture, nodeId, scheduledTime);
    if (jobId > -1) {
        // one job is found
        todo.dequeue(new Job(jobId));
        // We ignore if the job is not in the Map outstandingJobs
        outstandingJobs.remove(jobId);
        // Loading/Refresh the job here, in-order to update the job for the latest changes.
        // Otherwise when the next immediate load task runs, it still fetch the job with the
        // old updates.
        ParameterizedType genericSuperClass = (ParameterizedType) getConnection().getClass().getGenericSuperclass();
        Class entityClass = (Class) genericSuperClass.getActualTypeArguments()[0];
        HumanTaskJobDAO updatedJob = (HumanTaskJobDAO) getEntityManager().find(entityClass, jobId);
        getEntityManager().refresh(updatedJob);
        if (immediate) {
            // Immediate scheduling means we add the job immediately to the todo list and
            // we put it in the DB for safe keeping
            addTodoList(new Job(updatedJob));
        } else if (nearfuture) {
            // Re-schedule load-immediate job task
            todo.clearTasks(LoadImmediateTask.class);
            todo.dequeue(new Job(jobId));
            // We ignore if the job is not in the Map outstandingJobs
            outstandingJobs.remove(jobId);
            todo.enqueue(new LoadImmediateTask(System.currentTimeMillis() + 1000));
        } else {
            todo.clearTasks(UpgradeJobsTask.class);
            todo.enqueue(new UpgradeJobsTask(System.currentTimeMillis() + 1000));
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) AtomicLong(java.util.concurrent.atomic.AtomicLong) InvalidUpdateRequestException(org.wso2.carbon.humantask.core.api.scheduler.InvalidUpdateRequestException) HumanTaskJobDAO(org.wso2.carbon.humantask.core.dao.HumanTaskJobDAO)

Example 35 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class HumanTaskPackageManagementSkeleton method getTaskConfigInfo.

/**
 * +     * Check the configuration type and return the configuration information for a given task ID
 * +     * @param taskId
 * +     * @return  TaskConfigInfoResponse response
 * +     * @throws  PackageManagementException
 * +
 */
public TaskConfigInfoResponse getTaskConfigInfo(QName taskId) throws PackageManagementException {
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    TaskConfigInfoResponse response = null;
    HumanTaskBaseConfiguration taskConf = HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantId).getTaskConfiguration(taskId);
    if (taskConf != null) {
        response = new TaskConfigInfoResponse();
        if (taskConf.getConfigurationType() == HumanTaskBaseConfiguration.ConfigurationType.TASK) {
            response.setTaskName(taskConf.getName());
            response.setServiceName(taskConf.getServiceName());
            response.setPortName(taskConf.getPortName());
            response.setCallbackServiceName(((TaskConfiguration) taskConf).getCallbackServiceName());
            response.setCallbackPortName(((TaskConfiguration) taskConf).getCallbackPortName());
        } else if (taskConf.getConfigurationType() == HumanTaskBaseConfiguration.ConfigurationType.NOTIFICATION) {
            response.setTaskName(((NotificationConfiguration) taskConf).getName());
            response.setServiceName(taskConf.getServiceName());
            response.setPortName(taskConf.getPortName());
        }
    }
    return response;
}
Also used : NotificationConfiguration(org.wso2.carbon.humantask.core.store.NotificationConfiguration) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)

Aggregations

HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)41 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)35 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)28 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)28 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)28 UserStoreException (org.wso2.carbon.user.core.UserStoreException)28 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)27 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)27 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)25 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)25 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)25 ArrayList (java.util.ArrayList)14 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)13 Element (org.w3c.dom.Element)12 QName (javax.xml.namespace.QName)11 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)11 IOException (java.io.IOException)9 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)9 AxisFault (org.apache.axis2.AxisFault)8 HumanTaskDeploymentException (org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException)8