Skip to content

Commit 7559a3e

Browse files
Merge pull request #10 from SendSafely/v3.1.2
v3.1.2
2 parents 31e99ec + 336375c commit 7559a3e

11 files changed

+214
-5
lines changed

SendSafelyAPI/src/com/sendsafely/SendSafely.java

+17
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

+18
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
}
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+
}

SendSafelyAPI/src/com/sendsafely/dto/response/PackageInformationResponse.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.sendsafely.dto.response;
22

3+
import java.util.Date;
34
import java.util.List;
45

56
import com.sendsafely.ContactGroup;
@@ -24,6 +25,8 @@ public class PackageInformationResponse extends BaseResponse {
2425
private String label;
2526
private boolean isVDR;
2627
private String rootDirectoryId;
28+
private Date packageTimestamp;
29+
private String packageSender;
2730

2831
public List<RecipientResponse> getRecipients() {
2932
return recipients;
@@ -128,6 +131,18 @@ public String getRootDirectoryId() {
128131
public void setRootDirectoryId(String rootDirectoryId) {
129132
this.rootDirectoryId = rootDirectoryId;
130133
}
134+
public Date getPackageTimestamp() {
135+
return packageTimestamp;
136+
}
137+
public void setPackageTimestamp(Date packageTimestamp) {
138+
this.packageTimestamp = packageTimestamp;
139+
}
140+
public String getPackageSender() {
141+
return packageSender;
142+
}
143+
public void setPackageSender(String packageSender) {
144+
this.packageSender = packageSender;
145+
}
131146

132147

133148

SendSafelyAPI/src/com/sendsafely/dto/response/PackageListResponse.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public class PackageListResponse extends BaseResponse {
1919
private PackageState state;
2020
private int packageState;
2121
private int life;
22-
private String description;
22+
private String packageLabel;
23+
private boolean packageIsVdr;
2324
private String packageUserName;
2425
private Date packageUpdateTimestamp;
2526

@@ -84,10 +85,16 @@ public void setLife(int life) {
8485
this.life = life;
8586
}
8687
public String getDescription() {
87-
return description;
88+
return packageLabel;
8889
}
8990
public void setDescription(String description) {
90-
this.description = description;
91+
this.packageLabel = description;
92+
}
93+
public boolean getIsWorkspace() {
94+
return packageIsVdr;
95+
}
96+
public void setIsWorkspace(boolean isWorkspace) {
97+
this.packageIsVdr = isWorkspace;
9198
}
9299
public String getPackageUserName() {
93100
return packageUserName;
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

+32-2
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
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ protected PackageReference convert(PackageListResponse obj) {
7979
info.setStatus(convert(obj.getPackageState()));
8080
info.setPackageOwner(obj.getPackageUserName());
8181
info.setPackageTimestamp(obj.getPackageUpdateTimestamp());
82+
info.setPackageDescriptor(obj.getDescription());
83+
info.setIsWorkspace(obj.getIsWorkspace());
8284
return info;
8385
}
8486

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

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ protected PackageReference convert(PackageListResponse obj) {
6666
info.setContactGroupNames(obj.getContactGroups());
6767
info.setServerSecret(obj.getServerSecret());
6868
info.setState(obj.getState());
69+
info.setPackageTimestamp(obj.getPackageUpdateTimestamp());
70+
info.setPackageOwner(obj.getPackageUserName());
6971

7072
return info;
7173
}
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+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ protected Package convert(PackageInformationResponse obj)
8686
info.setRootDirectoryId(obj.getRootDirectoryId());
8787
info.setPackageDescriptor(obj.getLabel());
8888
info.setIsWorkspace(obj.isVDR());
89+
info.setPackageTimestamp(obj.getPackageTimestamp());
90+
info.setPackageOwner(obj.getPackageSender());
8991
return info;
9092
}
9193

0 commit comments

Comments
 (0)