Пример #1
0
  @SuppressWarnings("unchecked")
  public long addOutputContent(long taskId, Map<String, Object> params) {
    Task task = persistenceContext.findTask(taskId);
    long outputContentId = task.getTaskData().getOutputContentId();
    Content outputContent = persistenceContext.findContent(outputContentId);

    long contentId = -1;
    if (outputContent == null) {
      ContentMarshallerContext context = getMarshallerContext(task);
      ContentData outputContentData =
          ContentMarshallerHelper.marshal(task, params, context.getEnvironment());
      Content content = TaskModelProvider.getFactory().newContent();
      ((InternalContent) content).setContent(outputContentData.getContent());
      persistenceContext.persistContent(content);

      ((InternalTaskData) task.getTaskData()).setOutput(content.getId(), outputContentData);
      contentId = content.getId();
    } else {
      // I need to merge it if it already exist
      ContentMarshallerContext context = getMarshallerContext(task);
      Object unmarshalledObject =
          ContentMarshallerHelper.unmarshall(
              outputContent.getContent(), context.getEnvironment(), context.getClassloader());
      if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
        ((Map<String, Object>) unmarshalledObject).putAll(params);
      }
      ContentData outputContentData =
          ContentMarshallerHelper.marshal(task, unmarshalledObject, context.getEnvironment());
      ((InternalContent) outputContent).setContent(outputContentData.getContent());
      persistenceContext.persistContent(outputContent);
      contentId = outputContentId;
    }
    ((InternalTaskData) task.getTaskData()).setTaskOutputVariables(params);
    taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, params);

    return contentId;
  }
Пример #2
0
  public void taskOperation(
      final Operation operation,
      final long taskId,
      final String userId,
      final String targetEntityId,
      final Map<String, Object> data,
      List<String> groupIds,
      OrganizationalEntity... entities)
      throws TaskException {

    try {
      final List<OperationCommand> commands = operations.get(operation);

      Task task = persistenceContext.findTask(taskId);
      if (task == null) {
        String errorMessage = "Task '" + taskId + "' not found";
        throw new PermissionDeniedException(errorMessage);
      }
      User user = persistenceContext.findUser(userId);
      OrganizationalEntity targetEntity = null;
      if (targetEntityId != null && !targetEntityId.equals("")) {
        targetEntity = persistenceContext.findOrgEntity(targetEntityId);
      }

      switch (operation) {
        case Activate:
          {
            taskEventSupport.fireBeforeTaskActivated(task, context);
            break;
          }
        case Claim:
          {
            taskEventSupport.fireBeforeTaskClaimed(task, context);
            break;
          }
        case Complete:
          {
            taskEventSupport.fireBeforeTaskCompleted(task, context);
            break;
          }
        case Delegate:
          {
            taskEventSupport.fireBeforeTaskDelegated(task, context);
            break;
          }
        case Exit:
          {
            taskEventSupport.fireBeforeTaskExited(task, context);
            break;
          }

        case Fail:
          {
            if (data != null) {

              FaultData faultData = ContentMarshallerHelper.marshalFault(data, null);
              Content content = TaskModelProvider.getFactory().newContent();
              ((InternalContent) content).setContent(faultData.getContent());
              persistenceContext.persistContent(content);
              ((InternalTaskData) task.getTaskData()).setFault(content.getId(), faultData);
            }
            taskEventSupport.fireBeforeTaskFailed(task, context);
            break;
          }
        case Forward:
          {
            taskEventSupport.fireBeforeTaskForwarded(task, context);
            break;
          }
        case Nominate:
          {
            taskEventSupport.fireBeforeTaskNominated(task, context);
            break;
          }
        case Release:
          {
            taskEventSupport.fireBeforeTaskReleased(task, context);
            break;
          }
        case Resume:
          {
            taskEventSupport.fireBeforeTaskResumed(task, context);
            break;
          }
        case Skip:
          {
            taskEventSupport.fireBeforeTaskSkipped(task, context);
            break;
          }
        case Start:
          {
            taskEventSupport.fireBeforeTaskStarted(task, context);
            break;
          }
        case Stop:
          {
            taskEventSupport.fireBeforeTaskStopped(task, context);
            break;
          }
        case Suspend:
          {
            taskEventSupport.fireBeforeTaskSuspended(task, context);
            break;
          }
      }

      evalCommand(operation, commands, task, user, targetEntity, groupIds, entities);

      switch (operation) {
        case Activate:
          {
            taskEventSupport.fireAfterTaskActivated(task, context);
            break;
          }
        case Claim:
          {
            taskEventSupport.fireAfterTaskClaimed(task, context);
            break;
          }
        case Complete:
          {
            if (data != null) {

              taskContentService.addOutputContent(taskId, data);
            }
            taskEventSupport.fireAfterTaskCompleted(task, context);
            break;
          }
        case Delegate:
          {
            // This is a really bad hack to execut the correct behavior
            ((InternalTaskData) task.getTaskData()).setStatus(Status.Reserved);
            taskEventSupport.fireAfterTaskDelegated(task, context);
            break;
          }
        case Exit:
          {
            taskEventSupport.fireAfterTaskExited(task, context);
            break;
          }
        case Fail:
          {
            taskEventSupport.fireAfterTaskFailed(task, context);
            break;
          }
        case Forward:
          {
            taskEventSupport.fireAfterTaskForwarded(task, context);
            break;
          }
        case Nominate:
          {
            taskEventSupport.fireAfterTaskNominated(task, context);
            break;
          }
        case Release:
          {
            taskEventSupport.fireAfterTaskReleased(task, context);
            break;
          }
        case Resume:
          {
            taskEventSupport.fireAfterTaskResumed(task, context);
            break;
          }
        case Start:
          {
            taskEventSupport.fireAfterTaskStarted(task, context);
            break;
          }
        case Skip:
          {
            taskEventSupport.fireAfterTaskSkipped(task, context);
            break;
          }
        case Stop:
          {
            taskEventSupport.fireAfterTaskStopped(task, context);
            break;
          }
        case Suspend:
          {
            taskEventSupport.fireAfterTaskSuspended(task, context);
            break;
          }
      }
    } catch (RuntimeException re) {
      throw re;
    }
  }