Java Code Examples for com.fasterxml.jackson.core.JsonPointer#compile()

The following examples show how to use com.fasterxml.jackson.core.JsonPointer#compile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeDeserializer.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
protected ArrayNode deserializeArrayNode(JsonParser p, DeserializationContext context, JsonLocation startLocation)
        throws IOException {
    final Model model = (Model) context.getAttribute(ATTRIBUTE_MODEL);
    final AbstractNode parent = (AbstractNode) context.getAttribute(ATTRIBUTE_PARENT);
    final JsonPointer ptr = (JsonPointer) context.getAttribute(ATTRIBUTE_POINTER);

    ArrayNode node = model.arrayNode(parent, ptr);

    int i = 0;
    while (p.nextToken() != JsonToken.END_ARRAY) {
        JsonPointer pp = JsonPointer.compile(ptr.toString() + "/" + i);

        context.setAttribute(ATTRIBUTE_PARENT, node);
        context.setAttribute(ATTRIBUTE_POINTER, pp);

        AbstractNode v = deserialize(p, context);

        node.add(v);
        i++;
    }

    node.setStartLocation(createLocation(startLocation));
    node.setEndLocation(createLocation(p.getCurrentLocation()));
    return node;
}
 
Example 2
Source File: OpenApi3Validator.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
protected void validateOperationIdReferences(Model model, AbstractNode node, Set<SwaggerError> errors) {
    JsonPointer schemaPointer = JsonPointer.compile("/definitions/link/properties/operationId");

    if (node != null && node.getType() != null && schemaPointer.equals(node.getType().getPointer())) {
        List<AbstractNode> nodes = model.findByType(operationPointer);
        Iterator<AbstractNode> it = nodes.iterator();

        boolean found = false;
        while (it.hasNext() && !found) {
            AbstractNode current = it.next();
            AbstractNode value = current.get("operationId");

            found = value != null && Objects.equals(node.asValue().getValue(), value.asValue().getValue());
        }

        if (!found) {
            errors.add(error(node, IMarker.SEVERITY_ERROR, Messages.error_invalid_operation_id));
        }
    }
}
 
Example 3
Source File: OpenApi3Validator.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
protected void validateParameters(Model model, AbstractNode node, Set<SwaggerError> errors) {
    final JsonPointer pointer = JsonPointer.compile("/definitions/parameterOrReference");

    if (node != null && node.getType() != null && pointer.equals(node.getType().getPointer())) {
        // validation parameter location value
        if (node.isObject() && node.asObject().get("in") != null) {
            AbstractNode valueNode = node.asObject().get("in");
            try {
                Object value = valueNode.asValue().getValue();

                if (!Arrays.asList("query", "header", "path", "cookie").contains(value)) {
                    errors.add(error(valueNode, IMarker.SEVERITY_ERROR, Messages.error_invalid_parameter_location));
                }
            } catch (Exception e) {
                errors.add(error(valueNode, IMarker.SEVERITY_ERROR, Messages.error_invalid_parameter_location));
            }
        }
    }
}
 
Example 4
Source File: MetadataService.java    From centraldogma with Apache License 2.0 6 votes vote down vote up
/**
 * Adds the specified {@code member} to the {@link ProjectMetadata} of the specified {@code projectName}
 * with the specified {@code projectRole}.
 */
public CompletableFuture<Revision> addMember(Author author, String projectName,
                                             User member, ProjectRole projectRole) {
    requireNonNull(author, "author");
    requireNonNull(projectName, "projectName");
    requireNonNull(member, "member");
    requireNonNull(projectRole, "projectRole");

    final Member newMember = new Member(member, projectRole, UserAndTimestamp.of(author));
    final JsonPointer path = JsonPointer.compile("/members" + encodeSegment(newMember.id()));
    final Change<JsonNode> change =
            Change.ofJsonPatch(METADATA_JSON,
                               asJsonArray(new TestAbsenceOperation(path),
                                           new AddOperation(path, Jackson.valueToTree(newMember))));
    final String commitSummary =
            "Add a member '" + newMember.id() + "' to the project '" + projectName + '\'';
    return metadataRepo.push(projectName, Project.REPO_DOGMA, author, commitSummary, change);
}
 
