Example usage for com.fasterxml.jackson.databind JsonNode get

List of usage examples for com.fasterxml.jackson.databind JsonNode get

Introduction

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

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:vk.model.VKApiCountry.java

/**
 * Fills a Country instance from JsonNode.
 *///from   ww  w. j  a v a2s . c  o  m
public VKApiCountry parse(JsonNode from) {
    id = from.get("id").asInt();
    title = from.get("title").asText();
    return this;
}

From source file:com.github.fge.jsonschema.processors.validation.ArraySchemaSelector.java

public ArraySchemaSelector(final JsonNode digest) {
    hasItems = digest.get("hasItems").booleanValue();
    itemsIsArray = digest.get("itemsIsArray").booleanValue();
    itemsSize = digest.get("itemsSize").intValue();
    hasAdditional = digest.get("hasAdditional").booleanValue();
}

From source file:com.pkrete.locationservice.admin.deserializers.LanguageJSONDeserializer.java

@Override
public Language deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {

    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    int id = node.get("id") == null ? 0 : node.get("id").intValue();
    String name = node.get("name") == null ? "" : node.get("name").textValue();
    String code = node.get("code") == null ? "" : node.get("code").textValue();
    return new Language(id, name, code);
}

From source file:org.eel.kitchen.jsonschema.syntax.PatternSyntaxChecker.java

@Override
void checkValue(final Message.Builder msg, final List<Message> messages, final JsonNode schema) {
    final String value = schema.get(keyword).textValue();
    if (RhinoHelper.regexIsValid(value))
        return;//from   w w  w.ja  va  2  s  . co  m

    msg.setMessage("pattern is not a valid ECMA 262 regex").addInfo("found", value);

    messages.add(msg.build());
}

From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.api.ConfigControllerTest.java

@Test
public void testConfig() throws Exception {
    final Tuple2<Integer, JsonNode> tup = fetchJson("/config", false);
    assertEquals(200, tup._1.intValue());
    final JsonNode json = tup._2;

    assertEquals("test-cluster", json.get("frameworkName").asText());
    assertThat(json.get("frameworkId").asText()).isNotEmpty();
    assertEquals(9042, json.get("nativePort").asInt());
    assertEquals(9160, json.get("rpcPort").asInt());
}

From source file:dao.ScriptFinderDAO.java

