Skip to content

Commit 2d2cf85

Browse files
committed
fix: Support creating ongoing Legal Hold policy with start date
Closes: SDK-4293
1 parent fc1a3e3 commit 2d2cf85

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,33 @@ public static BoxLegalHoldPolicy.Info create(BoxAPIConnection api, String name,
101101
* @return information about the Legal Hold Policy created.
102102
*/
103103
public static BoxLegalHoldPolicy.Info createOngoing(BoxAPIConnection api, String name, String description) {
104+
return createOngoing(api, name, description, null);
105+
}
106+
107+
108+
/**
109+
* Creates a new ongoing Legal Hold Policy.
110+
*
111+
* @param api the API connection to be used by the resource.
112+
* @param name the name of Legal Hold Policy.
113+
* @param description the description of Legal Hold Policy.
114+
* @param filterStartedAt optional date filter applies to Custodian assignments only.
115+
* @return information about the Legal Hold Policy created.
116+
*/
117+
public static BoxLegalHoldPolicy.Info createOngoing(
118+
BoxAPIConnection api, String name, String description, Date filterStartedAt
119+
) {
104120
URL url = ALL_LEGAL_HOLD_URL_TEMPLATE.build(api.getBaseURL());
105121
BoxJSONRequest request = new BoxJSONRequest(api, url, "POST");
106122
JsonObject requestJSON = new JsonObject()
107-
.add("policy_name", name)
108-
.add("is_ongoing", true);
123+
.add("policy_name", name)
124+
.add("is_ongoing", true);
109125
if (description != null) {
110126
requestJSON.add("description", description);
111127
}
128+
if (filterStartedAt != null) {
129+
requestJSON.add("filter_started_at", BoxDateFormat.format(filterStartedAt));
130+
}
112131
request.setBody(requestJSON.toString());
113132
try (BoxJSONResponse response = request.send()) {
114133
JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"type": "legal_hold_policy",
3+
"id": "11111",
4+
"policy_name": "Trial Documents",
5+
"description": "This is a description.",
6+
"status": "active",
7+
"assignment_counts": {
8+
"user": 0,
9+
"folder": 0,
10+
"file": 0,
11+
"file_version": 0
12+
},
13+
"is_ongoing": true,
14+
"created_by": {
15+
"type": "user",
16+
"id": "33333",
17+
"name": "Test User",
18+
"login": "[email protected]"
19+
},
20+
"created_at": "2018-04-25T16:37:05-07:00",
21+
"modified_at": "2018-04-25T16:37:05-07:00",
22+
"deleted_at": null,
23+
"filter_started_at": "2018-04-25T16:37:05-07:00",
24+
"filter_ended_at": null
25+
}

src/test/java/com/box/sdk/BoxLegalHoldPolicyTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,47 @@ public void testCreateOngoingNewLegalHoldPolicySucceedsAndSendsCorrectJson() {
189189
Assert.assertTrue(policyInfo.getIsOngoing());
190190
}
191191

192+
@Test
193+
public void testCreateOngoingWithSTartDateNewLegalHoldPolicySucceedsAndSendsCorrectJson() throws ParseException {
194+
final String legalHoldsURL = "/2.0/legal_hold_policies";
195+
final String policyID = "11111";
196+
final String createdByID = "33333";
197+
final String createdByName = "Test User";
198+
final String createdByLogin = "[email protected]";
199+
final String policyName = "Trial Documents";
200+
final String description = "This is a description.";
201+
final String startTimeString = "2018-04-25T23:37:05Z";
202+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
203+
final Date startTime = dateFormat.parse("2018-04-25T16:37:05-07:00");
204+
205+
JsonObject policyObject = new JsonObject()
206+
.add("policy_name", policyName)
207+
.add("is_ongoing", true)
208+
.add("description", description)
209+
.add("filter_started_at", startTimeString);
210+
211+
String result = TestUtils.getFixture("BoxLegalHold/PostOngoingWithStartDateLegalHoldPolicies201");
212+
213+
wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(legalHoldsURL))
214+
.withRequestBody(WireMock.equalToJson(policyObject.toString()))
215+
.willReturn(WireMock.aResponse()
216+
.withHeader("Content-Type", APPLICATION_JSON)
217+
.withBody(result)));
218+
219+
BoxLegalHoldPolicy.Info policyInfo = BoxLegalHoldPolicy.createOngoing(
220+
this.api, policyName, description, startTime
221+
);
222+
223+
Assert.assertEquals(policyID, policyInfo.getID());
224+
Assert.assertEquals(createdByID, policyInfo.getCreatedBy().getID());
225+
Assert.assertEquals(createdByName, policyInfo.getCreatedBy().getName());
226+
Assert.assertEquals(createdByLogin, policyInfo.getCreatedBy().getLogin());
227+
Assert.assertEquals(policyName, policyInfo.getPolicyName());
228+
Assert.assertEquals(description, policyInfo.getDescription());
229+
Assert.assertEquals(startTime, policyInfo.getFilterStartedAt());
230+
Assert.assertTrue(policyInfo.getIsOngoing());
231+
}
232+
192233

193234
@Test
194235
public void testUpdateLegalHoldPolicySucceedsAndSendsCorrectJson() {

0 commit comments

Comments
 (0)