use of io.apicurio.datamodels.core.models.common.IExample in project apicurio-data-models by Apicurio.
the class DeleteExampleCommand_30 method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[DeleteExampleCommand] Reverting.");
if (this.isNullOrUndefined(this._oldExample)) {
return;
}
Oas30MediaType mediaType = (Oas30MediaType) this._mediaTypePath.resolve(document);
if (this.isNullOrUndefined(mediaType)) {
LoggerCompat.info("[DeleteExampleCommand] No media type found.");
return;
}
IExample example = mediaType.createExample(this._exampleName);
Library.readNode(this._oldExample, (Node) example);
mediaType.addExample(example);
}
use of io.apicurio.datamodels.core.models.common.IExample in project apicurio-data-models by Apicurio.
the class DeleteExampleCommand_30 method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[DeleteExampleCommand] Executing.");
this._oldExample = null;
IExamplesParent parent = (IExamplesParent) this._mediaTypePath.resolve(document);
if (this.isNullOrUndefined(parent) || this.isNullOrUndefined(parent.getExample(this._exampleName))) {
LoggerCompat.debug("[DeleteExampleCommand] No example named: " + this._exampleName);
return;
}
IExample example = parent.removeExample(this._exampleName);
this._oldExample = Library.writeNode((Node) example);
}
use of io.apicurio.datamodels.core.models.common.IExample in project apicurio-data-models by Apicurio.
the class DeleteParameterExampleCommand_30 method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[DeleteExampleCommand] Executing.");
this._oldExample = null;
Oas30Parameter parameter = (Oas30Parameter) this._parameterPath.resolve(document);
if (this.isNullOrUndefined(parameter) || this.isNullOrUndefined(parameter.getExample(this._exampleName))) {
LoggerCompat.debug("[DeleteExampleCommand] No example named: " + this._exampleName);
return;
}
IExample example = parameter.removeExample(this._exampleName);
this._oldExample = Library.writeNode((Node) example);
}
use of io.apicurio.datamodels.core.models.common.IExample in project apicurio-data-models by Apicurio.
the class DeleteAllExamplesCommand method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
if (this.isNullOrUndefined(document)) {
LoggerCompat.debug("[DeleteAllExamplesCommand] Could not revert the command, invalid argument.");
return;
}
if (this.isNullOrUndefined(this._mediaTypePath)) {
LoggerCompat.debug("[DeleteAllExamplesCommand] Could not revert the command, problem when unmarshalling.");
return;
}
LoggerCompat.info("[DeleteAllExamplesCommand] Reverting.");
IExamplesParent parent = (IExamplesParent) this._mediaTypePath.resolve(document);
if (this.isNullOrUndefined(parent)) {
LoggerCompat.info("[DeleteAllExamplesCommand] No media type found.");
return;
}
if (this.isNullOrUndefined(this._oldExamples)) {
LoggerCompat.info("[DeleteAllExamplesCommand] Could not revert. Previous data is not available.");
return;
}
for (String k : this._oldExamples.keySet()) {
IExample example = parent.createExample(k);
Library.readNode(this._oldExamples.get(k), (Node) example);
parent.addExample(example);
}
}
Aggregations