Class DefaultTaskService

java.lang.Object
cloud.opencode.base.flow.internal.DefaultTaskService
All Implemented Interfaces:
TaskService

public final class DefaultTaskService extends Object implements TaskService
Default TaskService implementation. Centralises the v4 §8.0.1 ownership pre-check (requireOwnedPendingTask(String, String)) and delegates to one of the seven operation/* classes. 默认 TaskService 实现:集中实现所有权前置校验,再委派给 7 个 operation。

R3 SEC P0-3/4/5: when a non-no-op CurrentUserProvider is wired, the read-by-id and per-user listing methods enforce that the caller is either the resource owner (assignee / initiator) or an administrator — defeating IDOR enumeration. With the default CurrentUserProvider.NO_OP the engine documents that the host MUST enforce authorisation at its own API boundary; nothing changes for legacy wiring.

R3 SEC P0-3/4/5:装配真实 CurrentUserProvider 时引擎强制按所属人 鉴权读路径;默认 NO_OP 保持向后兼容(由宿主自行在 API 边界鉴权)。

Since:
JDK 25, opencode-base-flow V1.0.5
Author:
Leon Soo
  • Constructor Details

    • DefaultTaskService

      public DefaultTaskService(FlowRepository repo, AssigneeResolver assigneeResolver, ExpressionEvaluator exprEvaluator)
      Convenience constructor wiring all dependencies from the SPIs with a no-op FlowMetrics. 便利构造器:从 SPI 装配全部依赖,默认使用 no-op FlowMetrics。
      Parameters:
      repo - persistence facade — 持久化门面
      assigneeResolver - assignee resolver SPI — 参与者解析 SPI
      exprEvaluator - optional expression evaluator SPI — 可选表达式 SPI
      Since:
      JDK 25, opencode-base-flow V1.0.5
    • DefaultTaskService

      public DefaultTaskService(FlowRepository repo, AssigneeResolver assigneeResolver, ExpressionEvaluator exprEvaluator, FlowMetrics metrics)
      Convenience constructor wiring all dependencies from the SPIs with an explicit FlowMetrics. 便利构造器:从 SPI 装配全部依赖,显式注入 FlowMetrics。
      Parameters:
      repo - persistence facade — 持久化门面
      assigneeResolver - assignee resolver SPI — 参与者解析 SPI
      exprEvaluator - optional expression evaluator SPI — 可选表达式 SPI
      metrics - metrics sink — 指标接收器
      Since:
      JDK 25, opencode-base-flow V1.0.5
    • DefaultTaskService

      public DefaultTaskService(FlowRepository repo, AssigneeResolver assigneeResolver, ExpressionEvaluator exprEvaluator, FlowMetrics metrics, CurrentUserProvider currentUser)
      Full convenience constructor including authn SPI. 完整便利构造器(含认证 SPI)。
      Parameters:
      repo - persistence facade — 持久化门面
      assigneeResolver - assignee resolver SPI — 参与者解析 SPI
      exprEvaluator - optional expression evaluator SPI — 可选表达式 SPI
      metrics - metrics sink — 指标接收器
      currentUser - current-user SPI; CurrentUserProvider.NO_OP disables engine-level read-path authz — 当前用户 SPI;NO_OP 表示由宿主自行鉴权
      Since:
      JDK 25, opencode-base-flow V1.0.5
    • DefaultTaskService

      public DefaultTaskService(FlowRepository repo, ApproveOperation approveOp, VoteOperation voteOp, RejectOperation rejectOp, AddSignOperation addSignOp, WithdrawOperation withdrawOp, TransferOperation transferOp, CirculateOperation circulateOp)
      Test-friendly constructor accepting fully-built operation instances (no-op FlowMetrics). 测试友好构造器:接受外部构造好的 operation(no-op metrics)。
      Parameters:
      repo - persistence facade — 持久化门面
      approveOp - approve operation — 同意操作
      voteOp - vote operation — 投票操作
      rejectOp - reject operation — 驳回操作
      addSignOp - add-sign operation — 加签操作
      withdrawOp - withdraw operation — 撤回操作
      transferOp - transfer operation — 转办操作
      circulateOp - circulate operation — 抄送操作
      Since:
      JDK 25, opencode-base-flow V1.0.5
    • DefaultTaskService

      public DefaultTaskService(FlowRepository repo, ApproveOperation approveOp, VoteOperation voteOp, RejectOperation rejectOp, AddSignOperation addSignOp, WithdrawOperation withdrawOp, TransferOperation transferOp, CirculateOperation circulateOp, FlowMetrics metrics)
      Test-friendly constructor accepting fully-built operation instances with explicit FlowMetrics. 测试友好构造器:接受外部构造好的 operation + 显式 metrics。
      Parameters:
      repo - persistence facade — 持久化门面
      approveOp - approve operation — 同意操作
      voteOp - vote operation — 投票操作
      rejectOp - reject operation — 驳回操作
      addSignOp - add-sign operation — 加签操作
      withdrawOp - withdraw operation — 撤回操作
      transferOp - transfer operation — 转办操作
      circulateOp - circulate operation — 抄送操作
      metrics - metrics sink — 指标接收器
      Since:
      JDK 25, opencode-base-flow V1.0.5
    • DefaultTaskService

      public DefaultTaskService(FlowRepository repo, ApproveOperation approveOp, VoteOperation voteOp, RejectOperation rejectOp, AddSignOperation addSignOp, WithdrawOperation withdrawOp, TransferOperation transferOp, CirculateOperation circulateOp, FlowMetrics metrics, CurrentUserProvider currentUser)
      Full test-friendly constructor including authn SPI. 完整测试构造器(含认证 SPI)。
      Parameters:
      repo - persistence facade — 持久化门面
      approveOp - approve operation — 同意操作
      voteOp - vote operation — 投票操作
      rejectOp - reject operation — 驳回操作
      addSignOp - add-sign operation — 加签操作
      withdrawOp - withdraw operation — 撤回操作
      transferOp - transfer operation — 转办操作
      circulateOp - circulate operation — 抄送操作
      metrics - metrics sink — 指标接收器
      currentUser - current-user SPI — 当前用户 SPI
      Since:
      JDK 25, opencode-base-flow V1.0.5
  • Method Details

    • findTodo

      public List<Task> findTodo(String userId, int page, int size)
      Description copied from interface: TaskService
      Paginated todo query (status = PENDING) for a user. size is capped at 200 (v4 D18). 分页查询用户待办(仅 PENDING)。size 硬上限 200。
      Specified by:
      findTodo in interface TaskService
      Parameters:
      userId - assignee user id — 承接人
      page - zero-based page — 页码(0 起)
      size - page size (≤ 200) — 每页大小(≤ 200)
      Returns:
      tasks on the requested page — 该页任务
    • get

      public Task get(String taskId)
      Description copied from interface: TaskService
      Returns the task by id (or throws TASK_NOT_FOUND). 按 id 返回任务(不存在抛 TASK_NOT_FOUND)。
      Specified by:
      get in interface TaskService
      Parameters:
      taskId - task id — 任务 ID
      Returns:
      task — 任务
    • approve

      public void approve(String taskId, String userId, String comment)
      Description copied from interface: TaskService
      Approve action. 同意。
      Specified by:
      approve in interface TaskService
      Parameters:
      taskId - task id — 任务 ID
      userId - caller user id — 调用者
      comment - comment (nullable) — 文本意见(可空)
    • vote

      public void vote(String taskId, String userId, VoteOpinion opinion, String comment)
      Description copied from interface: TaskService
      Vote action (records vote and marks task DONE). 投票(记录投票并把 task 置为 DONE)。
      Specified by:
      vote in interface TaskService
      Parameters:
      taskId - task id — 任务 ID
      userId - caller user id — 调用者
      opinion - vote opinion — 投票意见
      comment - comment (nullable) — 文本意见(可空)
    • reject

      public void reject(String taskId, String userId, String targetStepId, String comment)
      Description copied from interface: TaskService
      Reject action. 驳回。
      Specified by:
      reject in interface TaskService
      Parameters:
      taskId - task id — 任务 ID
      userId - caller user id — 调用者
      targetStepId - null = previous; "_INITIATOR_" = to-initiator; otherwise a visited step id — null 上一级;"_INITIATOR_" 起草点; 否则指定步骤 id
      comment - comment (nullable) — 文本意见
    • addSign

      public void addSign(String taskId, String userId, List<String> additionalUserIds, String comment)
      Description copied from interface: TaskService
      Add-sign action. Only USER ids accepted (no role / dept). 后加签。仅接受 userId 列表。
      Specified by:
      addSign in interface TaskService
      Parameters:
      taskId - task id — 任务 ID
      userId - caller user id — 调用者
      additionalUserIds - extra user ids — 新增加签人
      comment - comment (nullable) — 文本意见
    • withdraw

      public void withdraw(String instanceId, String initiatorId, String reason)
      Description copied from interface: TaskService
      Withdraw the running instance (initiator only). 撤回运行中的实例(仅发起人)。
      Specified by:
      withdraw in interface TaskService
      Parameters:
      instanceId - instance id — 实例 ID
      initiatorId - initiator user id — 发起人
      reason - reason (nullable) — 理由
    • transfer

      public void transfer(String taskId, String fromUserId, String toUserId, String reason)
      Description copied from interface: TaskService
      Transfer the current task to another user. 转办给他人。
      Specified by:
      transfer in interface TaskService
      Parameters:
      taskId - task id — 任务 ID
      fromUserId - caller user id — 调用者
      toUserId - target user id — 目标 userId
      reason - reason (nullable) — 理由
    • circulate

      public void circulate(String taskId, String fromUserId, List<String> toUserIds, String comment)
      Description copied from interface: TaskService
      Circulate (read-only notification) to additional users. 抄送(仅通知)。
      Specified by:
      circulate in interface TaskService
      Parameters:
      taskId - task id — 任务 ID
      fromUserId - caller user id — 调用者
      toUserIds - notify these users — 被抄送 userId 列表
      comment - comment (nullable) — 文本意见