Search in sources :

Example 31 with ArrayNode

use of org.codehaus.jackson.node.ArrayNode in project activityinfo by bedatadriven.

the class SitesResourcesTest method indicatorsArePresent.

@Test
public void indicatorsArePresent() throws IOException {
    QueryParameters parameters = new QueryParameters();
    parameters.databaseIds.add(2);
    String json = query(parameters);
    System.out.println(json);
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory factory = mapper.getJsonFactory();
    JsonParser jp = factory.createJsonParser(json);
    ArrayNode array = (ArrayNode) mapper.readTree(jp);
    assertThat(array.size(), equalTo(3));
    JsonNode site6 = getSiteById(array, 6);
    assertThat(site6.path("id").asInt(), equalTo(6));
    assertThat(site6.path("activity").asInt(), equalTo(4));
    double indicatorValue = site6.path("indicatorValues").path("6").asDouble();
    assertThat(indicatorValue, equalTo(70d));
}
Also used : JsonFactory(org.codehaus.jackson.JsonFactory) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JsonParser(org.codehaus.jackson.JsonParser) Test(org.junit.Test)

Example 32 with ArrayNode

use of org.codehaus.jackson.node.ArrayNode in project neo4j-documentation by neo4j.

the class EnterpriseAuthenticationDocIT method shouldAllowExecutingEnterpriseBuiltInProceduresWithAuthDisabled.

@Test
public void shouldAllowExecutingEnterpriseBuiltInProceduresWithAuthDisabled() throws Exception {
    // Given
    startServerWithAuthDisabled();
    // When
    String method = "POST";
    String path = "db/data/transaction/commit";
    HTTP.RawPayload payload = HTTP.RawPayload.quotedJson("{'statements':[{'statement':'CALL dbms.listQueries()'}]}");
    HTTP.Response response = HTTP.request(method, server.baseUri().resolve(path).toString(), payload);
    // Then
    assertThat(response.status(), equalTo(200));
    ArrayNode errors = (ArrayNode) response.get("errors");
    assertThat("Should have no errors", errors.size(), equalTo(0));
    ArrayNode results = (ArrayNode) response.get("results");
    ArrayNode data = (ArrayNode) results.get(0).get("data");
    assertThat("Should see our own query", data.size(), equalTo(1));
}
Also used : HTTP(org.neo4j.doc.server.HTTP) ArrayNode(org.codehaus.jackson.node.ArrayNode) Test(org.junit.Test)

Example 33 with ArrayNode

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

the class WorkflowAccessor method getWorkflow.

@GET
@Path("{workflowId}")
public Response getWorkflow(@PathParam("clusterId") String clusterId, @PathParam("workflowId") String workflowId) {
    TaskDriver taskDriver = getTaskDriver(clusterId);
    WorkflowConfig workflowConfig = taskDriver.getWorkflowConfig(workflowId);
    WorkflowContext workflowContext = taskDriver.getWorkflowContext(workflowId);
    ObjectNode root = JsonNodeFactory.instance.objectNode();
    TextNode id = JsonNodeFactory.instance.textNode(workflowId);
    root.put(Properties.id.name(), id);
    ObjectNode workflowConfigNode = JsonNodeFactory.instance.objectNode();
    ObjectNode workflowContextNode = JsonNodeFactory.instance.objectNode();
    if (workflowConfig != null) {
        getWorkflowConfigNode(workflowConfigNode, workflowConfig.getRecord());
    }
    if (workflowContext != null) {
        getWorkflowContextNode(workflowContextNode, workflowContext.getRecord());
    }
    root.put(WorkflowProperties.WorkflowConfig.name(), workflowConfigNode);
    root.put(WorkflowProperties.WorkflowContext.name(), workflowContextNode);
    JobDag jobDag = workflowConfig.getJobDag();
    ArrayNode jobs = OBJECT_MAPPER.valueToTree(jobDag.getAllNodes());
    ObjectNode parentJobs = OBJECT_MAPPER.valueToTree(jobDag.getChildrenToParents());
    root.put(WorkflowProperties.Jobs.name(), jobs);
    root.put(WorkflowProperties.ParentJobs.name(), parentJobs);
    return JSONRepresentation(root);
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) ObjectNode(org.codehaus.jackson.node.ObjectNode) TaskDriver(org.apache.helix.task.TaskDriver) WorkflowContext(org.apache.helix.task.WorkflowContext) TextNode(org.codehaus.jackson.node.TextNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) JobDag(org.apache.helix.task.JobDag) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 34 with ArrayNode

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

the class InstanceAccessor method getInstances.

@GET
public Response getInstances(@PathParam("clusterId") String clusterId) {
    HelixDataAccessor accessor = getDataAccssor(clusterId);
    ObjectNode root = JsonNodeFactory.instance.objectNode();
    root.put(Properties.id.name(), JsonNodeFactory.instance.textNode(clusterId));
    ArrayNode instancesNode = root.putArray(InstanceProperties.instances.name());
    ArrayNode onlineNode = root.putArray(InstanceProperties.online.name());
    ArrayNode disabledNode = root.putArray(InstanceProperties.disabled.name());
    List<String> instances = accessor.getChildNames(accessor.keyBuilder().instanceConfigs());
    if (instances != null) {
        instancesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(instances));
    } else {
        return notFound();
    }
    List<String> liveInstances = accessor.getChildNames(accessor.keyBuilder().liveInstances());
    ClusterConfig clusterConfig = accessor.getProperty(accessor.keyBuilder().clusterConfig());
    for (String instanceName : instances) {
        InstanceConfig instanceConfig = accessor.getProperty(accessor.keyBuilder().instanceConfig(instanceName));
        if (instanceConfig != null) {
            if (!instanceConfig.getInstanceEnabled() || (clusterConfig.getDisabledInstances() != null && clusterConfig.getDisabledInstances().containsKey(instanceName))) {
                disabledNode.add(JsonNodeFactory.instance.textNode(instanceName));
            }
            if (liveInstances.contains(instanceName)) {
                onlineNode.add(JsonNodeFactory.instance.textNode(instanceName));
            }
        }
    }
    return JSONRepresentation(root);
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) ObjectNode(org.codehaus.jackson.node.ObjectNode) InstanceConfig(org.apache.helix.model.InstanceConfig) ArrayNode(org.codehaus.jackson.node.ArrayNode) ClusterConfig(org.apache.helix.model.ClusterConfig) GET(javax.ws.rs.GET)

Example 35 with ArrayNode

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

the class JobAccessor method getJobs.

@GET
public Response getJobs(@PathParam("clusterId") String clusterId, @PathParam("workflowName") String workflowName) {
    TaskDriver driver = getTaskDriver(clusterId);
    WorkflowConfig workflowConfig = driver.getWorkflowConfig(workflowName);
    ObjectNode root = JsonNodeFactory.instance.objectNode();
    if (workflowConfig == null) {
        return badRequest(String.format("Workflow %s is not found!", workflowName));
    }
    Set<String> jobs = workflowConfig.getJobDag().getAllNodes();
    root.put(Properties.id.name(), JobProperties.Jobs.name());
    ArrayNode jobsNode = root.putArray(JobProperties.Jobs.name());
    if (jobs != null) {
        jobsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(jobs));
    }
    return JSONRepresentation(root);
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) ObjectNode(org.codehaus.jackson.node.ObjectNode) TaskDriver(org.apache.helix.task.TaskDriver) ArrayNode(org.codehaus.jackson.node.ArrayNode) GET(javax.ws.rs.GET)

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