Skip to content

Commit e899c7b

Browse files
BRIAN HOLYFIELDBRIAN HOLYFIELD
authored andcommitted
Updates for Release v2.1
Adds support for User Contact Groups Adds isAdmin flag in UserInformation class Improved Error Handling on Connection Errors
1 parent e12a239 commit e899c7b

File tree

49 files changed

+1491
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1491
-23
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.sendsafely;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collection;
5+
import java.util.HashSet;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
import com.sendsafely.dto.ContactGroupMember;
10+
11+
/**
12+
* A java bean containing the information for a contact group.
13+
* A ContactGroup contains information about a contact group including the following,
14+
* contactGroupId, contactGroupName, ContactGroupUsers, and users.
15+
* Only the Getters should be used from this object, since the server will populate the object.
16+
* Updating the setters will not change any state on the server and should be avoided.
17+
* @author michaelnowak
18+
*
19+
*/
20+
public class ContactGroup {
21+
private String contactGroupId;
22+
private String contactGroupName;
23+
private List<ContactGroupMember> users = new ArrayList<ContactGroupMember>(0);
24+
25+
/**
26+
* @description Get the contact group id
27+
* @return contactGroupId The id representation of the contact group.
28+
*/
29+
public String getContactGroupId() {
30+
return contactGroupId;
31+
}
32+
33+
/**
34+
* @description Set internally by the API
35+
* @param contactGroupId
36+
*/
37+
public void setContactGroupId(String contactGroupId) {
38+
this.contactGroupId = contactGroupId;
39+
}
40+
41+
/**
42+
* @description Get the contact group Name
43+
* @return contactGroupName
44+
*/
45+
public String getContactGroupName() {
46+
return contactGroupName;
47+
}
48+
49+
/**
50+
* @description Set internally by the API
51+
* @param contactGroupName
52+
*/
53+
public void setContactGroupName(String contactGroupName) {
54+
this.contactGroupName = contactGroupName;
55+
}
56+
57+
/**
58+
* @description Get a list of users
59+
* @return List<Map<String,String>> users
60+
*/
61+
public List<ContactGroupMember> getContactGroupMembers() {
62+
return users;
63+
}
64+
65+
/**
66+
* @description Set internally by the API
67+
* @param users
68+
*/
69+
public void setContactGroupMembers(List<ContactGroupMember> users) {
70+
this.users = users;
71+
}
72+
}

SendSafelyAPI/src/com/sendsafely/Package.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class Package extends BasePackage {
1515

1616
private List<Recipient> recipients;
1717

18+
private List<ContactGroup> contactGroups;
1819
/**
1920
* @description Get all recipients that are currently associated with the package
2021
* @returnType Recipient
@@ -31,5 +32,23 @@ public List<Recipient> getRecipients() {
3132
public void setRecipients(List<Recipient> recipients) {
3233
this.recipients = recipients;
3334
}
35+
36+
/**
37+
* @description Set internally by the API.
38+
* @return
39+
*/
40+
public List<ContactGroup> getContactGroups() {
41+
return contactGroups;
42+
}
43+
44+
/**
45+
* @description Set internally by the API.
46+
* @param contactGroups
47+
*/
48+
public void setContactGroups(List<ContactGroup> contactGroups) {
49+
this.contactGroups = contactGroups;
50+
}
51+
52+
3453

3554
}

SendSafelyAPI/src/com/sendsafely/PackageReference.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
public class PackageReference extends BasePackage {
1515

1616
private List<String> recipients;
17+
private List<String> contactGroupNames;
1718

1819
/**
1920
* @description Get all recipients that are currently associated with the package
@@ -32,4 +33,20 @@ public void setRecipients(List<String> recipients) {
3233
this.recipients = recipients;
3334
}
3435

36+
/**
37+
* @description Get all contactGroup names that are currently associated with the package
38+
* @returnType contactGroupName
39+
* @return
40+
*/
41+
public List<String> getContactGroupNames() {
42+
return contactGroupNames;
43+
}
44+
45+
/**
46+
* @description Set internally by the API.
47+
* @param contactGroupNames
48+
*/
49+
public void setContactGroupNames(List<String> contactGroupNames) {
50+
this.contactGroupNames = contactGroupNames;
51+
}
3552
}

