Search in sources :

Example 41 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class BoxTermsOfServiceUserStatus method getInfo.

/**
 * Retrieves a list of User Status for Terms of Service as an Iterable.
 *
 * @param api              the API connection to be used by the resource.
 * @param termsOfServiceID the ID of the terms of service.
 * @param userID           the ID of the user to retrieve terms of service for.
 * @return the Iterable of User Status for Terms of Service.
 */
public static List<BoxTermsOfServiceUserStatus.Info> getInfo(final BoxAPIConnection api, String termsOfServiceID, String userID) {
    QueryStringBuilder builder = new QueryStringBuilder();
    builder.appendParam("tos_id", termsOfServiceID);
    if (userID != null) {
        builder.appendParam("user_id", userID);
    }
    URL url = ALL_TERMS_OF_SERVICE_USER_STATUSES_TEMPLATE.buildWithQuery(api.getBaseURL(), builder.toString());
    BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
    int totalCount = responseJSON.get("total_count").asInt();
    List<BoxTermsOfServiceUserStatus.Info> termsOfServiceUserStatuses = new ArrayList<>(totalCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue value : entries) {
        JsonObject termsOfServiceUserStatusJSON = value.asObject();
        BoxTermsOfServiceUserStatus termsOfServiceUserStatus = new BoxTermsOfServiceUserStatus(api, termsOfServiceUserStatusJSON.get("id").asString());
        BoxTermsOfServiceUserStatus.Info info = termsOfServiceUserStatus.new Info(termsOfServiceUserStatusJSON);
        termsOfServiceUserStatuses.add(info);
    }
    return termsOfServiceUserStatuses;
}
Also used : ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL) JsonArray(com.eclipsesource.json.JsonArray)

Example 42 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class BoxFolderTest method testSetClassification.

