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

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

Introduction

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

Prototype

public String textValue() 

Source Link

Usage

From source file:com.digitalpebble.storm.crawler.filtering.regex.RegexURLNormalizer.java

@Override
public void configure(Map stormConf, JsonNode paramNode) {
    JsonNode node = paramNode.get("urlNormalizers");
    if (node != null && node.isArray()) {
        rules = readRules((ArrayNode) node);
    } else {/*  w  ww  .ja  va  2s. c  om*/
        JsonNode filenameNode = paramNode.get("regexNormalizerFile");
        String rulesFileName;
        if (filenameNode != null) {
            rulesFileName = filenameNode.textValue();
        } else {
            rulesFileName = "default-regex-normalizers.xml";
        }
        rules = readRules(rulesFileName);
    }

}

From source file:org.pentaho.metaverse.api.MetaverseLogicalIdGeneratorTest.java

@Test
public void testGenerateLogicalId() throws Exception {
    when(node.getProperty("name")).thenReturn("john doe");
    when(node.getProperty("age")).thenReturn(30);
    when(node.getProperty("address")).thenReturn("1234 Pentaho Way Orlando, FL 12345");
    Calendar cal = GregorianCalendar.getInstance();
    cal.set(1976, Calendar.JANUARY, 1, 0, 0, 0);
    when(node.getProperty("birthday")).thenReturn(cal.getTime());
    when(node.getPropertyKeys()).thenReturn(new HashSet<String>() {
        {/*w  w w  .ja va 2  s.c o  m*/
            add("address");
            add("age");
            add("birthday");
            add("name");
        }
    });

    // make sure there is no logicalid on the node initially
    assertNull(node.getProperty(DictionaryConst.PROPERTY_LOGICAL_ID));

    String logicalId = idGenerator.generateId(node);

    // it should come out in alphabetical order by key
    assertEquals(
            "{\"address\":\"1234 Pentaho Way Orlando, FL 12345\",\"age\":\"30\",\"birthday\":\"1976-01-01 00:00:00\",\"name\":\"john doe\"}",
            logicalId);

    // make sure the json string is parseable
    JsonNode jsonObject = objectMapper.readTree(logicalId);
    JsonNode address = jsonObject.get("address");
    assertEquals("1234 Pentaho Way Orlando, FL 12345", address.textValue());

    // make sure a call was made to add the logical id as a property
    verify(node).setProperty(DictionaryConst.PROPERTY_LOGICAL_ID, logicalId);

}

From source file:io.syndesis.connector.catalog.ConnectorCatalog.java

private void prefetchConnectors() {
    try (InputStream is = getClass().getResourceAsStream(CONNECTOR_SCHEMAS)) {
        if (is != null) {
            ArrayNode descriptors = (ArrayNode) new ObjectMapper().readTree(is);
            for (JsonNode descriptor : descriptors) {
                JsonNode gav = descriptor.get("gav");
                if (gav == null) {
                    continue;
                }/*from   w w w .  ja v a  2s  . c o m*/
                String gavCoords[] = gav.textValue().split(":");
                if (gavCoords.length < 3) {
                    continue;
                }
                LOG.info("Prefetched meta for {}:{}:{}", gavCoords[0], gavCoords[1], gavCoords[2]);
                prefetchedConnectors.add(gav.textValue());

                JsonNode connector = descriptor.get("connector");
                ObjectNode component = (ObjectNode) descriptor.get("component");
                if (connector != null) {
                    addConnector(gavCoords, connector, component);
                }
                if (component != null) {
                    addComponent(component);
                }
            }
        }
    } catch (IOException exp) {
        LOG.error("Cannot initialize connectors from {} : {}", CONNECTOR_SCHEMAS, exp.getMessage(), exp);
    }
}

From source file:org.pentaho.metaverse.api.MetaverseLogicalIdGeneratorTest.java

