Search in sources :

Example 1 with Server

use of io.apicurio.datamodels.core.models.common.Server in project apicurio-data-models by Apicurio.

the class DeleteServerCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[DeleteServerCommand] Executing.");
    this._oldServer = null;
    IServerParent parent = (IServerParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parent)) {
        return;
    }
    Server server = parent.getServer(_serverUrl);
    if (this.isNullOrUndefined(server)) {
        return;
    }
    List<Server> servers = parent.getServers();
    servers.remove(servers.indexOf(server));
    if (servers.size() == 0) {
        NodeCompat.setProperty(parent, Constants.PROP_SERVERS, null);
    }
    this._oldServer = Library.writeNode(server);
}
Also used : Server(io.apicurio.datamodels.core.models.common.Server) IServerParent(io.apicurio.datamodels.core.models.common.IServerParent)

Example 2 with Server

use of io.apicurio.datamodels.core.models.common.Server in project apicurio-data-models by Apicurio.

the class DeleteServerCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[DeleteServerCommand] Reverting.");
    if (this.isNullOrUndefined(this._oldServer)) {
        return;
    }
    IServerParent parent = (IServerParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parent)) {
        return;
    }
    Server server = parent.createServer();
    Library.readNode(this._oldServer, server);
    List<Server> servers = parent.getServers();
    if (this.isNullOrUndefined(servers)) {
        servers = new ArrayList<>();
        NodeCompat.setProperty(parent, Constants.PROP_SERVERS, servers);
    }
    servers.add(server);
}
Also used : Server(io.apicurio.datamodels.core.models.common.Server) IServerParent(io.apicurio.datamodels.core.models.common.IServerParent)

Example 3 with Server

use of io.apicurio.datamodels.core.models.common.Server in project apicurio-data-models by Apicurio.

the class ChangeServerCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[ChangeServerCommand] Reverting.");
    if (this.isNullOrUndefined(this._oldServer)) {
        return;
    }
    IServerParent parent = (IServerParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parent)) {
        return;
    }
    Server server = parent.getServer(_serverUrl);
    if (this.isNullOrUndefined(server)) {
        return;
    }
    this.replaceServerWith(server, this._oldServer);
}
Also used : Server(io.apicurio.datamodels.core.models.common.Server) IServerParent(io.apicurio.datamodels.core.models.common.IServerParent)

Example 4 with Server

use of io.apicurio.datamodels.core.models.common.Server in project apicurio-data-models by Apicurio.

the class DeleteAllServersCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[DeleteAllServersCommand] Reverting.");
    if (this._oldServers.size() == 0) {
        return;
    }
    IServerParent parent = (IServerParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parent)) {
        return;
    }
    List<Server> servers = parent.getServers();
    if (this.isNullOrUndefined(servers)) {
        servers = new ArrayList<>();
        NodeCompat.setProperty(parent, Constants.PROP_SERVERS, servers);
    }
    for (Object oldServer : this._oldServers) {
        Oas30Server server = (Oas30Server) parent.createServer();
        Library.readNode(oldServer, server);
        servers.add(server);
    }
}
Also used : Oas30Server(io.apicurio.datamodels.openapi.v3.models.Oas30Server) Oas30Server(io.apicurio.datamodels.openapi.v3.models.Oas30Server) Server(io.apicurio.datamodels.core.models.common.Server) IServerParent(io.apicurio.datamodels.core.models.common.IServerParent)

Example 5 with Server

use of io.apicurio.datamodels.core.models.common.Server in project apicurio-data-models by Apicurio.

the class NewServerCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[NewServerCommand] Executing.");
    IServerParent parent = (IServerParent) document;
    if (!this.isNullOrUndefined(this._parentPath)) {
        parent = (IServerParent) this._parentPath.resolve(document);
    }
    // If the parent doesn't exist, abort!
    if (this.isNullOrUndefined(parent)) {
        return;
    }
    List<Server> servers = parent.getServers();
    if (this.isNullOrUndefined(servers)) {
        servers = new ArrayList<>();
        NodeCompat.setProperty(parent, Constants.PROP_SERVERS, servers);
    }
    Server server = (Server) parent.createServer();
    Library.readNode(this._server, server);
    if (this.serverAlreadyExists(parent, server)) {
        this._serverExisted = true;
        return;
    } else {
        servers.add(server);
        this._serverExisted = false;
    }
}
Also used : Server(io.apicurio.datamodels.core.models.common.Server) IServerParent(io.apicurio.datamodels.core.models.common.IServerParent)

Aggregations

Server (io.apicurio.datamodels.core.models.common.Server)17 IServerParent (io.apicurio.datamodels.core.models.common.IServerParent)8 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)6 ServerVariable (io.apicurio.datamodels.core.models.common.ServerVariable)4 Oas30Server (io.apicurio.datamodels.openapi.v3.models.Oas30Server)3 OpenApiModelInfo (io.syndesis.server.api.generator.openapi.OpenApiModelInfo)3 Test (org.junit.Test)3 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 AaiServer (io.apicurio.datamodels.asyncapi.models.AaiServer)1 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)1 Aai20Server (io.apicurio.datamodels.asyncapi.v2.models.Aai20Server)1 Extension (io.apicurio.datamodels.core.models.Extension)1 OasDocument (io.apicurio.datamodels.openapi.models.OasDocument)1 Oas30ServerVariable (io.apicurio.datamodels.openapi.v3.models.Oas30ServerVariable)1 OpenAPI (io.swagger.v3.oas.models.OpenAPI)1