SendSafelyAPI/src/com/sendsafely/SendSafely.java

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@
2121
import com.sendsafely.dto.EnterpriseInfo;
2222
import com.sendsafely.dto.PackageURL;
2323
import com.sendsafely.dto.UserInformation;
24+
import com.sendsafely.dto.request.AddContactGroupAsRecipientRequest;
2425
import com.sendsafely.dto.request.AddDropzoneRecipientRequest;
26+
import com.sendsafely.dto.request.AddUserToContactGroupRequest;
2527
import com.sendsafely.dto.request.AddMessageRequest;
2628
import com.sendsafely.dto.request.AddRecipientRequest;
2729
import com.sendsafely.dto.request.AddRecipientsRequest;
30+
import com.sendsafely.dto.request.CreateContactGroupRequest;
2831
import com.sendsafely.dto.request.GetDropzoneRecipientRequest;
2932
import com.sendsafely.dto.request.GetMessageRequest;
33+
import com.sendsafely.dto.request.GetContactGroupsRequest;
34+
import com.sendsafely.dto.request.RemoveContactGroupAsRecipientRequest;
35+
import com.sendsafely.dto.request.RemoveContactGroupRequest;
36+
import com.sendsafely.dto.request.RemoveUserFromContactGroupRequest;
3037
import com.sendsafely.enums.APIResponse;
3138
import com.sendsafely.enums.CountryCode;
3239
import com.sendsafely.enums.Endpoint;
@@ -35,11 +42,18 @@
3542
import com.sendsafely.exceptions.DropzoneRecipientFailedException;
3643
import com.sendsafely.exceptions.PasswordRequiredException;
3744
import com.sendsafely.exceptions.RecipientFailedException;
45+
import com.sendsafely.exceptions.RemoveContactGroupAsRecipientFailedException;
46+
import com.sendsafely.exceptions.RemoveContactGroupFailedException;
47+
import com.sendsafely.exceptions.RemoveEmailContactGroupFailedException;
48+
import com.sendsafely.exceptions.ContactGroupException;
49+
import com.sendsafely.exceptions.AddEmailContactGroupFailedException;
3850
import com.sendsafely.exceptions.ApproverRequiredException;
51+
import com.sendsafely.exceptions.CreateContactGroupFailedException;
3952
import com.sendsafely.exceptions.CreatePackageFailedException;
4053
import com.sendsafely.exceptions.DeletePackageException;
4154
import com.sendsafely.exceptions.EnterpriseInfoFailedException;
4255
import com.sendsafely.exceptions.FinalizePackageFailedException;
56+
import com.sendsafely.exceptions.GetContactGroupsFailedException;
4357
import com.sendsafely.exceptions.GetPackagesException;
4458
import com.sendsafely.exceptions.InvalidCredentialsException;
4559
import com.sendsafely.exceptions.LimitExceededException;
@@ -52,24 +66,31 @@
5266
import com.sendsafely.exceptions.UploadFileException;
5367
import com.sendsafely.exceptions.UserInformationFailedException;
5468
import com.sendsafely.file.FileManager;
69+
import com.sendsafely.handlers.AddContactGroupAsRecipientHandler;
5570
import com.sendsafely.handlers.AddDropzoneRecipientHandler;
71+
import com.sendsafely.handlers.AddUserContactGroupHandler;
5672
import com.sendsafely.handlers.AddFileHandler;
5773
import com.sendsafely.handlers.AddMessageHandler;
5874
import com.sendsafely.handlers.AddRecipientHandler;
5975
import com.sendsafely.handlers.AddRecipientsHandler;
76+
import com.sendsafely.handlers.CreateContactGroupHandler;
6077
import com.sendsafely.handlers.CreatePackageHandler;
6178
import com.sendsafely.handlers.DeletePackageHandler;
6279
import com.sendsafely.handlers.DownloadAndDecryptFileHandler;
6380
import com.sendsafely.handlers.EnterpriseInfoHandler;
6481
import com.sendsafely.handlers.FinalizePackageHandler;
82+
import com.sendsafely.handlers.GetContactGroupsHandler;
6583
import com.sendsafely.handlers.GetDropzoneRecipientHandler;
6684
import com.sendsafely.handlers.GetMessageHandler;
6785
import com.sendsafely.handlers.GetPackagesHandler;
6886
import com.sendsafely.handlers.GetRecipientHandler;
6987
import com.sendsafely.handlers.HandlerFactory;
7088
import com.sendsafely.handlers.PackageInformationHandler;
7189
import com.sendsafely.handlers.ParseLinksHandler;
90+
import com.sendsafely.handlers.RemoveContactGroupAsRecipientHandler;
91+
import com.sendsafely.handlers.RemoveContactGroupHandler;
7292
import com.sendsafely.handlers.RemoveDropzoneRecipientHandler;
93+
import com.sendsafely.handlers.RemoveUserContactGroupHandler;
7394
import com.sendsafely.handlers.RemoveRecipientHandler;
7495
import com.sendsafely.handlers.UpdatePackageLifeHandler;
7596
import com.sendsafely.handlers.UpdateRecipientHandler;
@@ -746,5 +767,101 @@ else if (!response.equals(APIResponse.SUCCESS.toString()))
746767
return defaultCredentials;
747768

