Search in sources :

Example 1 with IOas30MediaTypeParent

use of io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent in project apicurio-data-models by Apicurio.

the class NewMediaTypeCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[NewMediaTypeCommand] Reverting.");
    if (!this._created) {
        LoggerCompat.info("[NewMediaTypeCommand] media type already existed, nothing done so no rollback necessary.");
        return;
    }
    IOas30MediaTypeParent node = (IOas30MediaTypeParent) this._nodePath.resolve(document);
    if (this.isNullOrUndefined(node)) {
        return;
    }
    node.removeMediaType(this._newMediaType);
}
Also used : IOas30MediaTypeParent(io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent)

Example 2 with IOas30MediaTypeParent

use of io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent in project apicurio-data-models by Apicurio.

the class DeleteMediaTypeCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[DeleteMediaTypeCommand] Reverting.");
    if (this.isNullOrUndefined(this._oldMediaType)) {
        return;
    }
    IOas30MediaTypeParent parent = (IOas30MediaTypeParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parent)) {
        return;
    }
    Oas30MediaType mediaType = parent.createMediaType(this._mediaTypeName);
    Library.readNode(this._oldMediaType, mediaType);
    parent.addMediaType(this._mediaTypeName, mediaType);
}
Also used : IOas30MediaTypeParent(io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 3 with IOas30MediaTypeParent

use of io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent in project apicurio-data-models by Apicurio.

the class NewMediaTypeCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[NewMediaTypeCommand] Executing.");
    this._created = false;
    IOas30MediaTypeParent node = (IOas30MediaTypeParent) this._nodePath.resolve(document);
    if (this.isNullOrUndefined(node)) {
        return;
    }
    Oas30MediaType mediaType = node.getMediaType(this._newMediaType);
    if (ModelUtils.isDefined(mediaType)) {
        return;
    }
    node.addMediaType(this._newMediaType, node.createMediaType(this._newMediaType));
    this._created = true;
}
Also used : IOas30MediaTypeParent(io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 4 with IOas30MediaTypeParent

use of io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent in project apicurio-data-models by Apicurio.

the class DeleteMediaTypeCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[DeleteMediaTypeCommand] Executing.");
    this._oldMediaType = null;
    Oas30MediaType mediaType = (Oas30MediaType) this._mediaTypePath.resolve(document);
    if (this.isNullOrUndefined(mediaType)) {
        return;
    }
    IOas30MediaTypeParent parent = (IOas30MediaTypeParent) mediaType.parent();
    parent.removeMediaType(this._mediaTypeName);
    this._oldMediaType = Library.writeNode(mediaType);
}
Also used : IOas30MediaTypeParent(io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Aggregations

IOas30MediaTypeParent (io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent)4 Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)3