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);
}
}
}
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;
}
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;
});
}
}
}
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);
}
}
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);
}
}
Aggregations