List of usage examples for com.fasterxml.jackson.databind JsonNode textValue
public String textValue()
From source file:com.unboundid.scim2.server.utils.SchemaChecker.java
/** * Check an attribute value to see if it has the right type. * * @param prefix The issue prefix./* w w w . j a v a 2 s .c o m*/ * @param node The attribute value. * @param path The attribute path. * @param attribute The attribute definition. * @param results The schema check results. * @param currentObjectNode The current resource. * @param isPartialReplace Whether this is a partial replace. * @param isPartialAdd Whether this is a partial add. * @throws ScimException If an error occurs. */ private void checkAttributeValue(final String prefix, final JsonNode node, final Path path, final AttributeDefinition attribute, final Results results, final ObjectNode currentObjectNode, final boolean isPartialReplace, final boolean isPartialAdd) throws ScimException { if (node.isNull()) { return; } // Check the node type. switch (attribute.getType()) { case STRING: case DATETIME: case BINARY: case REFERENCE: if (!node.isTextual()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON string"); return; } break; case BOOLEAN: if (!node.isBoolean()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON boolean"); return; } break; case DECIMAL: case INTEGER: if (!node.isNumber()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON number"); return; } break; case COMPLEX: if (!node.isObject()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON object"); return; } break; default: throw new RuntimeException("Unexpected attribute type " + attribute.getType()); } // If the node type checks out, check the actual value. switch (attribute.getType()) { case DATETIME: try { ISO8601Utils.parse(node.textValue(), new ParsePosition(0)); } catch (Exception e) { Debug.debug(Level.INFO, DebugType.EXCEPTION, "Invalid ISO8601 string during schema checking", e); results.syntaxIssues .add(prefix + "Value for attribute " + path + " is not a valid ISO8601 formatted string"); } break; case BINARY: try { Base64Variants.getDefaultVariant().decode(node.textValue()); } catch (Exception e) { Debug.debug(Level.INFO, DebugType.EXCEPTION, "Invalid base64 string during schema checking", e); results.syntaxIssues .add(prefix + "Value for attribute " + path + " is not a valid base64 encoded string"); } break; case REFERENCE: try { new URI(node.textValue()); } catch (Exception e) { Debug.debug(Level.INFO, DebugType.EXCEPTION, "Invalid URI string during schema checking", e); results.syntaxIssues.add(prefix + "Value for attribute " + path + " is not a valid URI string"); } break; case INTEGER: if (!node.isIntegralNumber()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " is not an integral number"); } break; case COMPLEX: checkObjectNode(prefix, path, attribute.getSubAttributes(), (ObjectNode) node, results, currentObjectNode, isPartialReplace, isPartialAdd, false); break; case STRING: // Check for canonical values if (attribute.getCanonicalValues() != null) { boolean found = false; for (String canonicalValue : attribute.getCanonicalValues()) { if (attribute.isCaseExact() ? canonicalValue.equals(node.textValue()) : StaticUtils.toLowerCase(canonicalValue) .equals(StaticUtils.toLowerCase(node.textValue()))) { found = true; break; } } if (!found) { results.syntaxIssues.add(prefix + "Value " + node.textValue() + " is not valid for attribute " + path + " because it " + "is not one of the canonical types: " + StaticUtils.collectionToString(attribute.getCanonicalValues(), ", ")); } } } // Special checking of the schemas attribute to ensure that // no undefined schemas are listed. if (attribute.equals(SchemaUtils.SCHEMAS_ATTRIBUTE_DEFINITION) && path.size() == 1) { boolean found = false; for (SchemaResource schemaExtension : resourceType.getSchemaExtensions().keySet()) { if (node.textValue().equals(schemaExtension.getId())) { found = true; break; } } if (!found) { found = node.textValue().equals(resourceType.getCoreSchema().getId()); } if (!found && !enabledOptions.contains(Option.ALLOW_UNDEFINED_ATTRIBUTES)) { results.syntaxIssues.add(prefix + "Schema URI " + node.textValue() + " is not a valid value for attribute " + path + " because it is " + "undefined as a core or schema extension for this resource type"); } } }
From source file:com.unboundid.scim2.common.GenericScimResource.java
/** * Gets a String value from a generic SCIM resource. If the path exists, * the JSON node at the path must be a String. If the path does not exist, * "{@code null}" will be returned.//w w w. ja v a 2s .com * <p> * * For example: * In a GenericScimResource (gsr) representing the following resource: * <pre><code> * { * "path1":"stringValue1" * } * </code></pre> * <p> * * getStringValue(Path.fromString("path1")) * returns Stringexample * <p> * * getStringValue(Path.fromString("bogusPath")) * returns null * * @param path the path to get the value from. * @return the value at the path, or null. * @throws ScimException thrown if an error occurs. */ public String getStringValue(final Path path) throws ScimException { JsonNode jsonNode = getValue(path); return jsonNode.isNull() ? null : jsonNode.textValue(); }
From source file:com.unboundid.scim2.common.GenericScimResource.java
/** * Gets a URI value from a generic SCIM resource. If the path exists, * the JSON node at the path must be a URI. If the path does not exist, * "{@code null}" will be returned.// ww w . j a va 2s . c om * <p> * * For example: * In a GenericScimResource (gsr) representing the following resource: * <pre><code> * { * "path1":"http://localhost:8080/uri/One" * } * </code></pre> * <p> * * getURIValue(Path.fromString("path1")) * returns "http://localhost:8080/uri/One" * <p> * * getURIValue(Path.fromString("bogusPath")) * returns null * * @param path the path to get the value from. * @return the value at the path, or null. * @throws ScimException thrown if an error occurs. */ public URI getURIValue(final Path path) throws ScimException { try { JsonNode jsonNode = getValue(path); return jsonNode.isNull() ? null : new URI(jsonNode.textValue()); } catch (URISyntaxException ex) { throw new ServerErrorException(ex.getMessage()); } }
From source file:com.unboundid.scim2.common.GenericScimResource.java
/** * Gets a Date value from a generic SCIM resource. If the path exists, * the JSON node at the path must be a Date. If the path does not exist, * "{@code null}" will be returned./*from w ww. java 2s. c om*/ * <p> * * For example: * In a GenericScimResource (gsr) representing the following resource: * <pre><code> * { * "path1":"1970-04-20T17:54:47.542Z" * } * </code></pre> * <p> * * getDateValue(Path.fromString("path1")) * returns a Date representing "1970-04-20T17:54:47.542Z" * <p> * * getDateValue(Path.fromString("bogusPath")) * returns null * * @param path the path to get the value from. * @return the value at the path, or null. * @throws ScimException thrown if an error occurs. */ public Date getDateValue(final Path path) throws ScimException { JsonNode jsonNode = getValue(path); if (jsonNode.isNull()) { return null; } String dateString = jsonNode.textValue(); return getDateForString(dateString); }
From source file:com.unboundid.scim2.common.GenericScimResource.java
/** * Gets a binary value from a generic SCIM resource. If the path exists, * the JSON node at the path must be a binary value. If the path does * not exist, "{@code null}" will be returned. * <p>//from w w w.j a v a2 s.co m * * For example: * In a GenericScimResource (gsr) representing the following resource: * <pre><code> * { * "path1":"AjIzLg==" * } * </code></pre> * <p> * * getBinaryValue(Path.fromString("path1")) * returns the byte array decoded from "AjIzLg==" * <p> * * getBinaryValue(Path.fromString("bogusPath")) * returns null * * @param path the path to get the value from. * @return the value at the path, or null. * @throws ScimException thrown if an error occurs. */ public byte[] getBinaryValue(final Path path) throws ScimException { JsonNode jsonNode = getValue(path); if (jsonNode.isNull()) { return null; } String binaryString = jsonNode.textValue(); return getBinaryForString(binaryString); }
From source file:com.appdynamics.analytics.processor.event.ElasticSearchEventService.java
private void verifyAndReplaceMultiSearchHeaders(int requestVersion, String accountName, JsonNode[] nodes)//from w ww .j av a 2 s .co m /* */ { /* 1510 */ if ((nodes.length == 0) || (nodes.length % 2 != 0)) { /* 1511 */ throw new ServiceRequestException("Invalid.NumberOfLines", "Multisearch requests must have an even number of lines and contain at least 2 lines."); /* */ } /* */ /* */ /* 1515 */ for (int i = 0; i < nodes.length; i += 2) { /* 1516 */ if (nodes[i].get("index") != null) { /* 1517 */ throw new ServiceRequestException("MustNotBeSpecified.IndexField", "The field 'index' must NOT be supplied in a multi search header."); /* */ } /* */ /* 1520 */ JsonNode eventType = nodes[i].get("eventType"); /* 1521 */ if (eventType == null) { /* 1522 */ throw new ServiceRequestException("MustBeSpecified.EventTypeField", "The field 'eventType' MUST be supplied in a multi search header."); /* */ } /* */ /* */ /* 1526 */ verifyEventTypeRepairingIndicesIfNecessary(requestVersion, accountName, eventType.textValue()); /* 1527 */ String indexName = this.indexNameResolver.resolveSearchAlias(accountName, eventType.textValue()); /* 1528 */ ((ObjectNode) nodes[i]).put("index", indexName); /* */ } /* */ }
From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java
public List<String> getTagsStrings(ArrayNode nodes, String location, ParseResult result) { if (nodes == null) return null; List<String> tags = new ArrayList<>(); for (JsonNode node : nodes) { if (node.getNodeType().equals(JsonNodeType.STRING)) { tags.add(node.textValue()); }/* ww w . j a v a 2s. com*/ } return tags; }
From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java
protected RequestBody getRequestBody(ObjectNode node, String location, ParseResult result) { if (node == null) { return null; }//from w ww. ja v a 2 s .c om final RequestBody body = new RequestBody(); JsonNode ref = node.get("$ref"); if (ref != null) { if (ref.getNodeType().equals(JsonNodeType.STRING)) { String mungedRef = mungedRef(ref.textValue()); if (mungedRef != null) { body.set$ref(mungedRef); } else { body.set$ref(ref.textValue()); } return body; } else { result.invalidType(location, "$ref", "string", node); return null; } } final String description = getString("description", node, false, location, result); if (StringUtils.isNotBlank(description)) { body.setDescription(description); } final Boolean required = getBoolean("required", node, false, location, result); if (required != null) { body.setRequired(required); } final ObjectNode contentNode = getObject("content", node, true, location, result); if (contentNode != null) { body.setContent(getContent(contentNode, location + ".content", result)); } Map<String, Object> extensions = getExtensions(node); if (extensions != null && extensions.size() > 0) { body.setExtensions(extensions); } Set<String> keys = getKeys(node); for (String key : keys) { if (!REQUEST_BODY_KEYS.contains(key) && !key.startsWith("x-")) { result.extra(location, key, node.get(key)); } } return body; }
From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java
public Example getExample(ObjectNode node, String location, ParseResult result) { if (node == null) return null; Example example = new Example(); JsonNode ref = node.get("$ref"); if (ref != null) { if (ref.getNodeType().equals(JsonNodeType.STRING)) { String mungedRef = mungedRef(ref.textValue()); if (mungedRef != null) { example.set$ref(mungedRef); } else { example.set$ref(ref.textValue()); }//from ww w .ja v a 2 s. c o m return example; } else { result.invalidType(location, "$ref", "string", node); return null; } } String value = getString("summary", node, false, location, result); if (StringUtils.isNotBlank(value)) { example.setSummary(value); } value = getString("description", node, false, location, result); if (StringUtils.isNotBlank(value)) { example.setDescription(value); } Object sample = getAnyExample("value", node, location, result); if (sample != null) { example.setValue(sample); } value = getString("externalValue", node, false, location, result); if (StringUtils.isNotBlank(value)) { example.setExternalValue(value); } Map<String, Object> extensions = getExtensions(node); if (extensions != null && extensions.size() > 0) { example.setExtensions(extensions); } Set<String> keys = getKeys(node); for (String key : keys) { if (!EXAMPLE_KEYS.contains(key) && !key.startsWith("x-")) { result.extra(location, key, node.get(key)); } } return example; }
From source file:io.swagger.v3.parser.util.OpenAPIDeserializer.java
public Callback getCallback(ObjectNode node, String location, ParseResult result) { if (node == null) { return null; }/*from w w w .jav a2 s . c om*/ Callback callback = new Callback(); Set<String> keys = getKeys(node); for (String name : keys) { JsonNode value = node.get(name); if (node != null) { JsonNode ref = node.get("$ref"); if (ref != null) { if (ref.getNodeType().equals(JsonNodeType.STRING)) { String mungedRef = mungedRef(ref.textValue()); if (mungedRef != null) { callback.set$ref(mungedRef); } else { callback.set$ref(ref.textValue()); } return callback; } else { result.invalidType(location, "$ref", "string", node); return null; } } callback.addPathItem(name, getPathItem((ObjectNode) value, location, result)); Map<String, Object> extensions = getExtensions(node); if (extensions != null && extensions.size() > 0) { callback.setExtensions(extensions); } } } return callback; }