Skip to content

Commit d9564e2

Browse files
authored
fix: Support creating ongoing Legal Hold policy with start date (#1281)
Closes: SDK-4293
1 parent 8cf8696 commit d9564e2

File tree

5 files changed

+120
-37
lines changed

5 files changed

+120
-37
lines changed

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

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.eclipsesource.json.JsonObject;
1616
import java.text.ParseException;
1717
import java.util.ArrayList;
18+
import java.util.Arrays;
1819
import java.util.Collections;
1920
import java.util.Date;
2021
import java.util.List;
@@ -227,47 +228,43 @@ public void aiExtractStructuredWithFields() throws InterruptedException {
227228
BoxAIAgentExtractStructured agentExtractStructured = (BoxAIAgentExtractStructured) agent;
228229

229230
BoxFile uploadedFile = uploadFileToUniqueFolder(api, "[aiExtractStructuredWithFields] Test File.txt",
230-
"My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar and books.");
231+
"My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar.");
231232

232233
try {
233234
// When a file has been just uploaded, AI service may not be ready to return text response
234235
// and 412 is returned
235236
retry(() -> {
236237
BoxAIExtractStructuredResponse response = BoxAI.extractMetadataStructured(api,
237238
Collections.singletonList(new BoxAIItem(uploadedFile.getID(), BoxAIItem.Type.FILE)),
238-
new ArrayList<BoxAIExtractField>() {{
239-
add(new BoxAIExtractField("firstName"));
240-
add(new BoxAIExtractField("lastName"));
241-
add(new BoxAIExtractField("date",
239+
Arrays.asList(
240+
new BoxAIExtractField("firstName"),
241+
new BoxAIExtractField("lastName"),
242+
new BoxAIExtractField("date",
242243
"Person date of birth",
243244
"Birth date",
244245
"dateOfBirth",
245246
null,
246-
"What is the date of your birth?"));
247-
add(new BoxAIExtractField("float",
247+
"What is the date of your birth?"),
248+
new BoxAIExtractField("float",
248249
"Person age",
249250
"Age",
250251
"age",
251252
null,
252-
"How old are you?"));
253-
add(new BoxAIExtractField("multiSelect",
253+
"How old are you?"),
254+
new BoxAIExtractField("multiSelect",
254255
"Person hobby",
255256
"Hobby",
256257
"hobby",
257-
new ArrayList<BoxAIExtractFieldOption>() {{
258-
add(new BoxAIExtractFieldOption("guitar"));
259-
add(new BoxAIExtractFieldOption("books"));
260-
}},
261-
"What is your hobby?"));
262-
}},
258+
Collections.singletonList(new BoxAIExtractFieldOption("guitar")),
259+
"What is your hobby?")
260+
),
263261
agentExtractStructured);
264262
JsonObject sourceJson = response.getSourceJson();
265263
assertThat(sourceJson.get("firstName").asString(), is(equalTo("John")));
266264
assertThat(sourceJson.get("lastName").asString(), is(equalTo("Doe")));
267265
assertThat(sourceJson.get("dateOfBirth").asString(), is(equalTo("1990-07-04")));
268266
assertThat(sourceJson.get("age").asInt(), is(equalTo(34)));
269267
assertThat(sourceJson.get("hobby").asArray().get(0).asString(), is(equalTo("guitar")));
270-
assertThat(sourceJson.get("hobby").asArray().get(1).asString(), is(equalTo("books")));
271268
}, 2, 2000);
272269
} finally {
273270
deleteFile(uploadedFile);
@@ -281,30 +278,31 @@ public void aiExtractStructuredWithMetadataTemplate() throws InterruptedExceptio
281278
BoxAIAgentExtractStructured agentExtractStructured = (BoxAIAgentExtractStructured) agent;
282279

283280
BoxFile uploadedFile = uploadFileToUniqueFolder(api, "[aiExtractStructuredWithMetadataTemplate] Test File.txt",
284-
"My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar and books.");
285-
String templateKey = "key" + java.util.UUID.randomUUID().toString();
281+
"My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar.");
282+
String templateKey = "key" + java.util.UUID.randomUUID();
286283
MetadataTemplate template = MetadataTemplate.createMetadataTemplate(api,
287284
"enterprise",
288285
templateKey,
289286
templateKey,
290287
false,
291-
new ArrayList<MetadataTemplate.Field>() {{
292-
add(new MetadataTemplate.Field(Json.parse(
288+
Arrays.asList(
289+
new MetadataTemplate.Field(Json.parse(
293290
"{\"key\":\"firstName\",\"displayName\":\"First name\","
294-
+ "\"description\":\"Person first name\",\"type\":\"string\"}").asObject()));
295-
add(new MetadataTemplate.Field(Json.parse(
291+
+ "\"description\":\"Person first name\",\"type\":\"string\"}").asObject()),
292+
new MetadataTemplate.Field(Json.parse(
296293
"{\"key\":\"lastName\",\"displayName\":\"Last name\","
297-
+ "\"description\":\"Person last name\",\"type\":\"string\"}").asObject()));
298-
add(new MetadataTemplate.Field(Json.parse(
294+
+ "\"description\":\"Person last name\",\"type\":\"string\"}").asObject()),
295+
new MetadataTemplate.Field(Json.parse(
299296
"{\"key\":\"dateOfBirth\",\"displayName\":\"Birth date\","
300-
+ "\"description\":\"Person date of birth\",\"type\":\"date\"}").asObject()));
301-
add(new MetadataTemplate.Field(Json.parse(
297+
+ "\"description\":\"Person date of birth\",\"type\":\"date\"}").asObject()),
298+
new MetadataTemplate.Field(Json.parse(
302299
"{\"key\":\"age\",\"displayName\":\"Age\","
303-
+ "\"description\":\"Person age\",\"type\":\"float\"}").asObject()));
304-
add(new MetadataTemplate.Field(Json.parse(
300+
+ "\"description\":\"Person age\",\"type\":\"float\"}").asObject()),
301+
new MetadataTemplate.Field(Json.parse(
305302
"{\"key\":\"hobby\",\"displayName\":\"Hobby\","
306-
+ "\"description\":\"Person hobby\",\"type\":\"multiSelect\"}").asObject()));
307-
}});
303+
+ "\"description\":\"Person hobby\",\"type\":\"multiSelect\","
304+
+ " \"options\":[{\"key\": \"guitar\"}, {\"key\": \"books\"}]}").asObject())
305+
));
308306