public static ObjectNode getPagedScripts(JsonNode filterOpt, int page, int size) {
    ObjectNode result = Json.newObject();

    javax.sql.DataSource ds = getJdbcTemplate().getDataSource();
    DataSourceTransactionManager tm = new DataSourceTransactionManager(ds);
    TransactionTemplate txTemplate = new TransactionTemplate(tm);
    String scriptName = null;/*from w  w  w . j  a  v  a  2s  .  co m*/
    String scriptPath = null;
    String scriptType = null;
    String chainName = null;
    String jobName = null;
    String committerName = null;
    String committerEmail = null;
    if (filterOpt != null && (filterOpt.isContainerNode())) {
        if (filterOpt.has("scriptName")) {
            scriptName = filterOpt.get("scriptName").asText();
        }
        if (filterOpt.has("scriptPath")) {
            scriptPath = filterOpt.get("scriptPath").asText();
        }
        if (filterOpt.has("scriptType")) {
            scriptType = filterOpt.get("scriptType").asText();
        }
        if (filterOpt.has("chainName")) {
            chainName = filterOpt.get("chainName").asText();
        }
        if (filterOpt.has("jobName")) {
            jobName = filterOpt.get("jobName").asText();
        }
        if (filterOpt.has("committerName")) {
            committerName = filterOpt.get("committerName").asText();
        }
        if (filterOpt.has("committerEmail")) {
            committerEmail = filterOpt.get("committerEmail").asText();
        }
    }

    final String finalScriptName = scriptName;
    final String finalScriptPath = scriptPath;
    final String finalScriptType = scriptType;
    final String finalChainName = chainName;
    final String finalJobName = jobName;
    final String finalCommitterName = committerName;
    result = txTemplate.execute(new TransactionCallback<ObjectNode>() {
        public ObjectNode doInTransaction(TransactionStatus status) {

            List<Map<String, Object>> rows = null;
            String whereClause = "";
            boolean needAnd = false;
            Map<String, Object> params = new HashMap<String, Object>();
            if (StringUtils.isNotBlank(finalScriptName)) {
                if (StringUtils.isBlank(whereClause)) {
                    whereClause = " WHERE ";
                }
                if (needAnd) {
                    whereClause += " AND ";
                }
                whereClause += " script_name like :scriptname ";
                needAnd = true;
                params.put("scriptname", "%" + finalScriptName + "%");
            }
            if (StringUtils.isNotBlank(finalScriptPath)) {
                if (StringUtils.isBlank(whereClause)) {
                    whereClause = " WHERE ";
                }
                if (needAnd) {
                    whereClause += " AND ";
                }
                whereClause += " script_path like :scriptpath ";
                needAnd = true;
                params.put("scriptpath", "%" + finalScriptPath + "%");
            }
            if (StringUtils.isNotBlank(finalScriptType)) {
                if (StringUtils.isBlank(whereClause)) {
                    whereClause = " WHERE ";
                }
                if (needAnd) {
                    whereClause += " AND ";
                }
                whereClause += " script_type like :scripttype ";
                needAnd = true;
                params.put("scripttype", "%" + finalScriptType + "%");
            }
            if (StringUtils.isNotBlank(finalChainName)) {
                if (StringUtils.isBlank(whereClause)) {
                    whereClause = " WHERE ";
                }
                if (needAnd) {
                    whereClause += " AND ";
                }
                whereClause += " chain_name like :chainname ";
                needAnd = true;
                params.put("chainname", "%" + finalChainName + "%");
            }
            if (StringUtils.isNotBlank(finalJobName)) {
                if (StringUtils.isBlank(whereClause)) {
                    whereClause = " WHERE ";
                }
                if (needAnd) {
                    whereClause += " AND ";
                }
                whereClause += " job_name like :jobname ";
                needAnd = true;
                params.put("jobname", "%" + finalJobName + "%");
            }
            if (StringUtils.isNotBlank(finalCommitterName)) {
                if (StringUtils.isBlank(whereClause)) {
                    whereClause = " WHERE ";
                }
                if (needAnd) {
                    whereClause += " AND ";
                }
                whereClause += " ( committer_ldap like :committername or committer_name like :committername )";
                needAnd = true;
                params.put("committername", "%" + finalCommitterName + "%");
            }
            String query = GET_PAGED_SCRIPTS.replace("$WHERE_CLAUSE", whereClause);
            params.put("index", (page - 1) * size);
            params.put("size", size);
            NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(
                    getJdbcTemplate().getDataSource());
            rows = namedParameterJdbcTemplate.queryForList(query, params);
            long count = 0;
            try {
                count = getJdbcTemplate().queryForObject("SELECT FOUND_ROWS()", Long.class);
            } catch (EmptyResultDataAccessException e) {
                Logger.error("Exception = " + e.getMessage());
            }

            List<ScriptInfo> pagedScripts = new ArrayList<ScriptInfo>();
            for (Map row : rows) {
                int applicationID = (Integer) row.get(ScriptInfoRowMapper.APPLICATION_ID_COLUMN);
                int jobID = (Integer) row.get(ScriptInfoRowMapper.JOB_ID_COLUMN);
                String scriptUrl = (String) row.get(ScriptInfoRowMapper.SCRIPT_URL_COLUMN);
                String scriptPath = (String) row.get(ScriptInfoRowMapper.SCRIPT_PATH_COLUMN);
                String scriptType = (String) row.get(ScriptInfoRowMapper.SCRIPT_TYPE_COLUMN);
                String chainName = (String) row.get(ScriptInfoRowMapper.CHAIN_NAME_COLUMN);
                String jobName = (String) row.get(ScriptInfoRowMapper.JOB_NAME_COLUMN);
                String scriptName = (String) row.get(ScriptInfoRowMapper.SCRIPT_NAME_COLUMN);
                String committerName = (String) row.get(ScriptInfoRowMapper.COMMITTER_NAMES_COLUMN);
                String committerEmail = (String) row.get(ScriptInfoRowMapper.COMMITTER_EMAILS_COLUMN);
                ScriptInfo scriptInfo = new ScriptInfo();
                scriptInfo.applicationID = applicationID;
                scriptInfo.jobID = jobID;
                scriptInfo.scriptUrl = scriptUrl;
                scriptInfo.scriptPath = scriptPath;
                scriptInfo.scriptType = scriptType;
                scriptInfo.scriptName = scriptName;
                scriptInfo.chainName = chainName;
                scriptInfo.jobName = jobName;
                scriptInfo.committerName = committerName;
                scriptInfo.committerEmail = committerEmail;
                pagedScripts.add(scriptInfo);
            }

            ObjectNode resultNode = Json.newObject();
            resultNode.put("count", count);
            resultNode.put("page", page);
            resultNode.put("itemsPerPage", size);
            resultNode.put("totalPages", (int) Math.ceil(count / ((double) size)));
            resultNode.set("scripts", Json.toJson(pagedScripts));

            return resultNode;
        }
    });

    return result;
}

From source file:org.pac4j.oauth.profile.foursquare.FoursquareUserFriendGroup.java

@Override
protected void buildFromJson(JsonNode json) {
    count = json.get("count").asInt();
    name = json.get("name").asText();
    type = json.get("type").asText();

    ArrayNode groupsArray = (ArrayNode) json.get("items");

    for (int i = 0; i < groupsArray.size(); i++) {
        FoursquareUserFriend friend = new FoursquareUserFriend();
        friend.buildFromJson(groupsArray.get(i));
        friends.add(friend);/*from   ww w.  ja v a  2s . c o m*/
    }
}

From source file:snow.console.Connect.java

@Override
public void execute(JsonNode data, StreamResults stream) {
    JsonNode ref = data.get("ref");
    if (ref instanceof TextNode)
        stream.put("ref", ref);
    stream.put("id", TextNode.valueOf(Terminal.create().id()));
}

From source file:org.lendingclub.mercator.aws.S3BucketScanner.java

@Override
public Optional<String> computeArn(JsonNode n) {
    String name = n.get("name").asText();

    return Optional.of("arn:aws:s3:::" + name);
}

From source file:com.ariatemplates.attester.junit.MessageHandler.java

protected Description getCorrespondingTest(JsonNode message, Map<Integer, Description> tests) {
    Integer id = message.get("taskId").asInt();
    return tests.get(id);
}