748769
}
770+
771+
/**
772+
* API to create a contact group
773+
* Use this to create a new contact group. Will accept a group name. Returned values will include a contact group Id that will be useful
774+
* for other calls against the api.
775+
*
776+
* @param groupName
777+
* @return String of groupId
778+
* @throws CreateContactGroupFailedException
779+
780+
*/
781+
public String createContactGroup(String groupName) throws CreateContactGroupFailedException{
782+
CreateContactGroupHandler handler = new CreateContactGroupHandler(uploadManager, new CreateContactGroupRequest(uploadManager.getJsonManager(), groupName));
783+
return handler.makeRequest();
784+
}
785+
786+
/**
787+
* API to remove a contact group
788+
* Use this to remove a contact group. Will accept a group id. No values will be returned.
789+
* If the api fails, the RemoveContactGroupFailedException will be triggered.
790+
*
791+
* @param groupId
792+
* @throws RemoveContactGroupFailedException
793+
794+
*/
795+
public void deleteContactGroup(String groupId) throws RemoveContactGroupFailedException{
796+
RemoveContactGroupHandler handler = new RemoveContactGroupHandler(uploadManager, new RemoveContactGroupRequest(uploadManager.getJsonManager(), groupId));
797+
handler.makeRequest();
798+
}
799+
800+
/**
801+
* API to add an email address to a contact group
802+
* Use this to add an email address to a contact group. Returns a string of recipient id.
803+
*
804+
* @param groupId
805+
* @param userEmail
806+
* @return
807+
* @throws AddEmailContactGroupFailedException
808+
*/
809+
public String addUserToContactGroup(String groupId, String userEmail) throws AddEmailContactGroupFailedException{
810+
AddUserContactGroupHandler handler = new AddUserContactGroupHandler(uploadManager, new AddUserToContactGroupRequest(uploadManager.getJsonManager(), groupId, userEmail));
811+
return handler.makeRequest();
812+
}
749813

