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);
}
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);
}
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);
}
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);
}
}
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;
}
}
Aggregations