Skip to content

Commit fb9a2ca

Browse files
committed
Added check of instance status before running example 4
1 parent 9d0e50d commit fb9a2ca

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/main/java/com/docusign/controller/maestro/examples/Mae004CancelWorkflowInstanceController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
@Controller
1919
@RequestMapping("/mae004")
2020
public class Mae004CancelWorkflowInstanceController extends AbstractMaestroController {
21+
public static final String IN_PROGRESS = "In Progress";
22+
2123
private static final String MODEL_IS_WORKFLOW_ID_PRESENT = "isWorkflowIdPresent";
2224

2325
public static final String NO_WORKFLOW_INSTANCE_AVAILABLE_TO_CANCEL = "No workflow instance available to cancel.";
@@ -48,6 +50,15 @@ protected Object doWork(
4850
throw new IllegalStateException(NO_WORKFLOW_INSTANCE_AVAILABLE_TO_CANCEL);
4951
}
5052

53+
var workflowInstance = CancelWorkflowInstanceService.GetWorkflowInstanceStatus(client,
54+
accountId,
55+
workflowId,
56+
instanceId);
57+
58+
if(!workflowInstance.workflowInstance().get().workflowStatus().get().equals(IN_PROGRESS)) {
59+
throw new IllegalStateException(getTextForCodeExampleByApiType().CustomErrorTexts.get(2).ErrorMessage);
60+
}
61+
5162
var paused = CancelWorkflowInstanceService.CancelMaestroWorkflowInstance(
5263
client,
5364
accountId,

src/main/java/com/docusign/controller/maestro/services/CancelWorkflowInstanceService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ public static CancelWorkflowInstanceResponse CancelMaestroWorkflowInstance(
1212
return client.maestro().workflowInstanceManagement()
1313
.cancelWorkflowInstance(accountId, workflowId, instanceId);
1414
}
15+
16+
public static GetWorkflowInstanceResponse GetWorkflowInstanceStatus(
17+
IamClient client,
18+
String accountId,
19+
String workflowId,
20+
String instanceId) throws Exception {
21+
return client.maestro().workflowInstanceManagement()
22+
.getWorkflowInstance(accountId, workflowId, instanceId);
23+
}
1524
}

0 commit comments

Comments
 (0)