Search in sources :

Example 1 with IExample

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);
}
Also used : IExample(io.apicurio.datamodels.core.models.common.IExample) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 2 with IExample

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);
}
Also used : IExample(io.apicurio.datamodels.core.models.common.IExample) Node(io.apicurio.datamodels.core.models.Node) IExamplesParent(io.apicurio.datamodels.core.models.common.IExamplesParent)

Example 3 with IExample

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);
}
Also used : Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter) IExample(io.apicurio.datamodels.core.models.common.IExample) Node(io.apicurio.datamodels.core.models.Node)

Example 4 with IExample

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);
    }
}
Also used : IExample(io.apicurio.datamodels.core.models.common.IExample) IExamplesParent(io.apicurio.datamodels.core.models.common.IExamplesParent)

Aggregations

IExample (io.apicurio.datamodels.core.models.common.IExample)4 Node (io.apicurio.datamodels.core.models.Node)2 IExamplesParent (io.apicurio.datamodels.core.models.common.IExamplesParent)2 Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)1 Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)1