@Test
public void testGenerateLogicalId_escapedCharacters() throws Exception {
    when(node.getProperty("name")).thenReturn("john\ndoe");
    when(node.getProperty("age")).thenReturn(30);
    when(node.getProperty("address")).thenReturn("1234 Pentaho Way\\Orlando, FL 12345");
    Calendar cal = GregorianCalendar.getInstance();
    cal.set(1976, Calendar.JANUARY, 1, 0, 0, 0);
    when(node.getProperty("birthday")).thenReturn(cal.getTime());
    when(node.getPropertyKeys()).thenReturn(new HashSet<String>() {
        {//from   ww  w.  j a v a2  s.co  m
            add("address");
            add("age");
            add("birthday");
            add("name");
        }
    });

    // make sure there is no logicalid on the node initially
    assertNull(node.getProperty(DictionaryConst.PROPERTY_LOGICAL_ID));

    String logicalId = idGenerator.generateId(node);

    // it should come out in alphabetical order by key
    assertEquals(
            "{\"address\":\"1234 Pentaho Way\\\\Orlando, FL 12345\",\"age\":\"30\",\"birthday\":\"1976-01-01 00:00:00\",\"name\":\"john\\ndoe\"}",
            logicalId);

    // make sure the json string is parseable
    JsonNode jsonObject = objectMapper.readTree(logicalId);
    JsonNode address = jsonObject.get("address");
    assertEquals("1234 Pentaho Way\\Orlando, FL 12345", address.textValue());
    JsonNode name = jsonObject.get("name");
    assertEquals("john\ndoe", name.textValue());
    System.out.println(jsonObject.toString());

    // make sure a call was made to add the logical id as a property
    verify(node).setProperty(DictionaryConst.PROPERTY_LOGICAL_ID, logicalId);

}

From source file:org.aperte.lp.movies.OpeningConfigValidator.java

/**
 * {@inheritDoc}/* w ww.jav  a  2 s .co m*/
 */
@Override
public ValidateConfigResponse validateConfig(String configJson) throws ParseException {
    if (configJson == null || configJson.isEmpty()) {
        return error(SELECT_COUNTRY_ERROR);
    }

    // Parse the configuration json
    ObjectMapper mapper = new ObjectMapper();
    JsonNode root = null;
    try {
        root = mapper.readTree(configJson);
    } catch (JsonProcessingException e) {
        throw new ParseException("Unable to parse JSON: " + configJson, e);
    } catch (IOException e) {
        throw new ParseException("Unable to parse JSON: " + configJson, e);
    }
    if (root == null) {
        return error(SELECT_COUNTRY_ERROR);
    }

    // Validate the country
    JsonNode countryNode = root.get("country");
    if (countryNode == null) {
        return error(SELECT_COUNTRY_ERROR);
    }
    if (!countryNode.isTextual()) {
        return error(SELECT_COUNTRY_ERROR);
    }
    String country = countryNode.textValue();
    if (country.isEmpty()) {
        return error(SELECT_COUNTRY_ERROR);
    }
    if (!countries.contains(country)) {
        return error(SELECT_COUNTRY_ERROR);
    }

    ValidateConfigResponse response = new ValidateConfigResponse();
    response.setValid(true);
    return response;
}

From source file:com.basistech.yca.JsonNodeFlattener.java

private static void traverse(JsonNode node, String pathSoFar, Dictionary<String, Object> map)
        throws IOException {
    if (!node.isContainerNode()) {
        Object value;//from   w  w w  .ja v a  2  s .  c  o  m
        if (node.isBigDecimal()) {
            value = node.decimalValue();
        } else if (node.isBigInteger()) {
            value = node.bigIntegerValue();
        } else if (node.isBinary()) {
            value = node.binaryValue();
        } else if (node.isBoolean()) {
            value = node.booleanValue();
        } else if (node.isDouble()) {
            value = node.doubleValue();
        } else if (node.isFloat()) {
            value = node.floatValue();
        } else if (node.isInt()) {
            value = node.intValue();
        } else if (node.isLong()) {
            value = node.longValue();
        } else if (node.isNull()) {
            // NOTE: stupid old Hashtable can't store null values.
            value = NULL;
        } else if (node.isShort()) {
            value = node.shortValue();
        } else if (node.isTextual()) {
            value = node.textValue();
        } else {
            throw new RuntimeException("Unanticipated node " + node);
        }
        map.put(pathSoFar, value);
    } else {
        if (node.isArray()) {
            traverseArray(node, pathSoFar, map);
        } else {
            traverseObject(node, pathSoFar, map);
        }
    }
}

