Search in sources :

Example 1 with JsonPointer

use of com.github.fge.jackson.jsonpointer.JsonPointer in project stackgres by ongres.

the class ExtensionsMutator method onExtensionToInstall.

@Override
protected void onExtensionToInstall(Builder<JsonPatchOperation> operations, StackGresClusterExtension extension, int index, StackGresClusterInstalledExtension installedExtension) {
    final JsonPointer extensionVersionPointer = CLUSTER_CONFIG_POINTER.append("postgres").append("extensions").append(index).append("version");
    final TextNode extensionVersion = new TextNode(installedExtension.getVersion());
    if (extension.getVersion() == null) {
        operations.add(new AddOperation(extensionVersionPointer, extensionVersion));
    } else if (!installedExtension.getVersion().equals(extension.getVersion())) {
        operations.add(new ReplaceOperation(extensionVersionPointer, extensionVersion));
    }
}
Also used : ReplaceOperation(com.github.fge.jsonpatch.ReplaceOperation) TextNode(com.fasterxml.jackson.databind.node.TextNode) JsonPointer(com.github.fge.jackson.jsonpointer.JsonPointer) AddOperation(com.github.fge.jsonpatch.AddOperation)

Example 2 with JsonPointer

use of com.github.fge.jackson.jsonpointer.JsonPointer in project stackgres by ongres.

the class ClusterConfigurationMutator method ensureConfigurationNode.

static List<JsonPatchOperation> ensureConfigurationNode(StackGresClusterReview review) {
    final StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
    StackGresClusterConfiguration configuration = spec.getConfiguration();
    if (configuration == null) {
        try {
            configuration = new StackGresClusterConfiguration();
            spec.setConfiguration(configuration);
            final JsonPointer confPointer = getTargetPointer();
            final AddOperation configurationAdd = new AddOperation(confPointer, JsonPatchMutator.FACTORY.objectNode());
            return ImmutableList.of(configurationAdd);
        } catch (NoSuchFieldException e) {
            return ImmutableList.of();
        }
    }
    return ImmutableList.of();
}
Also used : StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) JsonPointer(com.github.fge.jackson.jsonpointer.JsonPointer) AddOperation(com.github.fge.jsonpatch.AddOperation)

Example 3 with JsonPointer

use of com.github.fge.jackson.jsonpointer.JsonPointer in project stackgres by ongres.

the class AbstractExtensionsMutator method onExtensionToInstall.

protected void onExtensionToInstall(ImmutableList.Builder<JsonPatchOperation> operations, final StackGresClusterExtension extension, final int index, final StackGresClusterInstalledExtension installedExtension) {
    final JsonPointer extensionVersionPointer = TO_INSTALL_EXTENSIONS_POINTER.append(index).append("version");
    final TextNode extensionVersion = new TextNode(installedExtension.getVersion());
    if (extension.getVersion() == null) {
        operations.add(new AddOperation(extensionVersionPointer, extensionVersion));
    } else if (!installedExtension.getVersion().equals(extension.getVersion())) {
        operations.add(new ReplaceOperation(extensionVersionPointer, extensionVersion));
    }
}
Also used : ReplaceOperation(com.github.fge.jsonpatch.ReplaceOperation) TextNode(com.fasterxml.jackson.databind.node.TextNode) JsonPointer(com.github.fge.jackson.jsonpointer.JsonPointer) AddOperation(com.github.fge.jsonpatch.AddOperation)

Example 4 with JsonPointer

use of com.github.fge.jackson.jsonpointer.JsonPointer in project swagger-parser by swagger-api.

the class ApiObjectMigrator method migrate.

@Nonnull
@Override
public JsonNode migrate(@Nonnull final JsonNode input) throws SwaggerMigrationException {
    ObjectNode on = (ObjectNode) input;
    if (on.get("type") == null) {
        JsonNode responseMessages = on.get("responseMessages");
        JsonNode type = null;
        if (responseMessages != null && responseMessages instanceof ArrayNode) {
            // look for a 200 response
            ArrayNode arrayNode = (ArrayNode) responseMessages;
            Iterator<JsonNode> itr = arrayNode.elements();
            while (itr.hasNext()) {
                JsonNode rm = itr.next();
                JsonNode code = rm.get("code");
                if (code != null) {
                    if ("200".equals(code.toString())) {
                        type = rm;
                    }
                }
            }
        }
        if (type != null) {
            if (type.get("type") == null) {
                on.put("type", "void");
            } else {
                on.put("type", type.get("type"));
            }
        } else {
            on.put("type", "void");
        }
    }
    // if there are no parameters, we can insert an empty array
    if (on.get("parameters") == null) {
        on.put("parameters", Json.mapper().createArrayNode());
    }
    // see if there's a response
    final MutableJsonTree tree = new MutableJsonTree(input);
    tree.applyMigrator(renameMember("httpMethod", "method"));
    tree.applyMigrator(renameMember("errorResponses", "responseMessages"));
    /*
         * Migrate response messages, if any
         */
    JsonPointer ptr = JsonPointer.of("responseMessages");
    if (!ptr.path(tree.getBaseNode()).isMissingNode()) {
        tree.setPointer(ptr);
        tree.applyMigratorToElements(renameMember("reason", "message"));
    }
    /*
         * Migrate parameters
         */
    ptr = JsonPointer.of("parameters");
    tree.setPointer(ptr);
    tree.applyMigratorToElements(parametersMigrator);
    return tree.getBaseNode();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) MutableJsonTree(io.swagger.transform.util.MutableJsonTree) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonPointer(com.github.fge.jackson.jsonpointer.JsonPointer) Nonnull(javax.annotation.Nonnull)

Example 5 with JsonPointer

use of com.github.fge.jackson.jsonpointer.JsonPointer in project swagger-parser by swagger-api.

the class MutableJsonTree method applyMigrator.

/**
 * Apply a migrator to the node at the current pointer
 *
 * <p>It is assumed here that the current node is a JSON Object.</p>
 *
 * @param migrator the migrator to apply
 * @throws SwaggerMigrationException current node is not an object, or the
 *                                   migrator failed to apply
 */
public void applyMigrator(final SwaggerMigrator migrator) throws SwaggerMigrationException {
    final JsonPointer parent = currentPointer.parent();
    if (!parent.get(baseNode).isObject()) {
        throw new SwaggerMigrationException();
    }
    final ObjectNode parentNode = (ObjectNode) parent.get(baseNode);
    final JsonNode patched = migrator.migrate(currentNode);
    if (currentPointer.isEmpty()) {
        baseNode = currentNode = patched;
        return;
    }
    final String memberName = Iterables.getLast(currentPointer).getToken().getRaw();
    parentNode.put(memberName, patched);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonPointer(com.github.fge.jackson.jsonpointer.JsonPointer)

Aggregations

JsonPointer (com.github.fge.jackson.jsonpointer.JsonPointer)9 AddOperation (com.github.fge.jsonpatch.AddOperation)7 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)4 ReplaceOperation (com.github.fge.jsonpatch.ReplaceOperation)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 TextNode (com.fasterxml.jackson.databind.node.TextNode)3 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Seq (org.jooq.lambda.Seq)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 JacksonUtils (com.github.fge.jackson.JacksonUtils)1 CopyOperation (com.github.fge.jsonpatch.CopyOperation)1 MoveOperation (com.github.fge.jsonpatch.MoveOperation)1 Thing (de.fraunhofer.iosb.ilt.sta.model.Thing)1 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)1