Exemplo n.º 1
0
  private Void executedeadLine(
      TaskContext ctx,
      TaskPersistenceContext persistenceContext,
      Task task,
      DeadlineSummaryImpl deadlineSummaryImpl,
      TaskData taskData) {
    Deadline deadline = persistenceContext.findDeadline(deadlineSummaryImpl.getDeadlineId());
    if (task == null || deadline == null) {
      return null;
    }

    if (taskData != null) {
      // check if task is still in valid status
      if (DeadlineType.START.isValidStatus(taskData.getStatus())
          || DeadlineType.END.isValidStatus(taskData.getStatus())) {
        Map<String, Object> variables = getVariables(ctx, persistenceContext, task, taskData);
        if (deadline == null || deadline.getEscalations() == null) {
          return null;
        }

        for (Escalation escalation : deadline.getEscalations()) {
          for (Notification notification : escalation.getNotifications()) {
            if (notification.getNotificationType() == NotificationType.Email) {
              logger.debug("Sending an Email");
              notificationListener.onNotification(
                  new NotificationEvent(notification, task, variables));
            }
          }
        }
      }
    }
    return null;
  }
Exemplo n.º 2
0
  private void executeEscalatedDeadline(long taskId, long deadlineId, DeadlineType type) {
    // make sure it has tx manager as it runs as background thread - no request scope available
    if (!((JbpmServicesPersistenceManagerImpl) pm).hasTransactionManager()) {
      ((JbpmServicesPersistenceManagerImpl) pm)
          .setTransactionManager(new JbpmJTATransactionManager());
    }

    TaskImpl task = (TaskImpl) pm.find(TaskImpl.class, taskId);
    Deadline deadline = (DeadlineImpl) pm.find(DeadlineImpl.class, deadlineId);

    TaskData taskData = task.getTaskData();

    if (taskData != null) {
      // check if task is still in valid status
      if (type.isValidStatus(taskData.getStatus())) {
        Map<String, Object> variables = null;

        ContentImpl content =
            (ContentImpl) pm.find(ContentImpl.class, taskData.getDocumentContentId());

        if (content != null) {
          Object objectFromBytes =
              ContentMarshallerHelper.unmarshall(
                  content.getContent(), getEnvironment(), getClassLoader());

          if (objectFromBytes instanceof Map) {
            variables = (Map) objectFromBytes;

          } else {

            variables = new HashMap<String, Object>();
            variables.put("content", objectFromBytes);
          }
        } else {
          variables = Collections.emptyMap();
        }

        if (deadline == null || deadline.getEscalations() == null) {
          return;
        }

        for (Escalation escalation : deadline.getEscalations()) {

          // we won't impl constraints for now
          // escalation.getConstraints()

          // run reassignment first to allow notification to be send to new potential owners
          if (!escalation.getReassignments().isEmpty()) {
            // get first and ignore the rest.
            Reassignment reassignment = escalation.getReassignments().get(0);

            task.getTaskData().setStatus(Status.Ready);
            List potentialOwners = new ArrayList(reassignment.getPotentialOwners());
            task.getPeopleAssignments().setPotentialOwners(potentialOwners);
            task.getTaskData().setActualOwner(null);
          }
          for (Notification notification : escalation.getNotifications()) {
            if (notification.getNotificationType() == NotificationType.Email) {
              logger.log(Level.INFO, " ### Sending an Email");
              notificationEvents.fire(new NotificationEvent(notification, task, variables));
            }
          }
        }
      }
    }

    deadline.setEscalated(true);
  }