From source file:com.epam.dlab.backendapi.core.commands.CommandParserMock.java

/**
 * Return the value of json property or <b>null</b>.
 *
 * @param jsonNode - Json node./*from w ww  .j  a  va  2s  .  c o m*/
 */
private String getTextValue(JsonNode jsonNode) {
    return jsonNode != null ? jsonNode.textValue() : null;
}

From source file:controllers.PostController.java

@Transactional
@BodyParser.Of(BodyParser.Json.class)
public Result ping() {
    ArrayList<String> missing = new ArrayList<String>();
    JsonNode json = request().body().asJson();
    JsonNode node = json.findValue("device_id");
    String deviceId;/*from  w w w  .  j a va 2 s  . c o m*/
    if (node == null) {
        missing.add("device_id");
        deviceId = ""; // to get rid of warning
    } else {
        deviceId = node.textValue();
    }
    node = json.findValue("tech_id");
    int tech_id;
    if (node == null) {
        missing.add("tech_id");
        tech_id = 0; // to get rid of warning
    } else {
        tech_id = node.intValue();
    }
    if (missing.size() > 0) {
        return missingRequest(missing);
    }
    ObjectNode result = Json.newObject();
    result.put(Version.VERSION_PROJECT, Version.get(Version.VERSION_PROJECT));
    result.put(Version.VERSION_COMPANY, Version.get(Version.VERSION_COMPANY));
    result.put(Version.VERSION_EQUIPMENT, Version.get(Version.VERSION_EQUIPMENT));
    result.put(Version.VERSION_NOTE, Version.get(Version.VERSION_NOTE));
    result.put(Version.VERSION_TRUCK, Version.get(Version.VERSION_TRUCK));
    Technician tech = Technician.find.byId((long) tech_id);
    if (tech != null) {
        if (tech.reset_upload) {
            result.put("reset_upload", true);
            tech.reset_upload = false;
        }
        tech.last_ping = new Date(System.currentTimeMillis());
        tech.save();
    } else {
        Logger.error("ping(): could not find technician with ID " + tech_id);
        result.put("re-register", true);
        result.put("reset_upload", true);
    }
    return ok(result);
}

From source file:eu.eubrazilcc.lvl.oauth2.rest.jackson.LinkedInMapper.java

public Optional<Set<String>> getPositions() {
    final JsonNode node = rootNode.path("positions").path("values");
    Set<String> values = null;
    if (!node.isMissingNode()) {
        for (final JsonNode node2 : node) {
            final JsonNode isCurrentNode = node2.path("isCurrent");
            final JsonNode companyNode = node2.path("company").path("name");
            if (!isCurrentNode.isMissingNode() && !companyNode.isMissingNode()) {
                String value = null;
                if (isCurrentNode.booleanValue() && isNotBlank(value = trimToNull(companyNode.textValue()))) {
                    if (values == null) {
                        values = newHashSet();
                    }//from  www . j a  v a2s  .  c  om
                    values.add(value);
                }
            }
        }
    }
    return fromNullable(values);
}

From source file:com.github.fge.jsonschema.syntax.checkers.SyntaxCheckersTest.java

@DataProvider
protected final Iterator<Object[]> getValueTests() {
    if (valueTests.isMissingNode())
        return Iterators.emptyIterator();

    final List<Object[]> list = Lists.newArrayList();

    String msg;/*www. j  a  v  a 2 s .c  o m*/
    JsonNode msgNode;

    for (final JsonNode node : valueTests) {
        msgNode = node.get("message");
        msg = msgNode == null ? null : BUNDLE.getString(msgNode.textValue());
        list.add(new Object[] { node.get("schema"), msg, node.get("valid").booleanValue(),
                node.get("msgData") });
    }
    return list.iterator();
}