Search in sources :

Example 1 with IServerParent

use of io.apicurio.datamodels.core.models.common.IServerParent 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 IServerParent

use of io.apicurio.datamodels.core.models.common.IServerParent 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 IServerParent

use of io.apicurio.datamodels.core.models.common.IServerParent 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 IServerParent

use of io.apicurio.datamodels.core.models.common.IServerParent 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 IServerParent

use of io.apicurio.datamodels.core.models.common.IServerParent 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

IServerParent (io.apicurio.datamodels.core.models.common.IServerParent)8 Server (io.apicurio.datamodels.core.models.common.Server)8 Oas30Server (io.apicurio.datamodels.openapi.v3.models.Oas30Server)2