protected void addUserFromCallbackOperation(String userId) {
   try {
     boolean userExists = pm.find(UserImpl.class, userId) != null;
     if (!StringUtils.isEmpty(userId) && !userExists) {
       UserImpl user = new UserImpl(userId);
       pm.persist(user);
     }
   } catch (Throwable t) {
     // logger.log(Level.SEVERE, "Unable to add user " + userId);
   }
 }
 protected void addGroupFromCallbackOperation(String groupId) {
   try {
     boolean groupExists = pm.find(GroupImpl.class, groupId) != null;
     if (!StringUtils.isEmpty(groupId) && !groupExists) {
       GroupImpl group = new GroupImpl(groupId);
       pm.persist(group);
     }
   } catch (Throwable t) {
     // logger.log(Level.WARNING, "UserGroupCallback has not been registered.");
   }
 }
Esempio n. 3
0
  @PostConstruct
  public void init() {
    // 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());
    }

    long now = System.currentTimeMillis();
    List<DeadlineSummaryImpl> resultList =
        (List<DeadlineSummaryImpl>) pm.queryInTransaction("UnescalatedStartDeadlines");
    for (DeadlineSummaryImpl summary : resultList) {
      long delay = summary.getDate().getTime() - now;
      schedule(summary.getTaskId(), summary.getDeadlineId(), delay, DeadlineType.START);
    }

    resultList = (List<DeadlineSummaryImpl>) pm.queryInTransaction("UnescalatedEndDeadlines");
    for (DeadlineSummaryImpl summary : resultList) {
      long delay = summary.getDate().getTime() - now;
      schedule(summary.getTaskId(), summary.getDeadlineId(), delay, DeadlineType.END);
    }
  }
Esempio n. 4
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);
  }