use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project walkmod-core by walkmod.
the class SetReaderYMLAction method doAction.
@Override
public void doAction(JsonNode node) throws Exception {
if (node.has("chains") && (chain == null || "".equals(chain.trim()))) {
chain = "default";
}
ObjectNode reader = null;
ObjectMapper mapper = provider.getObjectMapper();
if (chain != null && !"".equals(chain.trim())) {
if (node.has("chains")) {
JsonNode chainsListNode = node.get("chains");
if (chainsListNode.isArray()) {
Iterator<JsonNode> it = chainsListNode.iterator();
boolean found = false;
while (it.hasNext() && !found) {
JsonNode current = it.next();
if (current.has("name")) {
String name = current.get("name").asText();
found = name.equals(chain);
if (found) {
if (current.has("reader")) {
reader = (ObjectNode) current.get("reader");
} else {
reader = new ObjectNode(mapper.getNodeFactory());
}
if (type != null && !"".equals(type.trim())) {
reader.set("type", new TextNode(type));
}
if (path != null && !"".equals(path.trim())) {
reader.set("path", new TextNode(path));
}
if (params != null && !params.isEmpty()) {
ObjectNode paramsObject = null;
if (reader.has("params")) {
paramsObject = (ObjectNode) reader.get("params");
} else {
paramsObject = new ObjectNode(mapper.getNodeFactory());
reader.set("params", paramsObject);
}
Set<String> keys = params.keySet();
for (String key : keys) {
paramsObject.put(key, params.get(key).toString());
}
}
}
}
}
}
}
if (reader != null) {
provider.write(node);
}
} else {
if (!node.has("chains")) {
ArrayNode chains = new ArrayNode(mapper.getNodeFactory());
ObjectNode defaultChain = new ObjectNode(mapper.getNodeFactory());
defaultChain.set("name", new TextNode("default"));
ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory());
if (type != null && !"".equals(type.trim())) {
readerNode.set("type", new TextNode(type));
}
if (path != null && !"".equals(path.trim())) {
readerNode.set("path", new TextNode(path));
}
if (params != null && !params.isEmpty()) {
ObjectNode paramsObject = new ObjectNode(mapper.getNodeFactory());
Set<String> keys = params.keySet();
for (String key : keys) {
paramsObject.put(key, params.get(key).toString());
}
readerNode.set("params", paramsObject);
}
defaultChain.set("reader", readerNode);
if (node.has("transformations")) {
defaultChain.set("transformations", node.get("transformations"));
}
chains.add(defaultChain);
provider.write(chains);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project solr-document-store by DBCDK.
the class StatusBean method createQueueStatusNode.
private JsonNode createQueueStatusNode() {
try (Connection connection = dataSource.getConnection();
Statement stmt = connection.createStatement();
PreparedStatement prepStmt = connection.prepareStatement("SELECT CAST(EXTRACT('epoch' FROM NOW() - dequeueafter) AS INTEGER) FROM queue WHERE consumer = ? ORDER BY dequeueafter LIMIT 1");
ResultSet resultSet = stmt.executeQuery("SELECT consumer, COUNT(*) FROM queue GROUP BY consumer")) {
ObjectNode node = O.createObjectNode();
while (resultSet.next()) {
int i = 0;
String consumer = resultSet.getString(++i);
int count = resultSet.getInt(++i);
Integer age = null;
prepStmt.setString(1, consumer);
try (ResultSet preResultSet = prepStmt.executeQuery()) {
if (preResultSet.next()) {
age = preResultSet.getInt(1);
}
}
ObjectNode scope = node.putObject(consumer);
scope.put("count", count);
scope.put("age", age);
}
return node;
} catch (SQLException ex) {
log.error("Sql error counting queue entries: {}", ex.getMessage());
log.debug("Sql error counting queue entries: ", ex);
return new TextNode("SQL Exception");
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project batfish by batfish.
the class JsonPathResult method extractValuesFromSuffix.
private void extractValuesFromSuffix(String displayVar, Extraction extraction, JsonPathExtractionHint jpeHint) {
for (Entry<String, JsonPathResultEntry> entry : _result.entrySet()) {
if (!_displayValues.containsKey(entry.getKey())) {
_displayValues.put(entry.getKey(), new HashMap<>());
}
if (entry.getValue().getSuffix() == null) {
throw new BatfishException("Cannot compute suffix-based display values with null suffix. " + "(Was suffix set to True in the original JsonPath Query?)");
}
Configuration.setDefaults(BatfishJsonPathDefaults.INSTANCE);
Configuration c = (new ConfigurationBuilder()).build();
Object jsonObject = JsonPath.parse(entry.getValue().getSuffix(), c).json();
JsonPathQuery query = new JsonPathQuery(jpeHint.getFilter(), true);
List<JsonNode> extractedList = new LinkedList<>();
switch(jpeHint.getUse()) {
case FUNCOFSUFFIX:
{
if (!extraction.getSchemaAsObject().isIntOrIntList()) {
throw new BatfishException("schema must be INT(LIST) with funcofsuffix-based extraction hint");
}
Object result = JsonPathAnswerer.computePathFunction(jsonObject, query);
if (result != null) {
if (result instanceof Integer) {
extractedList.add(new IntNode((Integer) result));
} else if (result instanceof ArrayNode) {
for (JsonNode node : (ArrayNode) result) {
if (!(node instanceof IntNode)) {
throw new BatfishException("Got non-integer result from path function after filter " + query.getPath());
}
extractedList.add(node);
}
} else {
throw new BatfishException("Unknown result type from computePathFunction");
}
}
}
break;
case PREFIXOFSUFFIX:
case SUFFIXOFSUFFIX:
{
JsonPathResult filterResult = JsonPathAnswerer.computeResult(jsonObject, query);
Map<String, JsonPathResultEntry> filterResultEntries = filterResult.getResult();
for (Entry<String, JsonPathResultEntry> resultEntry : filterResultEntries.entrySet()) {
JsonNode value = (jpeHint.getUse() == UseType.PREFIXOFSUFFIX) ? new TextNode(resultEntry.getValue().getPrefixPart(jpeHint.getIndex())) : resultEntry.getValue().getSuffix();
confirmValueType(value, extraction.getSchemaAsObject().getBaseType());
extractedList.add(value);
}
}
break;
default:
throw new BatfishException("Unknown UseType " + jpeHint.getUse());
}
if (extractedList.size() == 0) {
throw new BatfishException("Got no results after filtering suffix values of the answer" + "\nFilter: " + jpeHint.getFilter() + "\nJson: " + jsonObject);
}
if (extraction.getSchemaAsObject().isList()) {
ArrayNode arrayNode = BatfishObjectMapper.mapper().valueToTree(extractedList);
_displayValues.get(entry.getKey()).put(displayVar, arrayNode);
} else {
if (extractedList.size() > 1) {
throw new BatfishException("Got multiple results after filtering suffix values " + " of the answer, but the display type is non-list");
}
_displayValues.get(entry.getKey()).put(displayVar, extractedList.get(0));
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project graylog2-server by Graylog2.
the class NodeAdapterES6Test method buildVersionJsonObject.
private JsonNode buildVersionJsonObject(String foobar) {
final ObjectNode versionObject = objectMapper.createObjectNode();
versionObject.set("number", new TextNode(foobar));
final ObjectNode jsonObject = objectMapper.createObjectNode();
jsonObject.set("version", versionObject);
return jsonObject;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project graylog2-server by Graylog2.
the class JestUtilsTest method executeWithUnsuccessfulResponseAndErrorDetails.
@Test
public void executeWithUnsuccessfulResponseAndErrorDetails() throws Exception {
final Ping request = new Ping.Builder().build();
final JestResult resultMock = mock(JestResult.class);
when(resultMock.isSucceeded()).thenReturn(false);
final ObjectNode rootCauseStub = objectMapper.createObjectNode();
rootCauseStub.set("reason", new TextNode("foobar"));
final ArrayNode rootCausesStub = objectMapper.createArrayNode();
rootCausesStub.add(rootCauseStub);
final ObjectNode errorStub = objectMapper.createObjectNode();
errorStub.set("root_cause", rootCausesStub);
final ObjectNode responseStub = objectMapper.createObjectNode();
responseStub.set("error", errorStub);
when(resultMock.getJsonObject()).thenReturn(responseStub);
when(clientMock.execute(request)).thenReturn(resultMock);
try {
JestUtils.execute(clientMock, request, () -> "BOOM");
fail("Expected ElasticsearchException to be thrown");
} catch (ElasticsearchException e) {
assertThat(e).hasMessageStartingWith("BOOM").hasMessageEndingWith("foobar").hasNoSuppressedExceptions();
assertThat(e.getErrorDetails()).containsExactly("foobar");
}
}
Aggregations