feat: let initiators withdraw running process instances

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
0264408
2026-09-11 16:39:17 +08:00
co-authored by Cursor
parent 946c9d3c52
commit 87b449e45c
15 changed files with 213 additions and 4 deletions
@@ -24,6 +24,10 @@ public interface OrdoEngine {
return reject(taskId, actor, null);
}
ApprovalTask reject(String taskId, String actor, String comment);
default ProcessInstance withdraw(String instanceId, String actor) {
return withdraw(instanceId, actor, null);
}
ProcessInstance withdraw(String instanceId, String actor, String comment);
Optional<ProcessInstance> findInstance(String instanceId);
Optional<ApprovalTask> findTask(String taskId);
List<ApprovalTask> findTasks(String instanceId);
@@ -1,5 +1,5 @@
package com.jetlumen.ordo.api;
public enum ProcessStatus {
RUNNING, APPROVED, REJECTED
RUNNING, APPROVED, REJECTED, WITHDRAWN
}
@@ -0,0 +1,7 @@
package com.jetlumen.ordo.api.exception;
public final class InstanceAlreadyCompletedException extends OrdoException {
public InstanceAlreadyCompletedException(String instanceId) {
super("instance is already completed: " + instanceId);
}
}
@@ -0,0 +1,7 @@
package com.jetlumen.ordo.api.exception;
public final class InstanceNotFoundException extends OrdoException {
public InstanceNotFoundException(String instanceId) {
super("instance not found: " + instanceId);
}
}
@@ -0,0 +1,7 @@
package com.jetlumen.ordo.api.exception;
public final class UnauthorizedInstanceOperationException extends OrdoException {
public UnauthorizedInstanceOperationException(String instanceId, String actor) {
super("actor '" + actor + "' is not the initiator for instance: " + instanceId);
}
}
@@ -15,4 +15,11 @@ public interface ProcessInstanceRepository {
Optional<ProcessInstance> findById(String instanceId);
boolean existsRunning(String definitionId);
/**
* Completes the instance only if it is still running.
*
* @return true if the update was applied, false if the instance was missing or already terminal
*/
boolean completeIfRunning(ProcessInstance completed);
}