Example usage for com.fasterxml.jackson.databind.node ArrayNode get

List of usage examples for com.fasterxml.jackson.databind.node ArrayNode get

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ArrayNode get.

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:org.walkmod.conf.providers.yml.RemoveIncludesOrExcludesYMLAction.java

@Override
public void doAction(JsonNode node) throws Exception {
    if (chain == null) {
        chain = "default";
    }/* w  w  w . ja v a  2s  .  co m*/

    if (node.has("chains")) {
        JsonNode chains = node.get("chains");
        if (chains.isArray()) {
            ArrayNode chainsArray = (ArrayNode) chains;
            int limit = chainsArray.size();
            JsonNode selectedChain = null;
            for (int i = 0; i < limit && selectedChain == null; i++) {
                JsonNode chainNode = chainsArray.get(i);
                if (chainNode.has("name")) {
                    if (chainNode.get("name").asText().equals(chain)) {
                        selectedChain = chainNode;
                    }
                }
            }
            if (selectedChain != null) {
                if (setToReader) {
                    JsonNode reader = null;
                    if (selectedChain.has("reader")) {
                        reader = selectedChain.get("reader");
                    }
                    if (reader != null) {
                        removesIncludesOrExcludesList((ObjectNode) reader);
                    }
                }
                if (setToWriter) {
                    JsonNode writer = null;
                    if (selectedChain.has("writer")) {
                        writer = selectedChain.get("writer");
                    }
                    if (writer != null) {
                        removesIncludesOrExcludesList((ObjectNode) writer);
                    }
                }
            }
        }
        provider.write(node);
    }
}

From source file:de.thingweb.thing.Thing.java

public URI getUri(int index) {
    JsonNode uris = getMetadata().get("uris");
    if (uris != null) {
        try {/*from   w  ww .j a va 2  s  .c o m*/
            if (uris.getNodeType() == JsonNodeType.STRING) {
                return new URI(uris.asText());
            } else if (uris.getNodeType() == JsonNodeType.ARRAY) {
                ArrayNode an = (ArrayNode) uris;
                return new URI(an.get(index).asText());
            }
        } catch (URISyntaxException e) {
            throw new RuntimeException("TD with malformed base uris");
        }
    } else {
        throw new RuntimeException("TD without base uris field");
    }
    // should never be reached
    throw new RuntimeException("Unexpected error while retrieving uri at index " + index);
}

From source file:com.marklogic.samplestack.database.DatabaseTransformsIT.java

@Test
public void answerPatchTransform() {
    // make a user
    contributorService.store(Utils.joeUser);

    // make sure there's no question
    operations.delete(ClientRole.SAMPLESTACK_CONTRIBUTOR, TEST_URI);

    askAndAnswer();/*from   w ww. j a  va  2s.c o m*/

    JsonNode output = operations.getJsonDocument(ClientRole.SAMPLESTACK_CONTRIBUTOR, TEST_URI);

    ArrayNode answers = (ArrayNode) output.get("answers");

    assertEquals("transform added an answer", "this is the text of my answer",
            answers.get(0).get("text").asText());
    assertEquals("transform added a user", Utils.joeUser.getUserName(),
            answers.get(0).get("owner").get("userName").asText());
    assertTrue("transform added empty comments", answers.get(0).get("comments") != null);

    contribManager.delete(TEST_URI);
}

From source file:com.turn.shapeshifter.NamedSchemaParserTest.java

@Test
public void testParseWithRepeatedTransform() throws Exception {
    NamedSchema schema = NamedSchema.of(Union.getDescriptor(), "Union").transform("int32_repeated", TWO);
    SchemaRegistry registry = new SchemaRegistry();
    registry.register(schema);// w  w  w .  jav  a 2s . c  o  m
    Union fibonacci = Union.newBuilder().addInt32Repeated(1).addInt32Repeated(1).addInt32Repeated(2)
            .addInt32Repeated(3).addInt32Repeated(5).addInt32Repeated(8).build();
    JsonNode result = new NamedSchemaSerializer(schema).serialize(fibonacci, registry);

    ArrayNode repeated = (ArrayNode) result.get("int32Repeated");
    Assert.assertEquals(6, repeated.size());
    Assert.assertEquals(2, repeated.get(0).asInt());
    Assert.assertEquals(2, repeated.get(1).asInt());
    Assert.assertEquals(4, repeated.get(2).asInt());
    Assert.assertEquals(6, repeated.get(3).asInt());
    Assert.assertEquals(10, repeated.get(4).asInt());
    Assert.assertEquals(16, repeated.get(5).asInt());

    Union parsed = Union.newBuilder().mergeFrom(new NamedSchemaParser(schema).parse(result, registry)).build();
    Assert.assertEquals(1, parsed.getInt32Repeated(0));
    Assert.assertEquals(1, parsed.getInt32Repeated(1));
    Assert.assertEquals(2, parsed.getInt32Repeated(2));
    Assert.assertEquals(3, parsed.getInt32Repeated(3));
    Assert.assertEquals(5, parsed.getInt32Repeated(4));
    Assert.assertEquals(8, parsed.getInt32Repeated(5));
}

