Skip to content

Commit 336375c

Browse files
Add support for notifying package recipients
1 parent 7e098b0 commit 336375c

File tree

6 files changed

+183
-2
lines changed

6 files changed

+183
-2
lines changed

SendSafelyAPI/src/com/sendsafely/SendSafely.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,23 @@ public PackageURL finalizePackage(String packageId, String keycode) throws Limit
680680
return handler.makeRequest(packageId, keycode);
681681
}
682682

683+
/**
684+
* @description Finalizes the package so it can be delivered to the recipients.
685+
* @param packageId The unique package id of the package to be finalized.
686+
* @param keycode The keycode belonging to the package.
687+
* @param notify A boolean flag indicating whether SendSafely should send the secure link to the package recipients
688+
* @returnType PackageURL
689+
* @return A link to access the package. This link can be sent to the recipients.
690+
* @throws LimitExceededException
691+
* @throws FinalizePackageFailedException
692+
* @throws ApproverRequiredException
693+
*/
694+
public PackageURL finalizePackage(String packageId, String keycode, boolean notify) throws LimitExceededException, FinalizePackageFailedException, ApproverRequiredException {
695+
FinalizePackageHandler handler = (FinalizePackageHandler)HandlerFactory.getInstance(uploadManager, Endpoint.FINALIZE_PACKAGE);
696+
handler.setNotify(notify);
697+
return handler.makeRequest(packageId, keycode);
698+
}
699+
683700
/**
684701
* @description Finalizes the package so it can be delivered to the recipients.
685702
* @param packageId The packageId which is to be finalized.

SendSafelyAPI/src/com/sendsafely/dto/PackageURL.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class PackageURL {
77
private URL secureLink;
88
private String keycode;
99
private boolean needsApproval;
10+
private String notificationStatus = "DISABLED";
1011

1112
/**
1213
* @returnType URL
@@ -54,6 +55,23 @@ public void setNeedsApproval(boolean needsApproval) {
5455
this.needsApproval = needsApproval;
5556
}
5657

58+
/**
59+
* @returnType String
60+
* @description Returns status DISABLED by default, SUCCESS if package email notification sent successfully, otherwise returns error message.
61+
* @return notificationStatus message indicating status of package email notification
62+
*/
63+
public String getNotificationStatus() {
64+
return notificationStatus;
65+
}
66+
67+
/**
68+
* @description Set internally by the API.
69+
* @param notificationStatus the status message indication success or error
70+
*/
71+
public void setNotificationStatus(String notificationStatus) {
72+
this.notificationStatus = notificationStatus;
73+
}
74+
5775

5876

