Ejemplo n.º 1
0
  @Post
  public void executeTaskAction(TaskActionRequest actionRequest) {
    if (!authenticate()) {
      return;
    }

    if (actionRequest == null) {
      throw new ResourceException(
          new Status(
              Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE.getCode(),
              "A request body was expected when executing a task action.",
              null,
              null));
    }

    Task task = getTaskFromRequest();
    if (TaskActionRequest.ACTION_COMPLETE.equals(actionRequest.getAction())) {
      completeTask(task, actionRequest);
    } else if (TaskActionRequest.ACTION_CLAIM.equals(actionRequest.getAction())) {
      claimTask(task, actionRequest);
    } else if (TaskActionRequest.ACTION_DELEGATE.equals(actionRequest.getAction())) {
      delegateTask(task, actionRequest);
    } else if (TaskActionRequest.ACTION_RESOLVE.equals(actionRequest.getAction())) {
      resolveTask(task, actionRequest);
    } else {
      throw new ActivitiIllegalArgumentException(
          "Invalid action: '" + actionRequest.getAction() + "'.");
    }
  }
Ejemplo n.º 2
0
  protected void completeTask(Task task, TaskActionRequest actionRequest) {
    if (actionRequest.getVariables() != null) {
      Map<String, Object> variablesToSet = new HashMap<String, Object>();
      for (RestVariable var : actionRequest.getVariables()) {
        if (var.getName() == null) {
          throw new ActivitiIllegalArgumentException("Variable name is required");
        }

        Object actualVariableValue =
            getApplication(ActivitiRestServicesApplication.class)
                .getRestResponseFactory()
                .getVariableValue(var);

        variablesToSet.put(var.getName(), actualVariableValue);
      }

      ActivitiUtil.getTaskService().complete(task.getId(), variablesToSet);
    } else {
      ActivitiUtil.getTaskService().complete(task.getId());
    }
  }
Ejemplo n.º 3
0
 protected void claimTask(Task task, TaskActionRequest actionRequest) {
   // In case the task is already claimed, a ActivitiTaskAlreadyClaimedException is thown and
   // converted to
   // a CONFLICT response by the StatusService
   ActivitiUtil.getTaskService().claim(task.getId(), actionRequest.getAssignee());
 }
Ejemplo n.º 4
0
 protected void delegateTask(Task task, TaskActionRequest actionRequest) {
   if (actionRequest.getAssignee() == null) {
     throw new ActivitiIllegalArgumentException("An assignee is required when delegating a task.");
   }
   ActivitiUtil.getTaskService().delegateTask(task.getId(), actionRequest.getAssignee());
 }