Skip to content

Commit f560db8

Browse files
authored
feat: Add signer_group_id for signer in sign request (#1220)
Closes: SDK-3518
1 parent 4e31abb commit f560db8

7 files changed

Lines changed: 145 additions & 4 deletions

File tree

src/intTest/java/com/box/sdk/BoxCollaborationAllowlistIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static com.box.sdk.BoxApiProvider.jwtApiForServiceAccount;
44
import static com.box.sdk.CleanupTools.removeAllowedDomains;
5+
import static com.box.sdk.UniqueTestFolder.randomizeName;
56
import static org.hamcrest.MatcherAssert.assertThat;
67
import static org.hamcrest.Matchers.is;
78
import static org.hamcrest.Matchers.not;
@@ -15,7 +16,7 @@
1516
import org.junit.Test;
1617

1718
public class BoxCollaborationAllowlistIT {
18-
private static final String DOMAIN_NAME = "test14.com";
19+
private static final String DOMAIN_NAME = randomizeName("test") + ".com";
1920

2021
@Before
2122
public void beforeClass() {

src/intTest/java/com/box/sdk/BoxRetentionPolicyAssignmentIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void attachPolicyToFileAndGetFilesUnderRetentionAndDeleteAttachment() thr
7575
.filter(f -> f.getID().equals(boxFile.getID()))
7676
.collect(Collectors.toList());
7777
assertTrue(matchingFileWithRetention2.isEmpty());
78-
}, 3, 1000);
78+
}, 5, 2000);
7979
} finally {
8080
//cleanup
8181
deleteFolder(folder.getResource());
@@ -123,7 +123,7 @@ public void attachPolicyToFileAndGetFileVersionsUnderRetentionAndDeleteAttachmen
123123
.filter(f -> f.getID().equals(boxFile.getID()))
124124
.collect(Collectors.toList());
125125
assertTrue(matchingFileWithRetention2.isEmpty());
126-
}, 3, 1000);
126+
}, 5, 2000);
127127
} finally {
128128
//cleanup
129129
deleteFolder(folder);

src/intTest/java/com/box/sdk/BoxSignRequestIT.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
import static com.box.sdk.BoxApiProvider.jwtApiForServiceAccount;
44
import static com.box.sdk.CleanupTools.deleteFile;
55
import static com.box.sdk.CleanupTools.deleteFolder;
6+
import static com.box.sdk.CleanupTools.deleteUser;
67
import static com.box.sdk.Retry.retry;
78
import static com.box.sdk.UniqueTestFolder.getUniqueFolder;
9+
import static com.box.sdk.UniqueTestFolder.randomizeName;
810
import static com.box.sdk.UniqueTestFolder.removeUniqueFolder;
911
import static com.box.sdk.UniqueTestFolder.setupUniqeFolder;
1012
import static com.box.sdk.UniqueTestFolder.uploadSampleFileToUniqueFolder;
1113
import static java.time.ZoneOffset.UTC;
1214
import static org.junit.Assert.assertEquals;
15+
import static org.junit.Assert.assertNotEquals;
1316
import static org.junit.Assert.assertNotNull;
1417
import static org.junit.Assert.assertTrue;
1518

1619
import java.time.Instant;
1720
import java.time.LocalDateTime;
1821
import java.util.ArrayList;
22+
import java.util.Collections;
1923
import java.util.Date;
2024
import java.util.List;
2125
import java.util.concurrent.atomic.AtomicReference;
@@ -146,5 +150,79 @@ public void createListAndCancelSignRequest() throws InterruptedException {
146150
deleteFolder(signedFileFolder);
147151
}
148152
}
153+
154+
@Test
155+
public void createignRequestForGroup() throws InterruptedException {
156+
// Test Setup
157+
BoxAPIConnection api = jwtApiForServiceAccount();
158+
BoxFolder uniqueFolder = getUniqueFolder(api);
159+
BoxFile file = null;
160+
BoxFolder signedFileFolder = null;
161+
BoxUser groupMemberUser1 = null;
162+
BoxUser groupMemberUser2 = null;
163+
String userName1 = randomizeName("login1") + "@boz.com";
164+
String userName2 = randomizeName("login2") + "@boz.com";
165+
AtomicReference<BoxSignRequest.Info> signRequestInfoCancel = new AtomicReference<>();
166+
String signerGroupName = randomizeName("GroupName");
167+
168+
try {
169+
groupMemberUser1 = BoxUser.createEnterpriseUser(api, userName1, "userName1").getResource();
170+
groupMemberUser2 = BoxUser.createEnterpriseUser(api, userName2, "userName2").getResource();
171+
172+
file = uploadSampleFileToUniqueFolder(api, "file_to_sign.pdf");
173+
List<BoxSignRequestFile> files = Collections.singletonList(new BoxSignRequestFile(file.getID()));
174+
175+
List<BoxSignRequestSigner> signers = new ArrayList<>();
176+
signers.add(new BoxSignRequestSigner(userName1).setSignerGroupId(signerGroupName));
177+
signers.add(new BoxSignRequestSigner(userName2).setSignerGroupId(signerGroupName));
178+
179+
signedFileFolder = uniqueFolder.createFolder("Folder - signRequestGroupIntegrationTest").getResource();
180+
181+
// Do Create
182+
BoxSignRequest.Info signRequestInfoCreate = BoxSignRequest
183+
.createSignRequest(api, files, signers, signedFileFolder.getID());
184+
185+
String signRequestIdCreate = signRequestInfoCreate.getID();
186+
List<BoxSignRequestSigner> createdSigners = signRequestInfoCreate.getSigners();
187+
BoxSignRequestSigner createdSigner1 = createdSigners.get(1);
188+
BoxSignRequestSigner createdSigner2 = createdSigners.get(2);
189+
190+
// Test Create
191+
assertNotNull(signRequestInfoCreate.getID());
192+
assertEquals(createdSigners.size(), 3);
193+
assertEquals(createdSigner1.getSignerGroupId(), createdSigner2.getSignerGroupId());
194+
assertNotEquals(createdSigner1.getSignerGroupId(), signerGroupName);
195+
196+
// Do Get by ID
197+
BoxSignRequest signRequestGetByID = new BoxSignRequest(api, signRequestIdCreate);
198+
199+
List<BoxSignRequestSigner> signersGet = signRequestGetByID.getInfo().getSigners();
200+
BoxSignRequestSigner signer1Get = signersGet.get(1);
201+
BoxSignRequestSigner signer2Get = createdSigners.get(2);
202+
203+
// Test Get
204+
assertNotNull(signRequestInfoCreate.getID());
205+
assertEquals(signersGet.size(), 3);
206+
assertEquals(signer1Get.getSignerGroupId(), signer2Get.getSignerGroupId());
207+
assertEquals(signer1Get.getSignerGroupId(), createdSigner1.getSignerGroupId());
208+
209+
retry(() -> signRequestInfoCancel.set(signRequestGetByID.cancel()), 5, 1000);
210+
211+
} finally {
212+
deleteUser(groupMemberUser1);
213+
deleteUser(groupMemberUser2);
214+
215+
if (signRequestInfoCancel.get() != null) {
216+
// Clean up
217+
List<BoxFile.Info> signRequestFiles = signRequestInfoCancel.get().getSignFiles().getFiles();
218+
for (BoxFile.Info signRequestFile : signRequestFiles) {
219+
BoxFile fileToDelete = new BoxFile(api, signRequestFile.getID());
220+
fileToDelete.delete();
221+
}
222+
}
223+
deleteFile(file);
224+
deleteFolder(signedFileFolder);
225+
}
226+
}
149227
}
150228