309307
try {
310308
// When a file has been just uploaded, AI service may not be ready to return text response
@@ -320,7 +318,6 @@ public void aiExtractStructuredWithMetadataTemplate() throws InterruptedExceptio
320318
assertThat(sourceJson.get("dateOfBirth").asString(), is(equalTo("1990-07-04T00:00:00Z")));
321319
assertThat(sourceJson.get("age").asInt(), is(equalTo(34)));
322320
assertThat(sourceJson.get("hobby").asArray().get(0).asString(), is(equalTo("guitar")));
323-
assertThat(sourceJson.get("hobby").asArray().get(1).asString(), is(equalTo("books")));
324321
}, 2, 2000);
325322
} finally {
326323
deleteFile(uploadedFile);

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/BoxAITest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.text.ParseException;
1313
import java.util.ArrayList;
14+
import java.util.Arrays;
1415
import java.util.Collections;
1516
import java.util.Date;
1617
import java.util.List;
@@ -364,10 +365,10 @@ public void testExtractMetadataStructuredWithFieldSuccess() {
364365
"The name of the file",
365366
"Name",
366367
"name",
367-
new ArrayList<BoxAIExtractFieldOption>() {{
368-
add(new BoxAIExtractFieldOption("option 1"));
369-
add(new BoxAIExtractFieldOption("option 2"));
370-
}},
368+
Arrays.asList(
369+
new BoxAIExtractFieldOption("option 1"),
370+
new BoxAIExtractFieldOption("option 2")
371+
),
371372
"What is the name of the file?");
372373

373374
final JsonObject expectedRequestBody = new JsonObject()

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)