use of io.apicurio.datamodels.core.models.common.IExamplesParent in project apicurio-data-models by Apicurio.
the class DeleteAllExamplesCommand method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[DeleteAllExamplesCommand] Executing.");
if (this.isNullOrUndefined(document)) {
LoggerCompat.debug("[DeleteAllExamplesCommand] Could not execute the command, invalid argument.");
return;
}
if (this.isNullOrUndefined(this._mediaTypePath)) {
LoggerCompat.debug("[DeleteAllExamplesCommand] Could not execute the command, problem when unmarshalling.");
return;
}
IExamplesParent parent = (IExamplesParent) this._mediaTypePath.resolve(document);
if (this.isNullOrUndefined(parent)) {
LoggerCompat.debug("[DeleteAllExamplesCommand] Media type not found.");
return;
}
this._oldExamples = new HashMap<>();
parent.getExamples().forEach(e -> {
this._oldExamples.put(e.getName(), Library.writeNode((Node) e));
});
parent.clearExamples();
}
use of io.apicurio.datamodels.core.models.common.IExamplesParent 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.IExamplesParent in project apicurio-data-models by Apicurio.
the class AddExampleCommand_30 method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[AddExampleCommand_30] Executing.");
this._exampleAdded = false;
IExamplesParent examplesParent = (IExamplesParent) this._parentPath.resolve(document);
if (this.isNullOrUndefined(examplesParent)) {
return;
}
if (!this.isNullOrUndefined(examplesParent.getExample(this._newExampleName))) {
return;
}
Oas30Example example = (Oas30Example) examplesParent.createExample(this._newExampleName);
example.summary = this._newExampleSummary;
example.description = this._newExampleDescription;
example.value = this._newExampleValue;
examplesParent.addExample(example);
this._exampleAdded = true;
}
use of io.apicurio.datamodels.core.models.common.IExamplesParent in project apicurio-data-models by Apicurio.
the class SetExampleCommand_30 method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[SetExampleCommand_30] Executing.");
this._oldValue = null;
this._nullExample = false;
if (!this.isNullOrUndefined(this._newExampleName)) {
IExamplesParent parent = (IExamplesParent) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
if (this.isNullOrUndefined(parent.getExample(this._newExampleName))) {
parent.addExample(parent.createExample(this._newExampleName));
this._nullExample = true;
} else {
this._oldValue = parent.getExample(this._newExampleName).getValue();
}
parent.getExample(this._newExampleName).setValue(this._newExample);
} else {
IExampleParent parent = (IExampleParent) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
this._oldValue = parent.getExample();
parent.setExample(this._newExample);
}
}
use of io.apicurio.datamodels.core.models.common.IExamplesParent in project apicurio-data-models by Apicurio.
the class SetExampleCommand_30 method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[SetExampleCommand_30] Reverting.");
if (!this.isNullOrUndefined(this._newExampleName)) {
IExamplesParent parent = (IExamplesParent) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
if (this._nullExample) {
parent.removeExample(this._newExampleName);
} else {
parent.getExample(this._newExampleName).setValue(this._oldValue);
}
} else {
IExampleParent parent = (IExampleParent) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
parent.setExample(this._oldValue);
this._oldValue = null;
}
}
Aggregations