Search in sources :

Example 11 with AaiMessage

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

the class RenameSchemaDefinitionCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[RenameSchemaDefinitionCommand] Executing.");
    this._references = new ArrayList<>();
    this._messageReferences = new ArrayList<>();
    if (this._renameSchemaDefinition(document, this._oldName, this._newName)) {
        String oldRef = this._nameToReference(this._oldName);
        String newRef = this._nameToReference(this._newName);
        SchemaRefFinder schemaFinder = new SchemaRefFinder(oldRef);
        SchemaRefFinder.ReferenceHolder referenceHolder = schemaFinder.findIn(document);
        for (Schema schema : referenceHolder.getSchemas()) {
            this._references.add(Library.createNodePath(schema));
            schema.$ref = newRef;
        }
        for (AaiMessage aaiMessage : referenceHolder.getMessages()) {
            this._messageReferences.add(Library.createNodePath(aaiMessage));
            JsonCompat.setPropertyString(aaiMessage.payload, "$ref", newRef);
        }
    }
}
Also used : Schema(io.apicurio.datamodels.core.models.common.Schema) Oas30OneOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30OneOfSchema) Oas30NotSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30NotSchema) AaiSchema(io.apicurio.datamodels.asyncapi.models.AaiSchema) IPropertySchema(io.apicurio.datamodels.core.models.common.IPropertySchema) OasSchema(io.apicurio.datamodels.openapi.models.OasSchema) Oas30AnyOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30AnyOfSchema) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 12 with AaiMessage

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

the class RenameMessageDefinitionCommand method renameMessageDefinition.

protected boolean renameMessageDefinition(AaiDocument document, String fromName, String toName) {
    Aai20Document doc20 = (Aai20Document) document;
    if (this.isNullOrUndefined(doc20.components) || this.isNullOrUndefined(doc20.components.messages)) {
        return false;
    }
    if (ModelUtils.isDefined(doc20.components.getMessage(toName))) {
        return false;
    }
    AaiMessage msgDef = doc20.components.removeMessage(fromName);
    msgDef.rename(toName);
    doc20.components.addMessage(toName, msgDef);
    return true;
}
Also used : Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 13 with AaiMessage

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

the class RenameMessageDefinitionCommand method undo.

@Override
public void undo(Document document) {
    LoggerCompat.info("[RenameMessageDefinitionCommand] Reverting.");
    if (this.renameMessageDefinition((AaiDocument) document, this._newName, this._oldName)) {
        String oldRef = this.nameToReference(this._oldName);
        if (ModelUtils.isDefined(this._references)) {
            this._references.forEach(ref -> {
                AaiMessage message = (AaiMessage) ref.resolve(document);
                message.$ref = oldRef;
            });
        }
    }
}
Also used : AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 14 with AaiMessage

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

the class DeleteMessageDefinitionCommand method undo.

@Override
public void undo(Document document) {
    LoggerCompat.info("[DeleteMessageDefinitionCommand] Reverting.");
    if (this.isNullOrUndefined(this._oldDefinition)) {
        return;
    }
    Aai20Document doc20 = (Aai20Document) document;
    if (ModelUtils.isDefined(doc20.components)) {
        Aai20NodeFactory factory = new Aai20NodeFactory();
        AaiMessage msgDef = factory.createMessage(doc20.components, _name);
        Library.readNode(_oldDefinition, msgDef);
        doc20.components.addMessage(_name, msgDef);
    }
}
Also used : Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) Aai20NodeFactory(io.apicurio.datamodels.asyncapi.v2.models.Aai20NodeFactory) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 15 with AaiMessage

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

the class DeleteMessageDefinitionCommand method execute.

@Override
public void execute(Document document) {
    LoggerCompat.info("[DeleteMessageDefinitionCommand] Executing.");
    Aai20Document doc20 = (Aai20Document) document;
    if (ModelUtils.isDefined(doc20.components)) {
        AaiMessage msgDef = doc20.components.removeMessage(_name);
        this._oldDefinition = Library.writeNode(msgDef);
    }
}
Also used : Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) 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