@Test
public void testSetClassification() throws IOException {
    final String folderID = "12345";
    final String classificationType = "Internal";
    final String metadataURL = "/folders/" + folderID + "/metadata/enterprise/securityClassification-6VMVochwUWo";
    JsonObject metadataObject = new JsonObject().add("op", "replace").add("path", "/Box__Security__Classification__Key").add("value", "Internal");
    JsonArray metadataArray = new JsonArray().add(metadataObject);
    String result = TestConfig.getFixture("BoxFolder/UpdateClassificationOnFolder200");
    wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(metadataURL)).willReturn(WireMock.aResponse().withStatus(409)));
    wireMockRule.stubFor(WireMock.put(WireMock.urlPathEqualTo(metadataURL)).withRequestBody(WireMock.equalToJson(metadataArray.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json-patch+json").withBody(result)));
    BoxFolder folder = new BoxFolder(this.api, folderID);
    String classification = folder.setClassification(classificationType);
    assertEquals(classificationType, classification);
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Example 43 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class BoxFolderTest method testChunkedUploadWithCorrectPartSizeAndAttributes.

@Test
public void testChunkedUploadWithCorrectPartSizeAndAttributes() throws IOException, InterruptedException {
    String javaVersion = System.getProperty("java.version");
    Assume.assumeFalse("Test is not run for JDK 7", javaVersion.contains("1.7"));
    final String preflightURL = "/files/content";
    final String sessionURL = "/files/upload_sessions";
    final String uploadURL = "/files/upload_sessions/D5E3F8ADA11A38F0A66AD0B64AACA658";
    final String commitURL = "/files/upload_sessions/D5E3F8ADA11A38F0A66AD0B64AACA658/commit";
    BoxFileTest.FakeStream stream = new BoxFileTest.FakeStream("aaaaa");
    String sessionResult = TestConfig.getFixture("BoxFile/CreateUploadSession201", wireMockRule.port());
    String uploadResult = TestConfig.getFixture("BoxFile/UploadPartOne200");
    String commitResult = TestConfig.getFixture("BoxFile/CommitUploadWithAttributes201");
    JsonObject idObject = new JsonObject().add("id", "12345");
    JsonObject preflightObject = new JsonObject().add("name", "testfile.txt").add("size", 5).add("parent", idObject);
    JsonObject sessionObject = new JsonObject().add("folder_id", "12345").add("file_size", 5).add("file_name", "testfile.txt");
    JsonObject partOne = new JsonObject().add("part_id", "CFEB5BA9").add("offset", 0).add("size", 5);
    JsonArray parts = new JsonArray().add(partOne);
    Map<String, String> fileAttributes = new HashMap<>();
    fileAttributes.put("content_modified_at", "2017-04-08T00:58:08Z");
    JsonObject fileAttributesJson = new JsonObject();
    for (String attrKey : fileAttributes.keySet()) {
        fileAttributesJson.set(attrKey, fileAttributes.get(attrKey));
    }
    JsonObject commitObject = new JsonObject().add("parts", parts).add("attributes", fileAttributesJson);
    wireMockRule.stubFor(WireMock.options(WireMock.urlPathEqualTo(preflightURL)).withRequestBody(WireMock.equalToJson(preflightObject.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withStatus(200)));
    wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(sessionURL)).withRequestBody(WireMock.equalToJson(sessionObject.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(sessionResult)));
    wireMockRule.stubFor(WireMock.put(WireMock.urlPathEqualTo(uploadURL)).withHeader("Digest", WireMock.containing("sha=31HjfCaaqU04+T5Te/biAgshQGw=")).withHeader("Content-Type", WireMock.containing("application/octet-stream")).withHeader("Content-Range", WireMock.containing("bytes 0-4/5")).withRequestBody(WireMock.equalTo("aaaaa")).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(uploadResult)));
    wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(commitURL)).withHeader("Content-Type", WireMock.equalTo("application/json")).withRequestBody(WireMock.containing(commitObject.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(commitResult)));
    BoxFolder folder = new BoxFolder(this.api, "12345");
    BoxFile.Info uploadedFile = folder.uploadLargeFile(stream, "testfile.txt", 5, fileAttributes);
    assertEquals("1111111", uploadedFile.getID());
    assertEquals("testuser@box.com", uploadedFile.getModifiedBy().getLogin());
    assertEquals("Test User", uploadedFile.getOwnedBy().getName());
    assertEquals("folder", uploadedFile.getParent().getType());
    assertEquals("testfile.txt", uploadedFile.getName());
    assertEquals(1491613088000L, uploadedFile.getContentModifiedAt().getTime());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) HashMap(java.util.HashMap) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Example 44 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class MetadataTest method testRemove.

@Test
public void testRemove() {
    Metadata m = new Metadata().remove("/foo");
    JsonArray operations = Json.parse(m.getPatch()).asArray();
    assertEquals(1, operations.size());
    JsonObject op = operations.get(0).asObject();
    assertEquals("remove", op.get("op").asString());
    assertEquals("/foo", op.get("path").asString());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Example 45 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class MetadataTest method testReplaceWithMultiSelect.

@Test
public void testReplaceWithMultiSelect() {
    List<String> valueList = new ArrayList<>();
    valueList.add("bar");
    valueList.add("qux");
    Metadata m = new Metadata().replace("/foo", valueList);
    JsonArray operations = Json.parse(m.getPatch()).asArray();
    assertEquals(1, operations.size());
    JsonObject op = operations.get(0).asObject();
    assertEquals("replace", op.get("op").asString());
    assertEquals("/foo", op.get("path").asString());
    assertEquals("[\"bar\",\"qux\"]", op.get("value").toString());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Aggregations

JsonArray (com.eclipsesource.json.JsonArray)111 JsonObject (com.eclipsesource.json.JsonObject)96 JsonValue (com.eclipsesource.json.JsonValue)32 Test (org.junit.Test)30 URL (java.net.URL)28 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)11 Matchers.containsString (org.hamcrest.Matchers.containsString)6 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)5 Map (java.util.Map)5 Link (org.eclipse.leshan.Link)4 Date (java.util.Date)3 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)3 ClientEndPointDTO (com.hazelcast.internal.management.dto.ClientEndPointDTO)2 MalformedURLException (java.net.MalformedURLException)2 DecimalFormat (java.text.DecimalFormat)2 DecimalFormatSymbols (java.text.DecimalFormatSymbols)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)2