protected void doCallbackOperationForTaskDeadlines(Deadlines deadlines) {
    if (deadlines != null) {
      if (deadlines.getStartDeadlines() != null) {
        List<? extends Deadline> startDeadlines = deadlines.getStartDeadlines();
        for (Deadline startDeadline : startDeadlines) {
          List<? extends Escalation> escalations = startDeadline.getEscalations();
          if (escalations != null) {
            for (Escalation escalation : escalations) {
              List<? extends Notification> notifications = escalation.getNotifications();
              List<? extends Reassignment> ressignments = escalation.getReassignments();
              if (notifications != null) {
                for (Notification notification : notifications) {
                  List<? extends OrganizationalEntity> recipients = notification.getRecipients();
                  if (recipients != null) {
                    for (OrganizationalEntity recipient : recipients) {
                      if (recipient instanceof User) {
                        doCallbackUserOperation(recipient.getId());
                      }
                      if (recipient instanceof Group) {
                        doCallbackGroupOperation(recipient.getId());
                      }
                    }
                  }
                  List<? extends OrganizationalEntity> administrators =
                      notification.getBusinessAdministrators();
                  if (administrators != null) {
                    for (OrganizationalEntity administrator : administrators) {
                      if (administrator instanceof User) {
                        doCallbackUserOperation(administrator.getId());
                      }
                      if (administrator instanceof Group) {
                        doCallbackGroupOperation(administrator.getId());
                      }
                    }
                  }
                }
              }
              if (ressignments != null) {
                for (Reassignment reassignment : ressignments) {
                  List<? extends OrganizationalEntity> potentialOwners =
                      reassignment.getPotentialOwners();
                  if (potentialOwners != null) {
                    for (OrganizationalEntity potentialOwner : potentialOwners) {
                      if (potentialOwner instanceof User) {
                        doCallbackUserOperation(potentialOwner.getId());
                      }
                      if (potentialOwner instanceof Group) {
                        doCallbackGroupOperation(potentialOwner.getId());
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }

      if (deadlines.getEndDeadlines() != null) {
        List<? extends Deadline> endDeadlines = deadlines.getEndDeadlines();
        for (Deadline endDeadline : endDeadlines) {
          List<? extends Escalation> escalations = endDeadline.getEscalations();
          if (escalations != null) {
            for (Escalation escalation : escalations) {
              List<? extends Notification> notifications = escalation.getNotifications();
              List<? extends Reassignment> ressignments = escalation.getReassignments();
              if (notifications != null) {
                for (Notification notification : notifications) {
                  List<? extends OrganizationalEntity> recipients = notification.getRecipients();
                  if (recipients != null) {
                    for (OrganizationalEntity recipient : recipients) {
                      if (recipient instanceof User) {
                        doCallbackUserOperation(recipient.getId());
                      }
                      if (recipient instanceof Group) {
                        doCallbackGroupOperation(recipient.getId());
                      }
                    }
                  }
                  List<? extends OrganizationalEntity> administrators =
                      notification.getBusinessAdministrators();
                  if (administrators != null) {
                    for (OrganizationalEntity administrator : administrators) {
                      if (administrator instanceof User) {
                        doCallbackUserOperation(administrator.getId());
                      }
                      if (administrator instanceof Group) {
                        doCallbackGroupOperation(administrator.getId());
                      }
                    }
                  }
                }
              }
              if (ressignments != null) {
                for (Reassignment reassignment : ressignments) {
                  List<? extends OrganizationalEntity> potentialOwners =
                      reassignment.getPotentialOwners();
                  if (potentialOwners != null) {
                    for (OrganizationalEntity potentialOwner : potentialOwners) {
                      if (potentialOwner instanceof User) {
                        doCallbackUserOperation(potentialOwner.getId());
                      }
                      if (potentialOwner instanceof Group) {
                        doCallbackGroupOperation(potentialOwner.getId());
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
예제 #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);
  }