From source file:org.gitana.platform.client.job.JobImpl.java

@Override
public List<JobLogEntry> getLogEntries() {
    List<JobLogEntry> list = new ArrayList<JobLogEntry>();

    ArrayNode entries = getArray(FIELD_LOG_ENTRIES);
    for (int i = 0; i < entries.size(); i++) {
        ObjectNode object = (ObjectNode) entries.get(i);

        JobLogEntry entry = new JobLogEntry(object);
        list.add(entry);//from ww w . jav a2s  . c  o  m
    }

    return list;
}

From source file:ru.histone.optimizer.SafeASTEvaluationOptimizerTest.java

@Test
public void constant_folding_advanced_expr1() throws IOException, HistoneException {
    String input = input("constant_folding/advanced_expr1.tpl");

    ArrayNode ast = histone.parseTemplateToAST(new StringReader(input));
    ArrayNode finalAst = histone.optimizeAST(ast);
    assertTrue(finalAst.get(0).asText().equals("1.43"));

    // Assert that evaluation results are equal
    String astS = histone.evaluateAST(ast);
    String finalAstS = histone.evaluateAST(finalAst);
    assertEquals(astS, finalAstS);//from   w  ww.  ja v a  2 s. c  om
}

From source file:ru.histone.optimizer.SafeASTEvaluationOptimizerTest.java

@Test
public void constant_folding_advanced_expr2() throws IOException, HistoneException {
    String input = input("constant_folding/advanced_expr2.tpl");

    ArrayNode ast = histone.parseTemplateToAST(new StringReader(input));
    ArrayNode finalAst = histone.optimizeAST(ast);
    assertTrue(finalAst.get(0).asBoolean() == false);

    // Assert that evaluation results are equal
    String astS = histone.evaluateAST(ast);
    String finalAstS = histone.evaluateAST(finalAst);
    assertEquals(astS, finalAstS);/*w w  w.j  ava 2  s. co  m*/
}

From source file:ru.histone.optimizer.SafeASTEvaluationOptimizerTest.java

@Test
public void constant_folding_advanced_expr3() throws IOException, HistoneException {
    String input = input("constant_folding/advanced_expr3.tpl");

    ArrayNode ast = histone.parseTemplateToAST(new StringReader(input));
    ArrayNode finalAst = histone.optimizeAST(ast);
    assertTrue(finalAst.get(0).asBoolean() == true);

    // Assert that evaluation results are equal
    String astS = histone.evaluateAST(ast);
    String finalAstS = histone.evaluateAST(finalAst);
    assertEquals(astS, finalAstS);/*from   ww  w.j  av  a2  s. c o  m*/
}

From source file:org.thingsboard.server.dao.rule.BaseRuleService.java

private void validateFilters(JsonNode filtersJson) {
    if (filtersJson == null || filtersJson.isNull()) {
        throw new IncorrectParameterException("Rule filters are required!");
    }//from  ww w  . j a v a 2s .  c  om
    if (!filtersJson.isArray()) {
        throw new IncorrectParameterException("Filters json is not an array!");
    }
    ArrayNode filtersArray = (ArrayNode) filtersJson;
    for (int i = 0; i < filtersArray.size(); i++) {
        validateComponentJson(filtersArray.get(i), ComponentType.FILTER);
    }
}

From source file:com.marklogic.entityservices.TestEsEntityTypeSPARQL.java

@Test
public void sampleSPARQLQuery2() throws JsonGenerationException, JsonMappingException, IOException {
    String assertTypeHasProperties = "PREFIX t: <http://marklogic.com/testing-entity-type/SchemaCompleteEntityType-0.0.1/> "
            + "PREFIX es: <http://marklogic.com/entity-services#> " + "SELECT ?version where {"
            + "t:SchemaCompleteEntityType ?version \"0.0.1\" ." + "}";

    JacksonHandle handle = queryMgr.executeSelect(queryMgr.newQueryDefinition(assertTypeHasProperties),
            new JacksonHandle());
    JsonNode results = handle.get();//from  w ww.j a va2  s  .com

    // to see on System.out
    //new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(System.out, results);

    ArrayNode bindings = (ArrayNode) results.get("results").get("bindings");
    assertEquals(1, bindings.size());

    assertEquals("http://marklogic.com/entity-services#version",
            bindings.get(0).get("version").get("value").asText());
}