Skip to content

Commit b7b5af1

Browse files
committed
added delete Envelope method
1 parent d1e0cac commit b7b5af1

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

src/main/java/com/docusign/controller/eSignature/examples/EG045ControllerDeleteRestoreEnvelope.java

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919
import javax.servlet.http.HttpServletResponse;
2020
import java.text.MessageFormat;
2121

22-
2322
/**
2423
* Used to delete the envelope and restore it back.
2524
*/
2625
@Controller
2726
@RequestMapping("/eg045")
2827
public class EG045ControllerDeleteRestoreEnvelope extends AbstractEsignatureController {
29-
public static final String RECYCLE_BIN_FOLDER_ID = "recyclebin";
30-
3128
public static final String SENT_ITEMS_FOLDER_NAME = "Sent items";
3229

3330
public static final String EXAMPLE_NUMBER = "/eg045";
@@ -36,7 +33,7 @@ public class EG045ControllerDeleteRestoreEnvelope extends AbstractEsignatureCont
3633

3734
public static final String RESTORE_ENVELOPE_PAGE = "pages/esignature/examples/eg045RestoreEnvelope";
3835

39-
public EG045ControllerDeleteRestoreEnvelope(DSConfiguration config, Session session, User user){
36+
public EG045ControllerDeleteRestoreEnvelope(DSConfiguration config, Session session, User user) {
4037
super(config, "eg045", session, user);
4138
}
4239

@@ -48,26 +45,22 @@ protected void onInitModel(WorkArguments args, ModelMap model) throws Exception
4845

4946
@Override
5047
protected Object doWork(WorkArguments args, ModelMap model,
51-
HttpServletResponse response) throws Exception {
48+
HttpServletResponse response) throws Exception {
5249
String envelopeId = args.getEnvelopeId();
5350
session.setEnvelopeId(envelopeId);
5451

5552
ApiClient apiClient = createApiClient(session.getBasePath(), user.getAccessToken());
5653

57-
DeleteRestoreEnvelopeService.moveEnvelopeToFolder(
54+
DeleteRestoreEnvelopeService.deleteEnvelope(
5855
apiClient,
5956
session.getAccountId(),
60-
envelopeId,
61-
RECYCLE_BIN_FOLDER_ID,
62-
null);
57+
envelopeId);
6358

6459
DoneExample.createDefault(getTextForCodeExampleByApiType().ExampleName)
6560
.withMessage(
66-
MessageFormat.format(
67-
getTextForCodeExampleByApiType().AdditionalPage.get(0).ResultsPageText,
68-
envelopeId
69-
)
70-
)
61+
MessageFormat.format(
62+
getTextForCodeExampleByApiType().AdditionalPage.get(0).ResultsPageText,
63+
envelopeId))
7164
.withRedirect(EXAMPLE_NUMBER + RESTORE_ENVELOPE)
7265
.addToModel(model, config);
7366

@@ -81,8 +74,7 @@ public String getRestoreEnvelope(WorkArguments args, ModelMap model) throws Exce
8174
String envelopeId = session.getEnvelopeId();
8275
String restoreEnvelopeText = MessageFormat.format(
8376
config.getCodeExamplesText().SupportingTexts.HelpingTexts.EnvelopeWillBeRestored,
84-
envelopeId
85-
);
77+
envelopeId);
8678

8779
model.addAttribute("restoreText", restoreEnvelopeText);
8880
model.addAttribute("envelopeId", envelopeId);
@@ -101,14 +93,12 @@ public String postRestoreEnvelope(WorkArguments args, ModelMap model) throws Exc
10193
FoldersResponse availableFolders = DeleteRestoreEnvelopeService.getFolders(apiClient, accountId);
10294
Folder folder = DeleteRestoreEnvelopeService.getFolderIdByName(availableFolders.getFolders(), folderName);
10395

104-
if(folder == null) {
96+
if (folder == null) {
10597
DoneExample.createDefault(getTextForCodeExampleByApiType().ExampleName)
10698
.withMessage(
107-
MessageFormat.format(
108-
getTextForCodeExampleByApiType().AdditionalPage.get(1).ResultsPageText,
109-
folderName
110-
)
111-
)
99+
MessageFormat.format(
100+
getTextForCodeExampleByApiType().AdditionalPage.get(1).ResultsPageText,
101+
folderName))
112102
.withRedirect(EXAMPLE_NUMBER + RESTORE_ENVELOPE)
113103
.addToModel(model, config);
114104

@@ -128,9 +118,7 @@ public String postRestoreEnvelope(WorkArguments args, ModelMap model) throws Exc
128118
getTextForCodeExampleByApiType().ResultsPageText,
129119
envelopeId,
130120
folder.getType(),
131-
folderName
132-
)
133-
)
121+
folderName))
134122
.addToModel(model, config);
135123

136124
return DONE_EXAMPLE_PAGE;

src/main/java/com/docusign/controller/eSignature/services/DeleteRestoreEnvelopeService.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,26 @@
1010
import java.util.List;
1111

1212
public final class DeleteRestoreEnvelopeService {
13+
public static final String RECYCLE_BIN_FOLDER_ID = "recyclebin";
14+
15+
public static FoldersResponse deleteEnvelope(
16+
ApiClient apiClient,
17+
String accountId,
18+
String envelopeId) throws Exception {
19+
FoldersApi foldersApi = new FoldersApi(apiClient);
20+
21+
FoldersRequest foldersRequest = new FoldersRequest();
22+
foldersRequest.setEnvelopeIds(Collections.singletonList(envelopeId));
23+
24+
return foldersApi.moveEnvelopes(accountId, RECYCLE_BIN_FOLDER_ID, foldersRequest);
25+
}
26+
1327
public static FoldersResponse moveEnvelopeToFolder(
14-
ApiClient apiClient,
15-
String accountId,
16-
String envelopeId,
17-
String folderId,
18-
String fromFolderId
19-
) throws Exception {
28+
ApiClient apiClient,
29+
String accountId,
30+
String envelopeId,
31+
String folderId,
32+
String fromFolderId) throws Exception {
2033
FoldersApi foldersApi = new FoldersApi(apiClient);
2134

2235
FoldersRequest foldersRequest = new FoldersRequest();
@@ -27,9 +40,8 @@ public static FoldersResponse moveEnvelopeToFolder(
2740
}
2841

2942
public static FoldersResponse getFolders(
30-
ApiClient apiClient,
31-
String accountId
32-
) throws Exception {
43+
ApiClient apiClient,
44+
String accountId) throws Exception {
3345
FoldersApi foldersApi = new FoldersApi(apiClient);
3446
return foldersApi.callList(accountId);
3547
}

0 commit comments

Comments
 (0)