Search in sources :

Example 51 with JsonArray

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

the class MetadataTemplateTest method testDeprecatedExecuteMetadataQueryWithFields.

@Test
public void testDeprecatedExecuteMetadataQueryWithFields() throws IOException {
    final String metadataQueryURL = "/metadata_queries/execute_read";
    final String from = "enterprise_67890.catalogImages";
    final String query = "photographer = :arg";
    final JsonObject queryParameters = new JsonObject().add("arg", "Bob Dylan");
    final String ancestorFolderId = "0";
    final String indexName = null;
    final String field1 = "sha1";
    final String field2 = "name";
    final String field3 = "id";
    final String field4 = "metadata.enterprise_240748.catalogImages.photographer";
    final JsonArray orderBy = null;
    final int limit = 2;
    final String marker = null;
    JsonArray fields = new JsonArray();
    fields.add(field1);
    fields.add(field2);
    fields.add(field3);
    fields.add(field4);
    JsonObject body = new JsonObject();
    body.add("from", from);
    body.add("query", query);
    body.add("query_params", queryParameters);
    body.add("ancestor_folder_id", ancestorFolderId);
    body.add("limit", limit);
    body.add("fields", fields);
    // First request will return a page of results with two items
    String result = TestConfig.getFixture("BoxMetadataTemplate/MetadataQueryResponseForFields200");
    wireMockRule.stubFor(post(urlPathEqualTo(metadataQueryURL)).withRequestBody(equalToJson(body.toString())).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(result)));
    // Make the first request and get the result
    BoxResourceIterable<BoxItem.Info> results = MetadataTemplate.executeMetadataQuery(this.api, from, query, queryParameters, ancestorFolderId, indexName, orderBy, limit, marker, field1, field2, field3, field4);
    // First item on the first page of results
    BoxFile.Info fileBoxItem = (BoxFile.Info) results.iterator().next();
    assertEquals("file", fileBoxItem.getType());
    assertEquals("1244738582", fileBoxItem.getID());
    assertEquals("Very Important.docx", fileBoxItem.getName());
    Metadata fileMetadata = fileBoxItem.getMetadata("catalogImages", "enterprise_67890");
    assertEquals("catalogImages", fileMetadata.getTemplateName());
    assertEquals("enterprise_67890", fileMetadata.getScope());
    assertEquals("Bob Dylan", fileMetadata.getString("/photographer"));
    // Second item on the first page of results
    BoxFolder.Info folderBoxItem = (BoxFolder.Info) results.iterator().next();
    assertEquals("folder", folderBoxItem.getType());
    assertEquals("124242482", folderBoxItem.getID());
    assertEquals("Also Important.docx", folderBoxItem.getName());
    Metadata folderMetadata = folderBoxItem.getMetadata("catalogImages", "enterprise_67890");
    assertEquals("catalogImages", folderMetadata.getTemplateName());
    assertEquals("enterprise_67890", folderMetadata.getScope());
    assertEquals("Bob Dylan", folderMetadata.getString("/photographer"));
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Example 52 with JsonArray

use of com.eclipsesource.json.JsonArray in project hazelcast by hazelcast.

the class MemberPartitionStateImpl method toJson.

@Override
public JsonObject toJson() {
    JsonObject root = new JsonObject();
    JsonArray partitionsArray = new JsonArray();
    for (Integer lsPartition : partitions) {
        partitionsArray.add(lsPartition);
    }
    root.add("partitions", partitionsArray);
    root.add("memberStateSafe", memberStateSafe);
    root.add("migrationQueueSize", migrationQueueSize);
    return root;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject)

Example 53 with JsonArray

use of com.eclipsesource.json.JsonArray in project hazelcast by hazelcast.

the class MemberStateImpl method toJson.

@Override
public JsonObject toJson() {
    final JsonObject root = new JsonObject();
    root.add("address", address);
    serializeMap(root, "mapStats", mapStats);
    serializeMap(root, "multiMapStats", multiMapStats);
    serializeMap(root, "replicatedMapStats", replicatedMapStats);
    serializeMap(root, "queueStats", queueStats);
    serializeMap(root, "topicStats", topicStats);
    serializeMap(root, "executorStats", executorStats);
    serializeMap(root, "cacheStats", cacheStats);
    serializeMap(root, "wanStats", wanStats);
    final JsonObject runtimePropsObject = new JsonObject();
    for (Map.Entry<String, Long> entry : runtimeProps.entrySet()) {
        runtimePropsObject.add(entry.getKey(), entry.getValue());
    }
    root.add("runtimeProps", runtimePropsObject);
    final JsonArray clientsArray = new JsonArray();
    for (ClientEndPointDTO client : clients) {
        clientsArray.add(client.toJson());
    }
    root.add("clients", clientsArray);
    root.add("beans", beans.toJson());
    root.add("memoryStats", memoryStats.toJson());
    root.add("operationStats", operationStats.toJson());
    root.add("memberPartitionState", memberPartitionState.toJson());
    root.add("nodeState", nodeState.toJson());
    root.add("hotRestartState", hotRestartState.toJson());
    root.add("clusterHotRestartStatus", clusterHotRestartStatus.toJson());
    root.add("wanSyncState", wanSyncState.toJson());
    return root;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ClientEndPointDTO(com.hazelcast.internal.management.dto.ClientEndPointDTO) JsonObject(com.eclipsesource.json.JsonObject) JsonUtil.getString(com.hazelcast.util.JsonUtil.getString) HashMap(java.util.HashMap) Map(java.util.Map)

Example 54 with JsonArray

use of com.eclipsesource.json.JsonArray in project hazelcast by hazelcast.

the class TimedMemberState method toJson.

@Override
public JsonObject toJson() {
    JsonObject root = new JsonObject();
    root.add("master", master);
    root.add("time", time);
    root.add("clusterName", clusterName);
    JsonArray instanceNames = new JsonArray();
    for (String instanceName : this.instanceNames) {
        instanceNames.add(instanceName);
    }
    root.add("instanceNames", instanceNames);
    if (memberList != null) {
        JsonArray members = new JsonArray();
        for (String member : memberList) {
            members.add(member);
        }
        root.add("memberList", members);
    }
    root.add("memberState", memberState.toJson());
    return root;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) JsonUtil.getString(com.hazelcast.util.JsonUtil.getString)

Example 55 with JsonArray

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

the class BoxItem method parsePathCollection.

private List<BoxFolder> parsePathCollection(JsonObject jsonObject) {
    int count = jsonObject.get("total_count").asInt();
    List<BoxFolder> pathCollection = new ArrayList<BoxFolder>(count);
    JsonArray entries = jsonObject.get("entries").asArray();
    for (JsonValue value : entries) {
        JsonObject entry = value.asObject();
        BoxFolder folder = new BoxFolder();
        folder.createFromJson(entry);
        pathCollection.add(folder);
    }
    return pathCollection;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject)

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