use of io.apicurio.datamodels.core.models.Node in project apicurio-data-models by Apicurio.
the class DeleteAllExamplesCommand method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[DeleteAllExamplesCommand] Executing.");
if (this.isNullOrUndefined(document)) {
LoggerCompat.debug("[DeleteAllExamplesCommand] Could not execute the command, invalid argument.");
return;
}
if (this.isNullOrUndefined(this._mediaTypePath)) {
LoggerCompat.debug("[DeleteAllExamplesCommand] Could not execute the command, problem when unmarshalling.");
return;
}
IExamplesParent parent = (IExamplesParent) this._mediaTypePath.resolve(document);
if (this.isNullOrUndefined(parent)) {
LoggerCompat.debug("[DeleteAllExamplesCommand] Media type not found.");
return;
}
this._oldExamples = new HashMap<>();
parent.getExamples().forEach(e -> {
this._oldExamples.put(e.getName(), Library.writeNode((Node) e));
});
parent.clearExamples();
}
use of io.apicurio.datamodels.core.models.Node in project apicurio-data-models by Apicurio.
the class DeleteAllParameterExamplesCommand method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[DeleteAllParameterExamplesCommand] Executing.");
if (this.isNullOrUndefined(document)) {
LoggerCompat.debug("[DeleteAllParameterExamplesCommand] Could not execute the command, invalid argument.");
return;
}
if (this.isNullOrUndefined(this._parameterPath)) {
LoggerCompat.debug("[DeleteAllParameterExamplesCommand] Could not execute the command, problem when unmarshalling.");
return;
}
Oas30Parameter parameter = (Oas30Parameter) this._parameterPath.resolve(document);
if (this.isNullOrUndefined(parameter)) {
LoggerCompat.debug("[DeleteAllParameterExamplesCommand] Parameter not found.");
return;
}
this._oldExamples = new HashMap<>();
parameter.getExamples().forEach(e -> {
this._oldExamples.put(e.getName(), Library.writeNode((Node) e));
});
parameter.clearExamples();
}
use of io.apicurio.datamodels.core.models.Node 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);
}
use of io.apicurio.datamodels.core.models.Node in project apicurio-data-models by Apicurio.
the class ChangePropertyCommand method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@SuppressWarnings("unchecked")
@Override
public void execute(Document document) {
LoggerCompat.info("[ChangePropertyCommand] Executing.");
Node node = this._nodePath.resolve(document);
if (this.isNullOrUndefined(node)) {
return;
}
this._oldValue = (T) NodeCompat.getProperty(node, this._property);
NodeCompat.setProperty(node, this._property, this._newValue);
}
use of io.apicurio.datamodels.core.models.Node in project apicurio-data-models by Apicurio.
the class ChangePropertyTypeCommand method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[ChangePropertyTypeCommand] Executing: " + this._newType);
IPropertySchema prop = (IPropertySchema) this._propPath.resolve(document);
if (this.isNullOrUndefined(prop)) {
return;
}
IPropertyParent parent = (IPropertyParent) ((Node) prop).parent();
List<String> required = parent.getRequiredProperties();
// Save the old info (for later undo operation)
this._oldProperty = Library.writeNode((Node) prop);
this._oldRequired = ModelUtils.isDefined(required) && required.size() > 0 && required.indexOf(prop.getPropertyName()) != -1;
// Update the schema's type
SimplifiedTypeUtil.setSimplifiedType((Schema) prop, this._newType);
if (!this.isNullOrUndefined(this._newType.required)) {
// Going from optional to required
if (Boolean.TRUE.equals(this._newType.required) && !this._oldRequired) {
if (this.isNullOrUndefined(required)) {
required = new ArrayList<>();
parent.setRequiredProperties(required);
this._nullRequired = true;
}
required.add(prop.getPropertyName());
}
// Going from required to optional - remove property name from required list.
if (Boolean.FALSE.equals(this._newType.required) && this._oldRequired) {
required.remove(required.indexOf(prop.getPropertyName()));
}
}
}
Aggregations