Search in sources :

Example 6 with ArrayNode

use of org.codehaus.jackson.node.ArrayNode in project motech by motech.

the class TaskServiceImpl method removeIgnoredFields.

private void removeIgnoredFields(JsonNode node) {
    if (null == node || node.isValueNode()) {
        return;
    }
    if (node.isObject()) {
        ObjectNode obj = (ObjectNode) node;
        obj.remove(IGNORED_FIELDS);
    }
    if (node.isArray()) {
        ArrayNode array = (ArrayNode) node;
        for (JsonNode item : array) {
            removeIgnoredFields(item);
        }
    }
    Iterator<Map.Entry<String, JsonNode>> elements = node.getFields();
    while (elements.hasNext()) {
        Map.Entry<String, JsonNode> entry = elements.next();
        if (!"values".equals(entry.getKey())) {
            removeIgnoredFields(entry.getValue());
        }
    }
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with ArrayNode

use of org.codehaus.jackson.node.ArrayNode in project helix by apache.

the class InstanceAccessor method getHealthReportsOnInstance.

@GET
@Path("{instanceName}/healthreports")
public Response getHealthReportsOnInstance(@PathParam("clusterId") String clusterId, @PathParam("instanceName") String instanceName) throws IOException {
    HelixDataAccessor accessor = getDataAccssor(clusterId);
    ObjectNode root = JsonNodeFactory.instance.objectNode();
    root.put(Properties.id.name(), instanceName);
    ArrayNode healthReportsNode = root.putArray(InstanceProperties.healthreports.name());
    List<String> healthReports = accessor.getChildNames(accessor.keyBuilder().healthReports(instanceName));
    if (healthReports != null && healthReports.size() > 0) {
        healthReportsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(healthReports));
    }
    return JSONRepresentation(root);
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 8 with ArrayNode

use of org.codehaus.jackson.node.ArrayNode in project helix by apache.

the class InstanceAccessor method getResourcesOnInstance.

@GET
@Path("{instanceName}/resources")
public Response getResourcesOnInstance(@PathParam("clusterId") String clusterId, @PathParam("instanceName") String instanceName) throws IOException {
    HelixDataAccessor accessor = getDataAccssor(clusterId);
    ObjectNode root = JsonNodeFactory.instance.objectNode();
    root.put(Properties.id.name(), instanceName);
    ArrayNode resourcesNode = root.putArray(InstanceProperties.resources.name());
    List<String> sessionIds = accessor.getChildNames(accessor.keyBuilder().sessions(instanceName));
    if (sessionIds == null || sessionIds.size() == 0) {
        return null;
    }
    // Only get resource list from current session id
    String currentSessionId = sessionIds.get(0);
    List<String> resources = accessor.getChildNames(accessor.keyBuilder().currentStates(instanceName, currentSessionId));
    if (resources != null && resources.size() > 0) {
        resourcesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(resources));
    }
    return JSONRepresentation(root);
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 9 with ArrayNode

use of org.codehaus.jackson.node.ArrayNode in project helix by apache.

the class ResourceAccessor method getResources.

@GET
public Response getResources(@PathParam("clusterId") String clusterId) {
    ObjectNode root = JsonNodeFactory.instance.objectNode();
    root.put(Properties.id.name(), JsonNodeFactory.instance.textNode(clusterId));
    ZkClient zkClient = getZkClient();
    ArrayNode idealStatesNode = root.putArray(ResourceProperties.idealStates.name());
    ArrayNode externalViewsNode = root.putArray(ResourceProperties.externalViews.name());
    List<String> idealStates = zkClient.getChildren(PropertyPathBuilder.idealState(clusterId));
    List<String> externalViews = zkClient.getChildren(PropertyPathBuilder.externalView(clusterId));
    if (idealStates != null) {
        idealStatesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(idealStates));
    } else {
        return notFound();
    }
    if (externalViews != null) {
        externalViewsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(externalViews));
    }
    return JSONRepresentation(root);
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) GET(javax.ws.rs.GET)

Example 10 with ArrayNode

use of org.codehaus.jackson.node.ArrayNode in project ovirt-engine by oVirt.

the class WebAdminHostPageServletTest method testGetPluginDefinitionsArray.

@Test
public void testGetPluginDefinitionsArray() {
    int mockDataCount = 10;
    List<PluginData> pluginData = new ArrayList<>();
    for (int i = 0; i < mockDataCount; i++) {
        PluginData mockData = mock(PluginData.class);
        // $NON-NLS-1$
        when(mockData.getName()).thenReturn("name" + i);
        // $NON-NLS-1$
        when(mockData.getUrl()).thenReturn("url" + i);
        when(mockData.mergeConfiguration()).thenReturn(mock(ObjectNode.class));
        when(mockData.isEnabled()).thenReturn(true);
        pluginData.add(mockData);
    }
    ArrayNode result = testServlet.getPluginDefinitionsArray(pluginData);
    assertEquals(mockDataCount, result.size());
    for (int i = 0; i < mockDataCount; i++) {
        JsonNode item = result.get(i);
        // $NON-NLS-1$ //$NON-NLS-2$
        assertEquals(item.get("name").asText(), "name" + i);
        // $NON-NLS-1$ //$NON-NLS-2$
        assertEquals(item.get("url").asText(), "url" + i);
        // $NON-NLS-1$
        assertTrue(item.get("config") instanceof ObjectNode);
        // $NON-NLS-1$
        assertTrue(item.get("enabled").asBoolean());
    }
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) PluginData(org.ovirt.engine.ui.frontend.server.gwt.plugin.PluginData) ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Test(org.junit.Test)

Aggregations

ArrayNode (org.codehaus.jackson.node.ArrayNode)44 ObjectNode (org.codehaus.jackson.node.ObjectNode)29 JsonNode (org.codehaus.jackson.JsonNode)17 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)11 GET (javax.ws.rs.GET)10 Test (org.junit.Test)10 Path (javax.ws.rs.Path)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Date (java.util.Date)4 List (java.util.List)4 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 Produces (javax.ws.rs.Produces)3 RegressionTestHelper (org.openmrs.module.htmlformentry.RegressionTestHelper)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2