src/intTest/java/com/box/sdk/BoxUserIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class BoxUserIT {
4242
public static void cleanup() {
4343
BoxAPIConnection api = jwtApiForServiceAccount();
4444
for (BoxUser.Info user : BoxUser.getAllEnterpriseUsers(api, NEW_USER_LOGIN)) {
45-
user.getResource().delete(false, false);
45+
user.getResource().delete(false, true);
4646
}
4747
Logger.getLogger(OkHttpClient.class.getName()).setLevel(Level.FINE);
4848
}

src/intTest/java/com/box/sdk/CleanupTools.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@ static void deleteGroup(BoxGroup group) {
4141
group.delete();
4242
}
4343
}
44+
45+
static void deleteUser(BoxUser user) {
46+
if (user != null) {
47+
user.delete(false, false);
48+
}
49+
}
4450
}

src/main/java/com/box/sdk/BoxSignRequestSigner.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class BoxSignRequestSigner extends BoxJSONObject {
2626
private String redirectUrl;
2727
private String declinedRedirectUrl;
2828
private String iframeableEmedUrl;
29+
private String signerGroupId;
2930
private BoxAPIConnection api;
3031

3132
/**
@@ -272,6 +273,28 @@ public BoxSignRequestSigner setIframeableEmedUrl(String iframeableEmedUrl) {
272273
return this;
273274
}
274275

276+
/**
277+
* Gets the signer group id. It is sufficient for only one signer from the group to sign the document.
278+
*
279+
* @return id of the group to which the sign request will be sent.
280+
*/
281+
public String getSignerGroupId() {
282+
return this.signerGroupId;
283+
}
284+
285+
/**
286+
* Sets the group id. If specified, signers sharing the same group ID will be assigned to the same input.
287+
* The group ID can be any string value, but it must be consistent across all signers.
288+
* It is sufficient for only one signer from the group to sign the document.
289+
*
290+
* @param signerGroupId id of the group to which the sign request will be sent
291+
* @return this BoxSignRequestSigner object for chaining.
292+
*/
293+
public BoxSignRequestSigner setSignerGroupId(String signerGroupId) {
294+
this.signerGroupId = signerGroupId;
295+
return this;
296+
}
297+
275298
/**
276299
* {@inheritDoc}
277300
*/
@@ -326,6 +349,9 @@ void parseJSONMember(JsonObject.Member member) {
326349
case "iframeable_embed_url":
327350
this.iframeableEmedUrl = value.asString();
328351
break;
352+
case "signer_group_id":
353+
this.signerGroupId = value.asString();
354+
break;
329355
default:
330356
return;
331357
}
@@ -348,6 +374,7 @@ public JsonObject getJSONObject() {
348374
JsonUtils.addIfNotNull(jsonObj, "embed_url_external_user_id", this.embedUrlExternalUserId);
349375
JsonUtils.addIfNotNull(jsonObj, "redirect_url", this.redirectUrl);
350376
JsonUtils.addIfNotNull(jsonObj, "declined_redirect_url", this.declinedRedirectUrl);
377+
JsonUtils.addIfNotNull(jsonObj, "signer_group_id", this.signerGroupId);
351378
return jsonObj;
352379
}
353380

src/main/java/com/box/sdk/BoxSignTemplateSigner.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class BoxSignTemplateSigner extends BoxJSONObject {
1818
private Boolean isInPerson;
1919
private int order;
2020
private BoxSignRequestSignerRole role;
21+
private String signerGroupId;
2122
private BoxAPIConnection api;
2223

2324
/**
@@ -31,11 +32,27 @@ public class BoxSignTemplateSigner extends BoxJSONObject {
3132
*/
3233
public BoxSignTemplateSigner(String email, List<BoxSignTemplateSignerInput> inputs, Boolean isInPerson,
3334
int order, BoxSignRequestSignerRole role) {
35+
this(email, inputs, isInPerson, order, role, null);
36+
}
37+
38+
/**
39+
* Constructs a BoxSignTemplateSigner object with the provided information.
40+
*
41+
* @param email the email.
42+
* @param inputs the inputs.
43+
* @param isInPerson whether the signer is in person or not.
44+
* @param order the order.
45+
* @param role the role.
46+
* @param signerGroupId the signer group id.
47+
*/
48+
public BoxSignTemplateSigner(String email, List<BoxSignTemplateSignerInput> inputs, Boolean isInPerson,
49+
int order, BoxSignRequestSignerRole role, String signerGroupId) {
3450
this.email = email;
3551
this.inputs = inputs;
3652
this.isInPerson = isInPerson;
3753
this.order = order;
3854
this.role = role;
55+
this.signerGroupId = signerGroupId;
3956
}
4057

4158
/**
@@ -94,6 +111,15 @@ public BoxSignRequestSignerRole getRole() {
94111
return this.role;
95112
}
96113

114+
/**
115+
* Gets the signer group id. It is sufficient for only one signer from the group to sign the document.
116+
*
117+
* @return the id of the group signer.
118+
*/
119+
public String getSignerGroupId() {
120+
return this.signerGroupId;
121+
}
122+
97123
/**
98124
* {@inheritDoc}
99125
*/
@@ -121,6 +147,9 @@ void parseJSONMember(JsonObject.Member member) {
121147
case "role":
122148
this.role = BoxSignRequestSignerRole.fromJSONString(value.asString());
123149
break;
150+
case "signer_group_id":
151+
this.signerGroupId = value.asString();
152+
break;
124153
default:
125154
return;
126155
}

0 commit comments

Comments
 (0)