5977
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.sendsafely.dto.request;
2+
3+
import com.sendsafely.enums.GetParam;
4+
import com.sendsafely.enums.HTTPMethod;
5+
import com.sendsafely.json.JsonManager;
6+
7+
public class NotifyPackageRecipientsRequest extends BaseRequest
8+
{
9+
10+
private HTTPMethod method = HTTPMethod.POST;
11+
private String path = "/package/" + GetParam.PACKAGE_ID + "/notify/";
12+
13+
public NotifyPackageRecipientsRequest(JsonManager jsonManager, String keyCode) {
14+
initialize(jsonManager, method, path);
15+
16+
super.setPostParam("keycode", keyCode);
17+
}
18+
19+
public NotifyPackageRecipientsRequest() {
20+
}
21+
22+
public void setPackageId(String packageId)
23+
{
24+
super.setGetParam(GetParam.PACKAGE_ID, packageId);
25+
}
26+
27+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.sendsafely.exceptions;
2+
3+
import java.util.List;
4+
5+
public class NotifyPackageRecipientsException extends Exception
6+
{
7+
private static final long serialVersionUID = 1L;
8+
private List<String> errors;
9+
10+
String error;
11+
12+
public NotifyPackageRecipientsException()
13+
{
14+
super();
15+
error = "unknown";
16+
}
17+
18+
public NotifyPackageRecipientsException(String err){
19+
super(err);
20+
error = err;
21+
}
22+
23+
public NotifyPackageRecipientsException(String err, List<String> errors){
24+
super(err);
25+
error = err;
26+
this.errors = errors;
27+
}
28+
29+
public NotifyPackageRecipientsException(Exception e){
30+
super(e);
31+
error = e.getMessage();
32+
}
33+
34+
public String getError()
35+
{
36+
return error;
37+
}
38+
39+
public List<String> getErrors()
40+
{
41+
return errors;
42+
}
43+
44+
}

SendSafelyAPI/src/com/sendsafely/handlers/FinalizePackageHandler.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.IOException;
44
import java.net.MalformedURLException;
55
import java.net.URL;
6-
import java.util.ArrayList;
76
import java.util.List;
87

98
import com.sendsafely.Package;
@@ -23,6 +22,7 @@ public class FinalizePackageHandler extends BaseHandler
2322
{
2423

2524
private FinalizePackageRequest request;
25+
private boolean notify = false;
2626

2727
public FinalizePackageHandler(UploadManager uploadManager) {
2828
super(uploadManager);
@@ -77,7 +77,18 @@ protected PackageURL makeRequest(String packageId, String packageCode, String ke
7777

7878
if(response.getResponse() == APIResponse.SUCCESS || response.getResponse() == APIResponse.PACKAGE_NEEDS_APPROVAL)
7979
{
80-
return convert(response, keyCode);
80+
PackageURL packageUrl = convert(response, keyCode);
81+
82+
if (notify) {
83+
try {
84+
notifyPackageRecipients(packageId,keyCode);
85+
packageUrl.setNotificationStatus(APIResponse.SUCCESS.toString());
86+
} catch (NotifyPackageRecipientsException e) {
87+
packageUrl.setNotificationStatus(e.getMessage());
88+
}
89+
}
90+
91+
return packageUrl;
8192
}
8293
else if(response.getResponse() == APIResponse.LIMIT_EXCEEDED)
8394
{
@@ -154,5 +165,24 @@ protected Package convert(CreatePackageResponse obj)
154165
info.setServerSecret(obj.getServerSecret());
155166
return info;
156167
}
168+
169+
protected void notifyPackageRecipients(String packageId, String keycode) throws NotifyPackageRecipientsException {
170+
171+
NotifyPackageRecipientsHandler handler = new NotifyPackageRecipientsHandler(uploadManager,keycode);
172+
173+
try {
174+
handler.makeRequest(packageId);
175+
} catch (NotifyPackageRecipientsException e) {
176+
throw new NotifyPackageRecipientsException(e);
177+
}
178+
}
179+
180+
public boolean isNotify() {
181+
return notify;
182+
}
183+
184+
public void setNotify(boolean notify) {
185+
this.notify = notify;
186+
}
157187

158188
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.sendsafely.handlers;
2+
3+
import java.io.IOException;
4+
5+
import com.sendsafely.dto.request.NotifyPackageRecipientsRequest;
6+
import com.sendsafely.dto.response.BaseResponse;
7+
import com.sendsafely.enums.APIResponse;
8+
import com.sendsafely.exceptions.NotifyPackageRecipientsException;
9+
import com.sendsafely.exceptions.SendFailedException;
10+
import com.sendsafely.upload.UploadManager;
11+
12+
public class NotifyPackageRecipientsHandler extends BaseHandler
13+
{
14+
15+
private NotifyPackageRecipientsRequest request;
16+
17+
public NotifyPackageRecipientsHandler(UploadManager uploadManager, String keycode) {
18+
super(uploadManager);
19+
this.request = new NotifyPackageRecipientsRequest(uploadManager.getJsonManager(),keycode);
20+
}
21+
22+
public BaseResponse makeRequest(String packageId) throws NotifyPackageRecipientsException {
23+
request.setPackageId(packageId);
24+
25+
BaseResponse response = send();
26+
27+
if(response.getResponse() != APIResponse.SUCCESS)
28+
{
29+
throw new NotifyPackageRecipientsException(response.getMessage());
30+
}
31+
32+
return response;
33+
}
34+
35+
protected BaseResponse send() throws NotifyPackageRecipientsException
36+
{
37+
try {
38+
return send(request, new BaseResponse());
39+
} catch (SendFailedException e) {
40+
throw new NotifyPackageRecipientsException(e);
41+
} catch (IOException e) {
42+
throw new NotifyPackageRecipientsException(e);
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)