Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/main/java/com/box/sdk/BoxLegalHoldPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,33 @@ public static BoxLegalHoldPolicy.Info create(BoxAPIConnection api, String name,
* @return information about the Legal Hold Policy created.
*/
public static BoxLegalHoldPolicy.Info createOngoing(BoxAPIConnection api, String name, String description) {
return createOngoing(api, name, description, null);
}


/**
* Creates a new ongoing Legal Hold Policy.
*
* @param api the API connection to be used by the resource.
* @param name the name of Legal Hold Policy.
* @param description the description of Legal Hold Policy.
* @param filterStartedAt optional date filter applies to Custodian assignments only.
* @return information about the Legal Hold Policy created.
*/
public static BoxLegalHoldPolicy.Info createOngoing(
BoxAPIConnection api, String name, String description, Date filterStartedAt
) {
URL url = ALL_LEGAL_HOLD_URL_TEMPLATE.build(api.getBaseURL());
BoxJSONRequest request = new BoxJSONRequest(api, url, "POST");
JsonObject requestJSON = new JsonObject()
.add("policy_name", name)
.add("is_ongoing", true);
.add("policy_name", name)
.add("is_ongoing", true);
if (description != null) {
requestJSON.add("description", description);
}
if (filterStartedAt != null) {
requestJSON.add("filter_started_at", BoxDateFormat.format(filterStartedAt));
}
request.setBody(requestJSON.toString());
try (BoxJSONResponse response = request.send()) {
JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "legal_hold_policy",
"id": "11111",
"policy_name": "Trial Documents",
"description": "This is a description.",
"status": "active",
"assignment_counts": {
"user": 0,
"folder": 0,
"file": 0,
"file_version": 0
},
"is_ongoing": true,
"created_by": {
"type": "user",
"id": "33333",
"name": "Test User",
"login": "[email protected]"
},
"created_at": "2018-04-25T16:37:05-07:00",
"modified_at": "2018-04-25T16:37:05-07:00",
"deleted_at": null,
"filter_started_at": "2018-04-25T16:37:05-07:00",
"filter_ended_at": null
}
41 changes: 41 additions & 0 deletions src/test/java/com/box/sdk/BoxLegalHoldPolicyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,47 @@ public void testCreateOngoingNewLegalHoldPolicySucceedsAndSendsCorrectJson() {
Assert.assertTrue(policyInfo.getIsOngoing());
}

@Test
public void testCreateOngoingWithStartDateNewLegalHoldPolicySucceedsAndSendsCorrectJson() throws ParseException {
final String legalHoldsURL = "/2.0/legal_hold_policies";
final String policyID = "11111";
final String createdByID = "33333";
final String createdByName = "Test User";
final String createdByLogin = "[email protected]";
final String policyName = "Trial Documents";
final String description = "This is a description.";
final String startTimeString = "2018-04-25T23:37:05Z";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
final Date startTime = dateFormat.parse("2018-04-25T16:37:05-07:00");

JsonObject policyObject = new JsonObject()
.add("policy_name", policyName)
.add("is_ongoing", true)
.add("description", description)
.add("filter_started_at", startTimeString);

String result = TestUtils.getFixture("BoxLegalHold/PostOngoingWithStartDateLegalHoldPolicies201");

wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(legalHoldsURL))
.withRequestBody(WireMock.equalToJson(policyObject.toString()))
.willReturn(WireMock.aResponse()
.withHeader("Content-Type", APPLICATION_JSON)
.withBody(result)));

BoxLegalHoldPolicy.Info policyInfo = BoxLegalHoldPolicy.createOngoing(
this.api, policyName, description, startTime
);

Assert.assertEquals(policyID, policyInfo.getID());
Assert.assertEquals(createdByID, policyInfo.getCreatedBy().getID());
Assert.assertEquals(createdByName, policyInfo.getCreatedBy().getName());
Assert.assertEquals(createdByLogin, policyInfo.getCreatedBy().getLogin());
Assert.assertEquals(policyName, policyInfo.getPolicyName());
Assert.assertEquals(description, policyInfo.getDescription());
Assert.assertEquals(startTime, policyInfo.getFilterStartedAt());
Assert.assertTrue(policyInfo.getIsOngoing());
}


@Test
public void testUpdateLegalHoldPolicySucceedsAndSendsCorrectJson() {
Expand Down
Loading