Example 5
Source File: JobIT.java    From zentity with Apache License 2.0 6 votes vote down vote up
public void testJobNoScope() throws Exception {
    int testResourceSet = TEST_RESOURCES_A;
    prepareTestResources(testResourceSet);
    try {
        String endpoint = "_zentity/resolution/zentity_test_entity_a";
        Request postResolution = new Request("POST", endpoint);
        postResolution.setEntity(TEST_PAYLOAD_JOB_NO_SCOPE);
        Response response = client.performRequest(postResolution);
        JsonNode json = Json.MAPPER.readTree(response.getEntity().getContent());
        assertEquals(json.get("hits").get("total").asInt(), 40);
        JsonPointer pathAttributes = JsonPointer.compile("/_attributes");
        JsonPointer pathNull = JsonPointer.compile("/_attributes/attribute_type_string_null");
        JsonPointer pathUnused = JsonPointer.compile("/_attributes/attribute_type_string_unused");
        for (JsonNode doc : json.get("hits").get("hits")) {
            assertEquals(doc.at(pathAttributes).isMissingNode(), false);
            assertEquals(doc.at(pathNull).isMissingNode(), true);
            assertEquals(doc.at(pathUnused).isMissingNode(), true);
        }
    } finally {
        destroyTestResources(testResourceSet);
    }
}
 
Example 6
Source File: JsonSchemaPreProcessorTest.java    From liiklus with MIT License 5 votes vote down vote up
private JsonSchemaPreProcessor getProcessor(boolean allowDeprecatedProperties) {
    return new JsonSchemaPreProcessor(
            getSchema("basic.yml"),
            JsonPointer.compile("/eventType"),
            allowDeprecatedProperties
    );
}
 
Example 7
Source File: CompositeSchema.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
public static JsonPointer pointer(String href) {
    if (href.startsWith("#")) {
        return JsonPointer.compile(href.substring(1));
    } else if (href.startsWith("/")) {
        return JsonPointer.compile(href);
    } else {
        String[] split = href.split("#");
        return split.length > 1 ? JsonPointer.compile(split[1]) : null;
    }
}
 
Example 8
Source File: JsonCacheTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetWithMissingAncestors() throws Exception {
    JsonPointer ptr = JsonPointer.compile("/nonExistentArray/0/nonExistentObject/stringProperty");
    assertFalse(cache.exists(ptr), "exists(ptr) returned incorrect value;");
    Object value = cache.get(ptr);
    assertNull(value, "stringProperty is non-null;");
    cache.set(ptr, "string value");
    assertTrue(cache.exists(ptr), "exists(ptr) returned incorrect value;");
    value = cache.get(ptr);
    assertEquals("string value", value, "stringProperty is null after being set;");
}
 
Example 9
Source File: JavaCXFExtServerCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
private JsonPointer getPointer(String suffix, boolean includeIndexes, boolean includeLastIndex) {
    StringBuilder path = new StringBuilder();
    appendPath(path, includeIndexes);
    if (includeIndexes && !includeLastIndex && isIndexed())
        path.setLength(path.lastIndexOf("/"));
    if (suffix != null)
        path.append('/').append(suffix);
    return JsonPointer.compile(path.toString());
}
 
Example 10
Source File: MetadataService.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a {@link RepositoryMetadata} of the specified {@code repoName} to the specified {@code projectName}
 * with the specified {@link PerRolePermissions}.
 */
public CompletableFuture<Revision> addRepo(Author author, String projectName, String repoName,
                                           PerRolePermissions permission) {
    requireNonNull(author, "author");
    requireNonNull(projectName, "projectName");
    requireNonNull(repoName, "repoName");
    requireNonNull(permission, "permission");

    final JsonPointer path = JsonPointer.compile("/repos" + encodeSegment(repoName));
    final RepositoryMetadata newRepositoryMetadata = new RepositoryMetadata(repoName,
                                                                            UserAndTimestamp.of(author),
                                                                            permission);
    final Change<JsonNode> change =
            Change.ofJsonPatch(METADATA_JSON,
                               asJsonArray(new TestAbsenceOperation(path),
                                           new AddOperation(path,
                                                            Jackson.valueToTree(newRepositoryMetadata))));
    final String commitSummary =
            "Add a repo '" + newRepositoryMetadata.id() + "' to the project '" + projectName + '\'';
    return metadataRepo.push(projectName, Project.REPO_DOGMA, author, commitSummary, change)
                       .handle((revision, cause) -> {
                           if (cause != null) {
                               if (Exceptions.peel(cause) instanceof ChangeConflictException) {
                                   throw new RepositoryExistsException(repoName);
                               } else {
                                   return Exceptions.throwUnsafely(cause);
                               }
                           }
                           return revision;
                       });
}
 
