List of usage examples for com.fasterxml.jackson.databind.node ArrayNode elements
public Iterator<JsonNode> elements()
From source file:nl.knaw.huygens.timbuctoo.storage.mongo.MongoStorage.java
private boolean doesVariationExist(String variation, ObjectNode objectTree) { ArrayNode variations = (ArrayNode) objectTree.get(DomainEntity.VARIATIONS); for (Iterator<JsonNode> variationIterator = variations.elements(); variationIterator.hasNext();) { if (Objects.equal(variation, variationIterator.next().asText())) { return true; }/*from w w w . j a va 2 s . c o m*/ } return false; }
From source file:com.microsoft.azure.AzureVMManagementServiceDelegate.java
/** * Creates a new deployment of VMs based on the provided template * * @param template Template to deploy// www .j av a 2 s.c o m * @param numberOfAgents Number of agents to create * @return The base name for the VMs that were created * @throws AzureCloudException * @throws java.io.IOException */ public static AzureVMDeploymentInfo createDeployment(final AzureVMAgentTemplate template, final int numberOfAgents) throws AzureCloudException, IOException { InputStream embeddedTemplate = null; InputStream fragmentStream = null; try { LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: createDeployment: Initializing deployment for agentTemplate {0}", template.getTemplateName()); Configuration config = ServiceDelegateHelper.getConfiguration(template); final ResourceManagementClient client = ServiceDelegateHelper.getResourceManagementClient(config); final Date timestamp = new Date(System.currentTimeMillis()); final String deploymentName = AzureUtil.getDeploymentName(template.getTemplateName(), timestamp); final String vmBaseName = AzureUtil.getVMBaseName(template.getTemplateName(), deploymentName, template.getOsType(), numberOfAgents); final String locationName = getLocationName(template.getLocation()); if (!template.getResourceGroupName().matches(Constants.DEFAULT_RESOURCE_GROUP_PATTERN)) { LOGGER.log(Level.SEVERE, "AzureVMManagementServiceDelegate: createDeployment: ResourceGroup Name {0} is invalid. It should be 1-64 alphanumeric characters", new Object[] { template.getResourceGroupName() }); throw new Exception("ResourceGroup Name is invalid"); } final String resourceGroupName = template.getResourceGroupName(); LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: createDeployment: Creating a new deployment {0} with VM base name {1}", new Object[] { deploymentName, vmBaseName }); client.getResourceGroupsOperations().createOrUpdate(resourceGroupName, new ResourceGroup(locationName)); final Deployment deployment = new Deployment(); final DeploymentProperties properties = new DeploymentProperties(); deployment.setProperties(properties); final boolean useCustomScriptExtension = template.getOsType().equals(Constants.OS_TYPE_WINDOWS) && !StringUtils.isBlank(template.getInitScript()) && template.getAgentLaunchMethod().equals(Constants.LAUNCH_METHOD_JNLP); // check if a custom image id has been provided otherwise work with publisher and offer if (template.getImageReferenceType().equals(IMAGE_CUSTOM_REFERENCE)) { if (useCustomScriptExtension) { LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: createDeployment: Use embedded deployment template {0}", EMBEDDED_TEMPLATE_IMAGE_WITH_SCRIPT_FILENAME); embeddedTemplate = AzureVMManagementServiceDelegate.class .getResourceAsStream(EMBEDDED_TEMPLATE_IMAGE_WITH_SCRIPT_FILENAME); } else { LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: createDeployment: Use embedded deployment template (with script) {0}", EMBEDDED_TEMPLATE_IMAGE_FILENAME); embeddedTemplate = AzureVMManagementServiceDelegate.class .getResourceAsStream(EMBEDDED_TEMPLATE_IMAGE_FILENAME); } } else { if (useCustomScriptExtension) { LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: createDeployment: Use embedded deployment template (with script) {0}", EMBEDDED_TEMPLATE_WITH_SCRIPT_FILENAME); embeddedTemplate = AzureVMManagementServiceDelegate.class .getResourceAsStream(EMBEDDED_TEMPLATE_WITH_SCRIPT_FILENAME); } else { LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: createDeployment: Use embedded deployment template {0}", EMBEDDED_TEMPLATE_FILENAME); embeddedTemplate = AzureVMManagementServiceDelegate.class .getResourceAsStream(EMBEDDED_TEMPLATE_FILENAME); } } final ObjectMapper mapper = new ObjectMapper(); final JsonNode tmp = mapper.readTree(embeddedTemplate); // Add count variable for loop.... final ObjectNode count = mapper.createObjectNode(); count.put("type", "int"); count.put("defaultValue", numberOfAgents); ObjectNode.class.cast(tmp.get("parameters")).replace("count", count); ObjectNode.class.cast(tmp.get("variables")).put("vmName", vmBaseName); ObjectNode.class.cast(tmp.get("variables")).put("location", locationName); if (StringUtils.isNotBlank(template.getImagePublisher())) { ObjectNode.class.cast(tmp.get("variables")).put("imagePublisher", template.getImagePublisher()); } if (StringUtils.isNotBlank(template.getImageOffer())) { ObjectNode.class.cast(tmp.get("variables")).put("imageOffer", template.getImageOffer()); } if (StringUtils.isNotBlank(template.getImageSku())) { ObjectNode.class.cast(tmp.get("variables")).put("imageSku", template.getImageSku()); } if (StringUtils.isNotBlank(template.getOsType())) { ObjectNode.class.cast(tmp.get("variables")).put("osType", template.getOsType()); } if (StringUtils.isNotBlank(template.getImage())) { ObjectNode.class.cast(tmp.get("variables")).put("image", template.getImage()); } // If using the custom script extension (vs. SSH) to startup the powershell scripts, // add variables for that and upload the init script to the storage account if (useCustomScriptExtension) { ObjectNode.class.cast(tmp.get("variables")).put("jenkinsServerURL", Jenkins.getInstance().getRootUrl()); // Calculate the client secrets. The secrets are based off the machine name, ArrayNode clientSecretsNode = ObjectNode.class.cast(tmp.get("variables")).putArray("clientSecrets"); for (int i = 0; i < numberOfAgents; i++) { clientSecretsNode .add(JnlpSlaveAgentProtocol.SLAVE_SECRET.mac(String.format("%s%d", vmBaseName, i))); } // Upload the startup script to blob storage String scriptName = String.format("%s%s", deploymentName, "init.ps1"); String scriptUri = uploadCustomScript(template, scriptName); ObjectNode.class.cast(tmp.get("variables")).put("startupScriptURI", scriptUri); ObjectNode.class.cast(tmp.get("variables")).put("startupScriptName", scriptName); String storageAccountKey = ServiceDelegateHelper.getStorageManagementClient(config) .getStorageAccountsOperations() .listKeys(template.getResourceGroupName(), template.getStorageAccountName()) .getStorageAccountKeys().getKey1(); final ObjectNode storageAccountKeyNode = mapper.createObjectNode(); storageAccountKeyNode.put("type", "secureString"); storageAccountKeyNode.put("defaultValue", storageAccountKey); // Add the storage account key ObjectNode.class.cast(tmp.get("parameters")).replace("storageAccountKey", storageAccountKeyNode); } ObjectNode.class.cast(tmp.get("variables")).put("vmSize", template.getVirtualMachineSize()); // Grab the username/pass StandardUsernamePasswordCredentials creds = AzureUtil.getCredentials(template.getCredentialsId()); ObjectNode.class.cast(tmp.get("variables")).put("adminUsername", creds.getUsername()); ObjectNode.class.cast(tmp.get("variables")).put("adminPassword", creds.getPassword().getPlainText()); if (StringUtils.isNotBlank(template.getStorageAccountName())) { ObjectNode.class.cast(tmp.get("variables")).put("storageAccountName", template.getStorageAccountName()); } // Network properties. If the vnet name isn't blank then // then subnet name can't be either (based on verification rules) if (StringUtils.isNotBlank(template.getVirtualNetworkName())) { ObjectNode.class.cast(tmp.get("variables")).put("virtualNetworkName", template.getVirtualNetworkName()); ObjectNode.class.cast(tmp.get("variables")).put("subnetName", template.getSubnetName()); } else { // Add the definition of the vnet and subnet into the template final String virtualNetworkName = Constants.DEFAULT_VNET_NAME; final String subnetName = Constants.DEFAULT_SUBNET_NAME; ObjectNode.class.cast(tmp.get("variables")).put("virtualNetworkName", virtualNetworkName); ObjectNode.class.cast(tmp.get("variables")).put("subnetName", subnetName); // Read the vnet fragment fragmentStream = AzureVMManagementServiceDelegate.class .getResourceAsStream(VIRTUAL_NETWORK_TEMPLATE_FRAGMENT_FILENAME); final JsonNode virtualNetworkFragment = mapper.readTree(fragmentStream); // Add the virtual network fragment ArrayNode.class.cast(tmp.get("resources")).add(virtualNetworkFragment); // Because we created/updated this in the template, we need to add the appropriate // dependsOn node to the networkInterface // Microsoft.Network/virtualNetworks/<vnet name> // Find the network interfaces node ArrayNode resourcesNodes = ArrayNode.class.cast(tmp.get("resources")); Iterator<JsonNode> resourcesNodesIter = resourcesNodes.elements(); while (resourcesNodesIter.hasNext()) { JsonNode resourcesNode = resourcesNodesIter.next(); JsonNode typeNode = resourcesNode.get("type"); if (typeNode == null || !typeNode.asText().equals("Microsoft.Network/networkInterfaces")) { continue; } // Find the dependsOn node ArrayNode dependsOnNode = ArrayNode.class.cast(resourcesNode.get("dependsOn")); // Add to the depends on node. dependsOnNode .add("[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"); break; } } // Deployment .... properties.setMode(DeploymentMode.Incremental); properties.setTemplate(tmp.toString()); // Register the deployment for cleanup AzureVMAgentCleanUpTask.registerDeployment(template.getAzureCloud().name, template.getResourceGroupName(), deploymentName); // Create the deployment client.getDeploymentsOperations().createOrUpdate(template.getResourceGroupName(), deploymentName, deployment); return new AzureVMDeploymentInfo(deploymentName, vmBaseName, numberOfAgents); } catch (Exception e) { LOGGER.log(Level.SEVERE, "AzureVMManagementServiceDelegate: deployment: Unable to deploy", e); // Pass the info off to the template so that it can be queued for update. template.handleTemplateProvisioningFailure(e.getMessage(), FailureStage.PROVISIONING); throw new AzureCloudException(e); } finally { if (embeddedTemplate != null) embeddedTemplate.close(); if (fragmentStream != null) fragmentStream.close(); } }
From source file:com.microsoft.azure.vmagent.AzureVMManagementServiceDelegate.java
private static void AddNSGNode(final JsonNode template, final ObjectMapper mapper, final String nsgName) throws IOException { ObjectNode.class.cast(template.get("variables")).put("nsgName", nsgName); ArrayNode resourcesNodes = ArrayNode.class.cast(template.get("resources")); Iterator<JsonNode> resourcesNodesIter = resourcesNodes.elements(); while (resourcesNodesIter.hasNext()) { JsonNode resourcesNode = resourcesNodesIter.next(); JsonNode typeNode = resourcesNode.get("type"); if (typeNode == null || !typeNode.asText().equals("Microsoft.Network/networkInterfaces")) { continue; }//www. jav a 2 s . c o m ObjectNode nsgNode = mapper.createObjectNode(); nsgNode.put("id", "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"); // Find the properties node // We will attach the provided NSG and not check if it's valid because that's done in the verification step ObjectNode propertiesNode = ObjectNode.class.cast(resourcesNode.get("properties")); propertiesNode.set("networkSecurityGroup", nsgNode); break; } }
From source file:com.redhat.lightblue.eval.ForEachExpressionEvaluator.java
private boolean update(JsonDoc doc, Path contextPath, UpdateInfo updateInfo) { boolean ret = false; // Get a reference to the array field, and iterate all elements in the array ArrayNode arrayNode = (ArrayNode) doc.get(new Path(contextPath, updateInfo.field)); LOGGER.debug("Array node {}={}", updateInfo.field, arrayNode); ArrayElement elementMd = updateInfo.fieldMd.getElement(); if (arrayNode != null) { int index = 0; MutablePath itrPath = new MutablePath(contextPath); itrPath.push(updateInfo.field);/*www . j a v a2s . co m*/ MutablePath arrSizePath = itrPath.copy(); arrSizePath.setLast(arrSizePath.getLast() + "#"); arrSizePath.rewriteIndexes(contextPath); itrPath.push(index); // Copy the nodes to a separate list, so we iterate on the // new copy, and modify the original ArrayList<JsonNode> nodes = new ArrayList<>(); for (Iterator<JsonNode> itr = arrayNode.elements(); itr.hasNext();) { nodes.add(itr.next()); } for (JsonNode elementNode : nodes) { itrPath.setLast(index); Path elementPath = itrPath.immutableCopy(); LOGGER.debug("itr:{}", elementPath); QueryEvaluationContext ctx = new QueryEvaluationContext(elementNode, elementPath); if (updateInfo.queryEvaluator.evaluate(ctx)) { LOGGER.debug("query matches {}", elementPath); LOGGER.debug("Calling updater {}", updateInfo.updater); if (updateInfo.updater.update(doc, elementMd, elementPath)) { LOGGER.debug("Updater {} returns {}", updateInfo.updater, true); ret = true; // Removal shifts nodes down if (updateInfo.updater instanceof RemoveEvaluator) { index--; } } else { LOGGER.debug("Updater {} return false", updateInfo.updater); } } else { LOGGER.debug("query does not match {}", elementPath); } index++; } if (ret) { doc.modify(arrSizePath, factory.numberNode(arrayNode.size()), false); } } return ret; }
From source file:com.microsoft.azure.vmagent.AzureVMManagementServiceDelegate.java
private static void AddDefaultVNetResourceNode(final JsonNode template, final ObjectMapper mapper) throws IOException { InputStream fragmentStream = null; try {//from w w w .j av a 2 s .c o m // Add the definition of the vnet and subnet into the template final String virtualNetworkName = Constants.DEFAULT_VNET_NAME; final String subnetName = Constants.DEFAULT_SUBNET_NAME; ObjectNode.class.cast(template.get("variables")).put("virtualNetworkName", virtualNetworkName); ObjectNode.class.cast(template.get("variables")).put("subnetName", subnetName); // Read the vnet fragment fragmentStream = AzureVMManagementServiceDelegate.class .getResourceAsStream(VIRTUAL_NETWORK_TEMPLATE_FRAGMENT_FILENAME); final JsonNode virtualNetworkFragment = mapper.readTree(fragmentStream); // Add the virtual network fragment ArrayNode.class.cast(template.get("resources")).add(virtualNetworkFragment); // Because we created/updated this in the template, we need to add the appropriate // dependsOn node to the networkInterface // Microsoft.Network/virtualNetworks/<vnet name> // Find the network interfaces node ArrayNode resourcesNodes = ArrayNode.class.cast(template.get("resources")); Iterator<JsonNode> resourcesNodesIter = resourcesNodes.elements(); while (resourcesNodesIter.hasNext()) { JsonNode resourcesNode = resourcesNodesIter.next(); JsonNode typeNode = resourcesNode.get("type"); if (typeNode == null || !typeNode.asText().equals("Microsoft.Network/networkInterfaces")) { continue; } // Find the dependsOn node ArrayNode dependsOnNode = ArrayNode.class.cast(resourcesNode.get("dependsOn")); // Add to the depends on node. dependsOnNode .add("[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"); break; } } catch (Exception e) { throw e; } finally { if (fragmentStream != null) { fragmentStream.close(); } } }
From source file:com.microsoft.azure.vmagent.AzureVMManagementServiceDelegate.java
private static void AddPublicIPResourceNode(final JsonNode template, final ObjectMapper mapper) throws IOException { final String ipName = "variables('vmName'), copyIndex(), 'IPName'"; try (InputStream fragmentStream = AzureVMManagementServiceDelegate.class .getResourceAsStream(PUBLIC_IP_FRAGMENT_FILENAME)) { final JsonNode publicIPFragment = mapper.readTree(fragmentStream); // Add the virtual network fragment ArrayNode.class.cast(template.get("resources")).add(publicIPFragment); // Because we created/updated this in the template, we need to add the appropriate // dependsOn node to the networkInterface and the ipConfigurations properties // "[concat('Microsoft.Network/publicIPAddresses/', variables('vmName'), copyIndex(), 'IPName')]" // Find the network interfaces node ArrayNode resourcesNodes = ArrayNode.class.cast(template.get("resources")); Iterator<JsonNode> resourcesNodesIter = resourcesNodes.elements(); while (resourcesNodesIter.hasNext()) { JsonNode resourcesNode = resourcesNodesIter.next(); JsonNode typeNode = resourcesNode.get("type"); if (typeNode == null || !typeNode.asText().equals("Microsoft.Network/networkInterfaces")) { continue; }/* w w w .j av a 2s. co m*/ // Find the dependsOn node ArrayNode dependsOnNode = ArrayNode.class.cast(resourcesNode.get("dependsOn")); // Add to the depends on node. dependsOnNode.add("[concat('Microsoft.Network/publicIPAddresses/'," + ipName + ")]"); //Find the ipConfigurations/ipconfig1 node ArrayNode ipConfigurationsNode = ArrayNode.class .cast(resourcesNode.get("properties").get("ipConfigurations")); Iterator<JsonNode> ipConfigNodeIter = ipConfigurationsNode.elements(); while (ipConfigNodeIter.hasNext()) { JsonNode ipConfigNode = ipConfigNodeIter.next(); JsonNode nameNode = ipConfigNode.get("name"); if (nameNode == null || !nameNode.asText().equals("ipconfig1")) { continue; } //find the properties node ObjectNode propertiesNode = ObjectNode.class.cast(ipConfigNode.get("properties")); //add the publicIPAddress node ObjectNode publicIPIdNode = mapper.createObjectNode(); publicIPIdNode.put("id", "[resourceId('Microsoft.Network/publicIPAddresses', concat(" + ipName + "))]"); // propertiesNode.putObject("publicIPAddress").put propertiesNode.set("publicIPAddress", publicIPIdNode); break; } break; } } }
From source file:org.wrml.runtime.format.application.schema.json.JsonSchema.java
private void parseExtensions(final ObjectNode rootNode, final SyntaxLoader syntaxLoader) { // v3 uses the extends keyword if (rootNode.has(PropertyType.Extends.getName())) { final JsonNode extendsJsonNode = rootNode.get(PropertyType.Extends.getName()); if (extendsJsonNode instanceof ArrayNode) { final ArrayNode extendsArrayNode = (ArrayNode) extendsJsonNode; final Iterator<JsonNode> elements = extendsArrayNode.elements(); while (elements.hasNext()) { final JsonNode baseSchemaUriNode = elements.next(); final String baseSchemaUriString = baseSchemaUriNode.asText(); if (baseSchemaUriString != null && !baseSchemaUriString.isEmpty()) { final URI baseSchemaUri = syntaxLoader.parseSyntacticText(baseSchemaUriString, URI.class); if (baseSchemaUri != null) { _ExtendsSet.add(baseSchemaUri); }//w w w . j ava 2 s .c o m } } } else if (extendsJsonNode instanceof TextNode) { final String baseSchemaUriString = extendsJsonNode.asText(); if (baseSchemaUriString != null && !baseSchemaUriString.isEmpty()) { final URI baseSchemaUri = syntaxLoader.parseSyntacticText(baseSchemaUriString, URI.class); if (baseSchemaUri != null) { _ExtendsSet.add(baseSchemaUri); } } } } // v4 uses the allOf keyword if (rootNode.has(PropertyType.AllOf.getName())) { final JsonNode allOfJsonNode = rootNode.get(PropertyType.AllOf.getName()); // This element type MUST be an array if (allOfJsonNode instanceof ArrayNode) { final ArrayNode allOfArrayNode = (ArrayNode) allOfJsonNode; final Iterator<JsonNode> elements = allOfArrayNode.elements(); while (elements.hasNext()) { final JsonNode schemaNode = elements.next(); final JsonNode baseSchemaUriNode = schemaNode.get(PropertyType.$Ref.getName()); if (baseSchemaUriNode != null) { final URI baseSchemaUri = syntaxLoader.parseSyntacticText(baseSchemaUriNode.asText(), URI.class); if (baseSchemaUri != null) { _ExtendsSet.add(baseSchemaUri); } } } } } }
From source file:com.appdynamics.analytics.processor.event.ElasticSearchEventService.java
private String[] arrayOfStringsFromNode(ArrayNode sourceNode) { /* 1595 */ String[] ary = new String[sourceNode.size()]; /* 1596 */ Iterator<JsonNode> elements = sourceNode.elements(); /* 1597 */ int i = 0; /* 1598 */ while (elements.hasNext()) { /* 1599 */ JsonNode elem = (JsonNode) elements.next(); /* 1600 */ ary[(i++)] = (elem.isTextual() ? elem.asText() : elem.toString()); /* */ } /* 1602 */ return ary; /* */ }/*from www. ja v a2s . c o m*/
From source file:org.wrml.runtime.schema.generator.SchemaGenerator.java
public Schema generateSchema(final JsonSchema jsonSchema, final URI... baseSchemaUris) throws SchemaGeneratorException { final URI schemaUri = jsonSchema.getId(); final Context context = getContext(); final Schema schema = context.newModel(getSchemaLoader().getSchemaDimensions()); schema.setUri(schemaUri);//from ww w. java2 s . co m final UniqueName literalUniqueName = JsonSchema.createJsonSchemaUniqueName(schemaUri); final String namespace = literalUniqueName.getNamespace(); final String localName = StringUtils.capitalize(literalUniqueName.getLocalName()); final UniqueName uniqueName = new UniqueName(namespace, localName); schema.setUniqueName(uniqueName); final String schemaDescription = jsonSchema.getDescription(); if (schemaDescription != null) { schema.setDescription(schemaDescription); } final String schemaTitle = uniqueName.getLocalName(); if (schemaTitle != null) { schema.setTitle(schemaTitle); } final Set<URI> baseSchemaUriSet = new HashSet<>(); if (baseSchemaUris != null) { baseSchemaUriSet.addAll(Arrays.asList(baseSchemaUris)); } baseSchemaUriSet.addAll(jsonSchema.getExtendedSchemaUris()); schema.getBaseSchemaUris().addAll(baseSchemaUriSet); final List<Slot> slots = schema.getSlots(); final Map<String, JsonSchema.Property> properties = jsonSchema.getProperties(); for (final String name : properties.keySet()) { final JsonSchema.Property property = properties.get(name); final Slot slot = context.newModel(Slot.class); slot.setName(name); final String slotDescription = property.getValue(PropertyType.Description); if (slotDescription != null) { slot.setDescription(slotDescription); } final String slotTitle = property.getValue(PropertyType.Title); if (slotTitle != null) { slot.setTitle(slotTitle); } final Value value = generateValue(jsonSchema, property); if (value == null) { throw new SchemaGeneratorException("Failed to generate a Value for slot: " + name, null, this); } slot.setValue(value); slots.add(slot); } final List<JsonSchema.Link> links = jsonSchema.getLinks(); for (final JsonSchema.Link jsonSchemaLink : links) { final Slot linkSlot = context.newModel(Slot.class); final URI linkRelationUri = jsonSchemaLink.getRelId(); if (linkRelationUri == null) { continue; } final LinkRelation linkRelation = getContext().getApiLoader().loadLinkRelation(linkRelationUri); if (linkRelation == null) { continue; } final String linkSlotName = linkRelation.getUniqueName().getLocalName(); if (linkSlotName == null) { continue; } linkSlot.setName(linkSlotName); final LinkValue linkValue = context.newModel(LinkValue.class); linkSlot.setValue(linkValue); linkValue.setLinkRelationUri(linkRelationUri); final URI targetSchemaUri = jsonSchemaLink.getTargetSchemaId(); if (targetSchemaUri != null) { linkValue.setResponseSchemaUri(targetSchemaUri); } final URI paramSchemaUri = jsonSchemaLink.getSchemaId(); linkValue.setRequestSchemaUri(paramSchemaUri); slots.add(linkSlot); } final ObjectNode rootNode = jsonSchema.getRootNode(); if (rootNode.has(Schema.SLOT_NAME_KEY_SLOT_NAMES)) { final JsonNode keySlotNamesJsonNode = rootNode.get(Schema.SLOT_NAME_KEY_SLOT_NAMES); if (keySlotNamesJsonNode instanceof ArrayNode) { final ArrayNode keySlotNamesArrayNode = (ArrayNode) keySlotNamesJsonNode; final Iterator<JsonNode> elements = keySlotNamesArrayNode.elements(); while (elements.hasNext()) { final JsonNode keySlotNameJsonNode = elements.next(); final String keySlotName = keySlotNameJsonNode.asText(); schema.getKeySlotNames().add(keySlotName); } } } LOG.debug("Generated WRML Schema from JSON Schema (" + schema.getUri() + "):\n" + schema); return schema; }
From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java
public List<SecurityRequirement> getSecurityRequirementsList(ArrayNode nodes, String location, ParseResult result) {//from www. j a va 2 s .c o m if (nodes == null) return null; List<SecurityRequirement> securityRequirements = new ArrayList<>(); for (JsonNode node : nodes) { if (node.getNodeType().equals(JsonNodeType.OBJECT)) { SecurityRequirement securityRequirement = new SecurityRequirement(); Set<String> keys = getKeys((ObjectNode) node); if (keys.size() == 0) { securityRequirements.add(securityRequirement); } else { for (String key : keys) { if (key != null) { JsonNode value = node.get(key); if (key != null && JsonNodeType.ARRAY.equals(value.getNodeType())) { ArrayNode arrayNode = (ArrayNode) value; List<String> scopes = Stream.generate(arrayNode.elements()::next) .map((n) -> n.asText()).limit(arrayNode.size()) .collect(Collectors.toList()); securityRequirement.addList(key, scopes); } } } if (securityRequirement.size() > 0) { securityRequirements.add(securityRequirement); } } } } return securityRequirements; }