814+
/**
815+
* API to remove an email address from a contact group
816+
* Use this to remove an email address from a contact group. Throws an exception if an error occurred.
817+
*
818+
* @param groupId
819+
* @param userId
820+
* @throws RemoveEmailContactGroupFailedException
821+
822+
*/
823+
public void removeUserFromContactGroup(String groupId, String userId) throws RemoveEmailContactGroupFailedException{
824+
RemoveUserContactGroupHandler handler = new RemoveUserContactGroupHandler(uploadManager, new RemoveUserFromContactGroupRequest(uploadManager.getJsonManager(), groupId, userId));
825+
handler.makeRequest();
826+
}
827+
828+
/**
829+
* API to add a contact group as a recipient on a package
830+
* Use this to add a contact group and all of the email members to a package as complete unit. Throws an exception if the call failed.
831+
*
832+
* @param packageId
833+
* @param groupId
834+
* @throws ContactGroupException
835+
*/
836+
public void addContactGroupToPackage(String packageId, String groupId) throws ContactGroupException{
837+
AddContactGroupAsRecipientHandler handler = new AddContactGroupAsRecipientHandler(uploadManager, new AddContactGroupAsRecipientRequest(uploadManager.getJsonManager(), packageId, groupId));
838+
handler.makeRequest();
839+
}
840+
841+
/**
842+
* API to remove a contact group as a recipient on a package
843+
* Use this to remove a contact group and all of the associated email members from a package as a complete unit.
844+
* Throws an exception if the call failed
845+
*
846+
* @param packageId
847+
* @param groupId
848+
* @throws RemoveContactGroupAsRecipientFailedException
849+
*/
850+
public void removeContactGroupFromPackage(String packageId,String groupId) throws RemoveContactGroupAsRecipientFailedException{
851+
RemoveContactGroupAsRecipientHandler handler = new RemoveContactGroupAsRecipientHandler(uploadManager, new RemoveContactGroupAsRecipientRequest(uploadManager.getJsonManager(), packageId, groupId));
852+
handler.makeRequest();
853+
}
854+
855+
/**
856+
* API to retrieve a list of contact groups, including all email addresses associated with the contact groups
857+
* Use this to get a list of contact groups and emails associated with each contact group. Throws an exception if the call fails
858+
* Returns a list of contact groups with email addresses within each contact group
859+
*
860+
* @return List<ContactGroupDTO> object of contact groups and email addresses
861+
* @throws GetContactGroupsFailedException
862+
*/
863+
public List<ContactGroup> getContactGroups() throws GetContactGroupsFailedException{
864+
GetContactGroupsHandler handler = new GetContactGroupsHandler(uploadManager, new GetContactGroupsRequest(uploadManager.getJsonManager()));
865+
return handler.makeRequest();
866+
}
750867
}

SendSafelyAPI/src/com/sendsafely/connection/ConnectionManager.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.io.InputStream;
55
import java.io.OutputStream;
66
import java.net.URL;
7+
import java.util.List;
8+
import java.util.Map;
79

810
import com.sendsafely.exceptions.SendFailedException;
911

@@ -58,4 +60,32 @@ public interface ConnectionManager {
5860
* @description Get a header from the response.
5961
*/
6062
public String getHeader(String header);
63+
64+
/**
65+
* @description Gets all headers from the response
66+
*/
67+
public Map<String, List<String>> getHeaders();
68+
69+
/**
70+
* @throws IOException
71+
* @description gets response code
72+
*/
73+
public int getResponseCode() throws IOException;
74+
75+
/**
76+
* @throws IOException
77+
* @description gets response message
78+
*/
79+
public String getResponseMessage() throws IOException;
80+
81+
/**
82+
* @description returns the content type
83+
*/
84+
public String getContentType();
85+
86+
/**
87+
* @description Get the server error stream.
88+
*/
89+
public InputStream getErrorStream() throws IOException;
90+
6191
}

SendSafelyAPI/src/com/sendsafely/connection/DefaultConnectionManager.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import java.net.HttpURLConnection;
1111
import java.net.ProtocolException;
1212
import java.net.URL;
13+
import java.util.List;
14+
import java.util.Map;
1315

1416
import com.sendsafely.exceptions.SendFailedException;
1517

@@ -82,5 +84,28 @@ public String getHeader(String header)
8284
{
8385
return conn.getHeaderField(header);
8486
}
87+
88+
@Override
89+
public Map<String,List<String>> getHeaders(){
90+
return conn.getHeaderFields();
91+
}
92+
93+
public int getResponseCode() throws IOException{
94+
return conn.getResponseCode();
95+
}
96+
97+
public String getResponseMessage() throws IOException{
98+
return conn.getResponseMessage();
99+
}
100+
101+
public String getContentType(){
102+
return conn.getContentType();
103+
}
104+
105+
@Override
106+
public InputStream getErrorStream() throws IOException
107+
{
108+
return conn.getErrorStream();
109+
}
85110

86111
}

0 commit comments

Comments
 (0)