Refine search
private String getTypeName(JsonNode node) { if (node.has("type") && node.get("type").isArray() && node.get("type").size() > 0) { for (JsonNode jsonNode : node.get("type")) { String typeName = jsonNode.asText(); if (!typeName.equals("null")) { return typeName; } } } if (node.has("type") && node.get("type").isTextual()) { return node.get("type").asText(); } return DEFAULT_TYPE_NAME; }
private Map.Entry<String, JsonNode> findAuthNode(final JsonNode config, final String reposName) { final JsonNode auths = config.get("auths"); if (auths != null && auths.size() > 0) { final Iterator<Map.Entry<String, JsonNode>> fields = auths.fields(); while (fields.hasNext()) { final Map.Entry<String, JsonNode> entry = fields.next(); if (entry.getKey().contains("://" + reposName) || entry.getKey().equals(reposName)) { return entry; } } } return null; }
public static ElasticsearchException specificException(Supplier<String> errorMessage, JsonNode errorNode) { final JsonNode rootCauses = errorNode.path("root_cause"); final List<String> reasons = new ArrayList<>(rootCauses.size()); reasons.add(reason.asText()); continue; switch(type.asText()) { case "query_parsing_exception": return buildQueryParsingException(errorMessage, rootCause, reasons); case "index_not_found_exception": final String indexName = rootCause.path("resource.id").asText(); return buildIndexNotFoundException(errorMessage, indexName); case "illegal_argument_exception":
private AuthConfig authConfigUsingHelper(final JsonNode config, final String reposName) throws Exception { final JsonNode credHelpers = config.get("credHelpers"); if (credHelpers != null && credHelpers.size() > 0) { final JsonNode helperNode = credHelpers.get(reposName); if (helperNode != null && helperNode.isTextual()) { final String helper = helperNode.asText(); return runCredentialProvider(reposName, helper); } } return null; }
@Override @SuppressWarnings("unchecked") public <T> T[] asArray(Class<T> tClazz) throws JWTDecodeException { if (!data.isArray()) { return null; } T[] arr = (T[]) Array.newInstance(tClazz, data.size()); for (int i = 0; i < data.size(); i++) { try { arr[i] = objectReader.treeToValue(data.get(i), tClazz); } catch (JsonProcessingException e) { throw new JWTDecodeException("Couldn't map the Claim's array contents to " + tClazz.getSimpleName(), e); } } return arr; }
@Override public PathDetail deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode pathDetail = jp.readValueAsTree(); if (pathDetail.size() != 3) throw new JsonParseException(jp, "PathDetail array must have exactly 3 entries but was " + pathDetail.size()); JsonNode from = pathDetail.get(0); JsonNode to = pathDetail.get(1); JsonNode val = pathDetail.get(2); PathDetail pd; if (val.isBoolean()) pd = new PathDetail(val.asBoolean()); else if (val.isLong()) pd = new PathDetail(val.asLong()); else if (val.isInt()) pd = new PathDetail(val.asInt()); else if (val.isDouble()) pd = new PathDetail(val.asDouble()); else if (val.isTextual()) pd = new PathDetail(val.asText()); else throw new JsonParseException(jp, "Unsupported type of PathDetail value " + pathDetail.getNodeType().name()); pd.setFirst(from.asInt()); pd.setLast(to.asInt()); return pd; } }
/** * Transforms the {@link JsonNode} into a map to integrate with the {@link SignatureChecker} utility. * * @param messageJson JSON of message. * @return Transformed map. */ private Map<String, String> toMap(JsonNode messageJson) { Map<String, String> fields = new HashMap<String, String>(messageJson.size()); Iterator<Map.Entry<String, JsonNode>> jsonFields = messageJson.fields(); while (jsonFields.hasNext()) { Map.Entry<String, JsonNode> next = jsonFields.next(); fields.put(next.getKey(), next.getValue().asText()); } return fields; }
/** * Returns the exposed entry points in a Map. The key is the ID of a given * resource collection and the value its managed type * * @return Map<String, String> Resource ID / Managed type, empty otherwise */ public Map<String, String> getRootEndpointMap() { JsonNode collectionArrayJsonNode = getCollectionJsonNode(); if (!collectionArrayJsonNode.isArray() || (collectionArrayJsonNode.size() == 0)) { if (_log.isDebugEnabled()) { _log.debug( "Unable to fetch the resources from the entry point"); } return Collections.emptyMap(); } Map<String, String> rootEndpointMap = new TreeMap<>(); for (final JsonNode collectionJsonNode : collectionArrayJsonNode) { JsonNode idJsonNode = collectionJsonNode.path(JSONLDConstants.ID); String managedType = ApioUtils.getManagedType(collectionJsonNode); rootEndpointMap.put(idJsonNode.asText(), managedType); } return Collections.unmodifiableMap(rootEndpointMap); }
protected JsonNode findJsonNode(JsonNode resource, String nodeName) { JsonNode jsonNode = resource.path(nodeName); if (_log.isDebugEnabled()) { if (jsonNode.isMissingNode()) { _log.debug("Unable to find the \"{}\" node", nodeName); } if (jsonNode.isArray() && (jsonNode.size() == 0)) { _log.debug("The \"{}\" array node is empty", jsonNode); } } return jsonNode; }
protected List<String> getActiveValueList(List<String> originalValues, String propertyName, ObjectNode taskElementProperties) { List<String> activeValues = originalValues; if (taskElementProperties != null) { JsonNode overrideValuesNode = taskElementProperties.get(propertyName); if (overrideValuesNode != null) { if (overrideValuesNode.isNull() || !overrideValuesNode.isArray() || overrideValuesNode.size() == 0) { activeValues = null; } else { activeValues = new ArrayList<String>(); for (JsonNode valueNode : overrideValuesNode) { activeValues.add(valueNode.asText()); } } } } return activeValues; } }
private static List<JmesPathExpression> getChildren(JsonNode jsonNode){ if(jsonNode.get("children").size() < 1) { throw new RuntimeException("Expected one or more arguments"); } Iterator<JsonNode> children = jsonNode.get("children").elements(); final List<JmesPathExpression> childrenList = new ArrayList<>(); while (children.hasNext()) { childrenList.add(fromAstJsonToAstJava(children.next())); } return childrenList; }
private static String serializeRow(JsonNode row, Map<Integer, Integer> expectedToActualColMap) { StringBuilder sb = new StringBuilder(); final int numCols = row.size(); sb.append(numCols).append('_'); for (int i = 0; i < numCols; i++) { String toAppend; if (expectedToActualColMap == null) { toAppend = row.get(i).asText(); } else { toAppend = row.get(expectedToActualColMap.get(i)).asText(); } // For number value, uniform the format and do fuzzy comparison try { double numValue = Double.parseDouble(toAppend); sb.append((int) (numValue * 100)).append('_'); } catch (NumberFormatException e) { sb.append(toAppend).append('_'); } } return sb.toString(); }
private ObjectNode arraySchema(JsonNode exampleArray) { ObjectNode schema = this.objectMapper.createObjectNode(); schema.put("type", "array"); if (exampleArray.size() > 0) { JsonNode exampleItem = exampleArray.get(0).isObject() ? mergeArrayItems(exampleArray) : exampleArray.get(0); schema.set("items", schemaFromExample(exampleItem)); } return schema; }
private void addEnumConstants(JsonNode node, JDefinedClass _enum, JsonNode customNames, JType type) { Collection<String> existingConstantNames = new ArrayList<>(); for (int i = 0; i < node.size(); i++) { JsonNode value = node.path(i); if (!value.isNull()) { String constantName = getConstantName(value.asText(), customNames.path(i).asText()); constantName = makeUnique(constantName, existingConstantNames); existingConstantNames.add(constantName); JEnumConstant constant = _enum.enumConstant(constantName); constant.arg(DefaultRule.getDefaultValue(type, value)); ruleFactory.getAnnotator().enumConstant(_enum, constant, value.asText()); } } }
private static JsonNode _findJsonNode(JsonNode resource, String nodeName) { JsonNode jsonNode = resource.path(nodeName); if (_log.isDebugEnabled()) { if (jsonNode.isMissingNode()) { _log.debug("Unable to find the \"{}\" node", nodeName); } if (jsonNode.isArray() && (jsonNode.size() == 0)) { _log.debug("The \"{}\" array node is empty", jsonNode); } } return jsonNode; }
List<String> getStringOrArray(Map<String, JsonNode> tree, String claimName) throws JWTDecodeException { JsonNode node = tree.get(claimName); if (node == null || node.isNull() || !(node.isArray() || node.isTextual())) { return null; } if (node.isTextual() && !node.asText().isEmpty()) { return Collections.singletonList(node.asText()); } List<String> list = new ArrayList<>(node.size()); for (int i = 0; i < node.size(); i++) { try { list.add(objectReader.treeToValue(node.get(i), String.class)); } catch (JsonProcessingException e) { throw new JWTDecodeException("Couldn't map the Claim's array contents to String", e); } } return list; }
@Override public Object deserialize(JsonNode n, ObjectMapper mapper) { List<Object> o = new ArrayList<Object>(); try { logger.debug("using custom array deserializer"); for(int i=0; i<n.size(); i++) { o.add(parent.deserialize(n.get(i), mapper)); } } catch (Exception e) { logger.error("exception deserializing Collection ", e); o = null; } return o; }