Example 11
Source File: JsonDataModelTree.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDataModelTree alloc(String path, Nodetype leaftype) throws WorkflowException {
    if (root == null || root instanceof MissingNode) {
        throw new WorkflowException("Invalid root node");
    }

    JsonPointer ptr = JsonPointer.compile(path);
    return alloc(ptr, leaftype);
}
 
Example 12
Source File: JSONUtils.java    From SkaETL with Apache License 2.0 5 votes vote down vote up
public void remove(JsonNode jsonNode, String path) {
    JsonPointer valueNodePointer = JsonPointer.compile(asJsonPath(path));
    JsonPointer parentPointer = valueNodePointer.head();
    JsonNode parentNode = jsonNode.at(parentPointer);
    if (parentNode.getNodeType() == JsonNodeType.OBJECT) {
        ObjectNode parentNodeToUpdate = (ObjectNode) parentNode;
        parentNodeToUpdate.remove(StringUtils.replace(valueNodePointer.last().toString(),"/",""));
    }

}
 
Example 13
Source File: JsonReference.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
private static JsonPointer createPointer(String text) {
    if (StringUtils.emptyToNull(text) == null) {
        return JsonPointer.compile("");
    }

    if (text.startsWith("#")) {
        text = text.substring(1);
    }
    return JsonPointer.compile(text);
}
 
Example 14
Source File: MetadataService.java    From centraldogma with Apache License 2.0 4 votes vote down vote up
/**
 * Generates the path of {@link JsonPointer} of permission of the specified {@code memberId} in the
 * specified {@code repoName}.
 */
private static JsonPointer perUserPermissionPointer(String repoName, String memberId) {
    return JsonPointer.compile("/repos" + encodeSegment(repoName) +
                               "/perUserPermissions" + encodeSegment(memberId));
}
 
Example 15
Source File: JsonPointerBasedInboundEventTenantDetector.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public JsonPointerBasedInboundEventTenantDetector(String jsonPointerExpression) {
    this.jsonPointerExpression = jsonPointerExpression;
    this.jsonPointer = JsonPointer.compile(jsonPointerExpression);
}
 
Example 16
Source File: JsonDataModelTree.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Sets boolean on specific json path.
 *
 * @param path   json path
 * @param isTrue boolean to set
 * @throws WorkflowException workflow exception
 */
public void setAt(String path, Boolean isTrue) throws WorkflowException {
    JsonPointer ptr = JsonPointer.compile(path);
    setAt(ptr, isTrue);
}
 
Example 17
Source File: JsonDataModelTree.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Sets boolean on specific json path.
 *
 * @param path     json path
 * @param jsonNode jsonNode to set
 * @throws WorkflowException workflow exception
 */
public void setAt(String path, JsonNode jsonNode) throws WorkflowException {
    JsonPointer ptr = JsonPointer.compile(path);
    setAt(ptr, jsonNode);
}
 
Example 18
Source File: JsonDataModelTree.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Gets integer node on specific path.
 *
 * @param path path of json node
 * @return integer on specific path
 * @throws WorkflowException workflow exception
 */
public Integer intAt(String path) throws WorkflowException {
    JsonPointer ptr = JsonPointer.compile(path);
    return intAt(ptr);
}
 
Example 19
Source File: JsonDataModelTree.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Gets json node on specific path as ObjectNode.
 *
 * @param path path of json node
 * @return ObjectNode type json node on specific path
 * @throws WorkflowException workflow exception
 */
public ObjectNode objectAt(String path) throws WorkflowException {
    JsonPointer ptr = JsonPointer.compile(path);
    return objectAt(ptr);
}
 
Example 20
Source File: JsonDataModelTree.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Gets json node on specific path.
 *
 * @param path path of json node
 * @return json node on specific path
 * @throws WorkflowException workflow exception
 */
public JsonNode nodeAt(String path) throws WorkflowException {
    JsonPointer ptr = JsonPointer.compile(path);
    return nodeAt(ptr);
}