private static void removeDocStrings(JsonNode json) { if (json.isObject()) { ((ObjectNode) json).remove("docString"); } if (json.isObject() || json.isArray()) { json.forEach(GrpcDocServiceTest::removeDocStrings); } }
private static void addExamples(JsonNode json) { json.get("services").forEach(service -> { final String serviceName = service.get("name").textValue(); // Add the method-specific examples. service.get("methods").forEach(method -> { final String methodName = method.get("name").textValue(); final ArrayNode exampleRequests = (ArrayNode) method.get("exampleRequests"); if (TestServiceGrpc.SERVICE_NAME.equals(serviceName) && "UnaryCall".equals(methodName)) { exampleRequests.add("{\n" + " \"payload\": {\n" + " \"body\": \"d29ybGQ=\"\n" + " }\n" + '}'); } }); }); }
private static void removeDocStrings(JsonNode json) { if (json.isObject()) { ((ObjectNode) json).remove("docString"); } if (json.isObject() || json.isArray()) { json.forEach(ThriftDocServiceTest::removeDocStrings); } }
public static List<String> getStringList(JsonNode data, String field) { if (data.has(field)) { List<String> list = new ArrayList<>(); data.get(field).forEach(node -> list.add(node.asText())); return list; } else { return null; } }
public static List<String> getStringList(JsonNode data, String field) { if (data.has(field)) { List<String> list = new ArrayList<>(); data.get(field).forEach(node -> list.add(node.asText())); return list; } else { return null; } }
protected String rewriteRequiredProperties(JsonNode error) { JsonNode missing = error.get("missing"); final StringJoiner missingStringJoiner = new StringJoiner(", "); missing.forEach(it -> missingStringJoiner.add(it.toString())); return String.format(Messages.error_missing_property, missingStringJoiner.toString()); }
protected String rewriteAdditionalProperties(JsonNode error) { final JsonNode unwanted = error.get("unwanted"); final StringJoiner unwantedStringJoiner = new StringJoiner(", "); unwanted.forEach(it -> unwantedStringJoiner.add(it.toString())); return String.format(Messages.error_additional_properties_not_allowed, unwantedStringJoiner.toString()); }
private void processDeletedElements(JsonNode deletedIds) { LOGGER.info("Processing deleted elements"); deletedIds.forEach(element -> { Integer oldId = element.has("old_ringgold_id") ? element.get("old_ringgold_id").asInt() : null; Integer newId = element.has("new_ringgold_id") ? element.get("new_ringgold_id").asInt() : null; deletedElementsMap.put(oldId, newId); }); }
protected String rewriteEnumError(JsonNode error) { final JsonNode value = error.get("value"); final JsonNode enums = error.get("enum"); final StringJoiner enumStringJoiner = new StringJoiner(", "); enums.forEach(it -> enumStringJoiner.add(it.toString())); return String.format(Messages.error_notInEnum, value.asText(), enumStringJoiner.toString()); }
private HashMap<String, String> getObjectHrefs(JsonNode objectNode) { HashMap<String, String> result = new LinkedHashMap<>(); JsonNode linksNode = objectNode.get("_links"); Iterator<String> names = linksNode.fieldNames(); linksNode.forEach(node -> result.put(names.next(), node.get("href").toString().replace("\"", ""))); return result; }
private void processIdentifiers(JsonNode identifiers) { LOGGER.info("Processing identifiers"); identifiers.forEach(identifier -> { Integer ringgoldId = identifier.get("ringgold_id").asInt(); String identifierType = identifier.get("identifier_type").asText(); if(ALLOWED_EXTERNAL_IDENTIFIERS.contains(identifierType)) { identifiersMap.computeIfAbsent(ringgoldId, element -> new ArrayList<>()).add(identifier); } else { LOGGER.info("Ignoring identifier {} of type {}", ringgoldId, identifierType); } }); }
public KubeScannerBuilder withKubeConfigUser(String user) { kubeConfig.path("users").forEach(it -> { if (it.path("name").asText().equals(user)) { String authToken = it.path("user").path("auth-provider").path("config").path("access-token").asText(); withConfig(c -> { logger.info("setting token"); c.withOauthToken(authToken); }); } }); return this; }
@Override public List<String> getBuildNames() { JsonNode node = jsonClient.get("/api/build"); List<String> names = new ArrayList<>(); node.path("builds").forEach((JsonNode numberNode) -> { String name = StringUtils.stripStart(numberNode.path("uri").asText(), "/"); if (StringUtils.isNotBlank(name)) { names.add(name); } }); return names; }
public Observable<JsonEvent> each() { List<JsonEvent> list = new ArrayList<>(); if (objectNodeOrArrayNode instanceof ObjectNode) { return Observable.from(asList(new JsonEvent((ObjectNode) objectNodeOrArrayNode))); } objectNodeOrArrayNode.forEach(node -> list.add(new JsonEvent((ObjectNode) node))); return Observable.from(list); }
private void throwIfInvalid(JsonNode json) throws IOException { if (json instanceof ArrayNode) { json.forEach(rethrowConsumer(val -> { try { StringToEncodedStringOfLimitedValuesConverter.throwIfInvalid(val, this.allowedValues); } catch (IOException e) { throw new IOException(val + e.getMessage(), e); } })); } else { throw new IOException("should be an array."); } }
private List<ValidationStamp> readValidationStamps(JsonNode validationStampIds) { List<ValidationStamp> validationStampList; if (validationStampIds.isArray()) { List<Integer> ids = new ArrayList<>(); validationStampIds.forEach(id -> ids.add(id.asInt())); // Reading the validation stamps and then the names validationStampList = ids.stream() .map(id -> structureService.getValidationStamp(ID.of(id))) .collect(Collectors.toList()); } else { throw new AutoPromotionPropertyCannotParseException("Cannot get the list of validation stamps"); } return validationStampList; }
@Override public Set<VtnServiceId> providerServices(VtnServiceId tServiceId) { checkNotNull(tServiceId); String response = restGet(tServiceId.id()); log.trace("Get provider services {}", response); ObjectMapper mapper = new ObjectMapper(); Set<VtnServiceId> pServices = Sets.newHashSet(); try { JsonNode nodes = mapper.readTree(response); nodes.forEach(node -> pServices.add(VtnServiceId.of(node.asText()))); } catch (IOException e) { log.warn("Failed to get service dependency"); } return pServices; }
private List<ConfluenceAttachment> getNextAttachments(String contentId, int limit, int start) { List<ConfluenceAttachment> attachments = new ArrayList<>(limit); HttpGet getAttachmentsRequest = this.httpRequestFactory.getAttachmentsRequest(contentId, limit, start, "version"); return sendRequestAndFailIfNot20x(getAttachmentsRequest, (response) -> { JsonNode jsonNode = parseJsonResponse(response); jsonNode.withArray("results").forEach(attachment -> attachments.add(extractConfluenceAttachment(attachment))); return attachments; }); }
private List<ConfluencePage> getNextChildPages(String contentId, int limit, int start) { List<ConfluencePage> pages = new ArrayList<>(limit); HttpGet getChildPagesByIdRequest = this.httpRequestFactory.getChildPagesByIdRequest(contentId, limit, start, "version"); return sendRequestAndFailIfNot20x(getChildPagesByIdRequest, (response) -> { JsonNode jsonNode = parseJsonResponse(response); jsonNode.withArray("results").forEach((page) -> pages.add(extractConfluencePageWithoutContent(page))); return pages; }); }