Search in sources :

Example 1 with AaiMessage

use of io.apicurio.datamodels.asyncapi.models.AaiMessage in project apicurio-data-models by Apicurio.

the class NewMessageDefinitionCommand method execute.

@Override
public void execute(Document document) {
    LoggerCompat.info("[NewMessageDefinitionCommand] Executing.");
    Aai20Document doc20 = (Aai20Document) document;
    if (this.isNullOrUndefined(doc20.components)) {
        doc20.components = doc20.createComponents();
        this._nullComponents = true;
    }
    this._nullComponents = false;
    Aai20Components components = (Aai20Components) doc20.components;
    if (this.isNullOrUndefined(components.getMessageTraitDefinition(_newName))) {
        Aai20NodeFactory factory = new Aai20NodeFactory();
        AaiMessage msgDef = factory.createMessage(components, _newName);
        if (!this.isNullOrUndefined(_newDescription != null)) {
            msgDef.description = _newDescription;
        }
        components.addMessage(_newName, msgDef);
        this._defExisted = false;
    } else {
        this._defExisted = true;
    }
}
Also used : Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) Aai20NodeFactory(io.apicurio.datamodels.asyncapi.v2.models.Aai20NodeFactory) Aai20Components(io.apicurio.datamodels.asyncapi.v2.models.Aai20Components) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 2 with AaiMessage

use of io.apicurio.datamodels.asyncapi.models.AaiMessage in project apicurio-data-models by Apicurio.

the class DeleteOneOfMessageCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(Document)
 */
@Override
public void execute(final Document document) {
    LoggerCompat.info("[DeleteOneOfMessageCommand] Executing.");
    final AaiMessage parent = (AaiMessage) this._parentPath.resolve(document);
    final AaiMessage res = parent.deleteOneOfMessage(this._oneOfIdc);
    boolean isOneOfMessage = res._isOneOfMessage;
    if (!isOneOfMessage) {
        return;
    }
    if (!this.isNullOrUndefined(res)) {
        this._oldMessage = Library.writeNode(res);
    }
}
Also used : AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 3 with AaiMessage

use of io.apicurio.datamodels.asyncapi.models.AaiMessage in project apicurio-data-models by Apicurio.

the class ChangePayloadRefCommand_Aai20 method execute.

@Override
public void execute(Document document) {
    LoggerCompat.info("[ChangePayloadRefCommand_Aai20] Executing.");
    this._changed = false;
    AaiMessage message;
    // Legacy: lookup from operation path
    if (!this.isNullOrUndefined(this._operationPath)) {
        AaiOperation operation = (AaiOperation) this._operationPath.resolve(document);
        if (this.isNullOrUndefined(operation) || this.isNullOrUndefined(operation.message)) {
            return;
        }
        message = operation.message;
    } else {
        message = (AaiMessage) this._messagePath.resolve(document);
    }
    if (this.isNullOrUndefined(message)) {
        return;
    }
    Object payload = message.payload;
    if (payload == null) {
        payload = JsonCompat.objectNode();
    }
    Object oldValue = JsonCompat.getProperty(payload, "$ref");
    if (oldValue != null && JsonCompat.isString(oldValue)) {
        this._oldPayloadRef = JsonCompat.toString(oldValue);
    }
    JsonCompat.setProperty(payload, "$ref", this._payloadRef);
    this._changed = true;
}
Also used : AaiOperation(io.apicurio.datamodels.asyncapi.models.AaiOperation) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 4 with AaiMessage

use of io.apicurio.datamodels.asyncapi.models.AaiMessage in project apicurio-data-models by Apicurio.

the class ChangePayloadRefCommand_Aai20 method undo.

@Override
public void undo(Document document) {
    LoggerCompat.info("[ChangePayloadRefCommand_Aai20] Reverting.");
    if (!this._changed) {
        return;
    }
    AaiMessage message;
    if (!this.isNullOrUndefined(this._operationPath)) {
        AaiOperation operation = (AaiOperation) this._operationPath.resolve(document);
        if (this.isNullOrUndefined(operation)) {
            return;
        }
        message = operation.message;
    } else {
        message = (AaiMessage) this._messagePath.resolve(document);
    }
    if (this.isNullOrUndefined(message)) {
        return;
    }
    Object payload = message.payload;
    if (this._oldPayloadRef != null) {
        JsonCompat.setProperty(payload, "$ref", this._oldPayloadRef);
    } else {
        JsonCompat.consumeProperty(payload, "$ref");
    }
}
Also used : AaiOperation(io.apicurio.datamodels.asyncapi.models.AaiOperation) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 5 with AaiMessage

use of io.apicurio.datamodels.asyncapi.models.AaiMessage in project apicurio-data-models by Apicurio.

the class AddOneOfInMessageCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[AddOneOfInMessageCommand] Reverting.");
    if (this.isNullOrUndefined(this._oldMessage)) {
        return;
    }
    final AaiMessage parentMessage = (AaiMessage) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parentMessage)) {
        return;
    }
    NodeCompat.setProperty(parentMessage.parent(), "message", parentMessage);
    parentMessage.oneOf = null;
    Library.readNode(this._oldMessage, parentMessage);
}
Also used : AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Aggregations

AaiMessage (io.apicurio.datamodels.asyncapi.models.AaiMessage)17 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)4 AaiOperation (io.apicurio.datamodels.asyncapi.models.AaiOperation)3 AaiSchema (io.apicurio.datamodels.asyncapi.models.AaiSchema)3 Aai20Message (io.apicurio.datamodels.asyncapi.v2.models.Aai20Message)2 Aai20NodeFactory (io.apicurio.datamodels.asyncapi.v2.models.Aai20NodeFactory)2 IPropertySchema (io.apicurio.datamodels.core.models.common.IPropertySchema)2 Schema (io.apicurio.datamodels.core.models.common.Schema)2 OasSchema (io.apicurio.datamodels.openapi.models.OasSchema)2 Oas30AnyOfSchema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30AnyOfSchema)2 Oas30NotSchema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30NotSchema)2 Oas30OneOfSchema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30OneOfSchema)2 AaiChannelBindingsDefinition (io.apicurio.datamodels.asyncapi.models.AaiChannelBindingsDefinition)1 AaiComponents (io.apicurio.datamodels.asyncapi.models.AaiComponents)1 AaiCorrelationId (io.apicurio.datamodels.asyncapi.models.AaiCorrelationId)1 AaiDocument (io.apicurio.datamodels.asyncapi.models.AaiDocument)1 AaiMessageBindingsDefinition (io.apicurio.datamodels.asyncapi.models.AaiMessageBindingsDefinition)1 AaiMessageTrait (io.apicurio.datamodels.asyncapi.models.AaiMessageTrait)1 AaiMessageTraitDefinition (io.apicurio.datamodels.asyncapi.models.AaiMessageTraitDefinition)1 AaiOperationBindingsDefinition (io.apicurio.datamodels.asyncapi.models.AaiOperationBindingsDefinition)1