Skip to content

Commit 7caed56

Browse files
authored
Merge pull request #167 from docusign/maestro-code-examples
Added custom error to cancel instance code example
2 parents 9e7dc1f + be13115 commit 7caed56

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
@@ -14,4 +14,13 @@ public static CancelWorkflowInstanceResponse CancelMaestroWorkflowInstance(
1414
.cancelWorkflowInstance(accountId, workflowId, instanceId);
1515
}
1616
//ds-snippet-end:Maestro4Step3
17+
18+
public static GetWorkflowInstanceResponse GetWorkflowInstanceStatus(
19+
IamClient client,
20+
String accountId,
21+
String workflowId,
22+
String instanceId) throws Exception {
23+
return client.maestro().workflowInstanceManagement()
24+
.getWorkflowInstance(accountId, workflowId, instanceId);
25+
}
1726
}

0 commit comments

Comments
 (0)