use of org.eclipse.winery.model.tosca.yaml.YTImportDefinition in project winery by eclipse.
the class YamlRepository method addImports.
/**
* Adds new import to existing imports
*
* @param oldImports existing imports
* @param newImport new import
* @return edited imports
*/
private List<YTMapImportDefinition> addImports(List<YTMapImportDefinition> oldImports, List<YTMapImportDefinition> newImport) {
if (newImport.isEmpty()) {
return oldImports;
}
if (newImport.get(0).isEmpty()) {
return oldImports;
}
Map.Entry<String, YTImportDefinition> targetImport = newImport.get(0).entrySet().iterator().next();
for (YTMapImportDefinition tMapImportDefinition : oldImports) {
for (Map.Entry<String, YTImportDefinition> tImportDefinitionEntry : tMapImportDefinition.entrySet()) {
if (tImportDefinitionEntry.getKey().equalsIgnoreCase(targetImport.getKey())) {
if (tImportDefinitionEntry.getValue().equals(targetImport.getValue())) {
return oldImports;
}
}
}
}
oldImports.get(0).put(targetImport.getKey(), targetImport.getValue());
return oldImports;
}
use of org.eclipse.winery.model.tosca.yaml.YTImportDefinition in project winery by eclipse.
the class FromCanonical method addNewImports.
private List<YTMapImportDefinition> addNewImports(List<YTMapImportDefinition> imports) {
List<YTMapImportDefinition> newImportsList = convertImports();
if (newImportsList.isEmpty()) {
return imports;
}
if (imports.isEmpty()) {
return newImportsList;
}
YTMapImportDefinition newImports = newImportsList.get(0);
YTMapImportDefinition existingImports = imports.get(0);
for (Map.Entry<String, YTImportDefinition> newImport : newImports.entrySet()) {
boolean found = false;
for (Map.Entry<String, YTImportDefinition> existingImport : existingImports.entrySet()) {
if (newImport.getKey().equalsIgnoreCase(existingImport.getKey()) && newImport.getValue().equals(existingImport.getValue())) {
found = true;
break;
}
}
if (!found) {
existingImports.put(newImport.getKey(), newImport.getValue());
}
}
imports.set(0, newImports);
return imports;
}
use of org.eclipse.winery.model.tosca.yaml.YTImportDefinition in project winery by eclipse.
the class SchemaVisitor method visit.
@Override
public Result visit(YTServiceTemplate node, Parameter parameter) {
Map<String, YTDataType> tmpDataTypes = this.data_types;
this.data_types = node.getDataTypes();
for (YTMapImportDefinition map : node.getImports()) {
for (Map.Entry<String, YTImportDefinition> entry : map.entrySet()) {
addImport(entry.getValue().getNamespaceUri(), new AbstractMap.SimpleEntry<>(entry));
}
}
// init localDataTypesList
node.getDataTypes().forEach((key, value) -> this.localDatatypeNames.add(key));
// Default: parameter.datatype is not set -> visit all datatype nodes
QName type = parameter.getDatatype();
if (type == null) {
for (Map.Entry<String, YTDataType> entry : node.getDataTypes().entrySet()) {
if (entry.getValue() != null) {
entry.getValue().accept(this, parameter.copy().addContext("datatypes", entry.getKey()));
}
}
visitChildren(node, parameter);
} else // Optimized: parameter.datatype is set and defined in this service template
if (type.getNamespaceURI().equals(parameter.getNamespace()) && this.localDatatypeNames.contains(type.getLocalPart())) {
node.getDataTypes().get(parameter.getDatatype().getLocalPart()).accept(this, parameter.copy().addContext("datatypes", parameter.getDatatype().getLocalPart()));
}
if (parameter.getBuildSchema()) {
for (Map.Entry<String, SchemaBuilder> entry : schemaBuilders.entrySet()) {
Document document = entry.getValue().build();
WriterUtils.saveType(document, parameter.getPath(), parameter.getNamespace(), entry.getValue().getNamespace());
}
}
this.data_types = tmpDataTypes;
return null;
}
use of org.eclipse.winery.model.tosca.yaml.YTImportDefinition in project winery by eclipse.
the class FromCanonical method convertImports.
public List<YTMapImportDefinition> convertImports() {
List<YTMapImportDefinition> imports = new ArrayList<>();
YTMapImportDefinition tMapImportDefinition = new YTMapImportDefinition();
for (Map.Entry<DefinitionsChildId, TDefinitions> importDefinition : importDefinitions.entrySet()) {
YTImportDefinition tImportDefinition = new YTImportDefinition.Builder(YamlExporter.getDefinitionsName(repository, importDefinition.getKey()).concat(Constants.SUFFIX_TOSCA_DEFINITIONS)).setNamespacePrefix(getNamespacePrefix(importDefinition.getKey().getQName().getNamespaceURI())).setNamespaceUri(importDefinition.getKey().getQName().getNamespaceURI()).build();
tMapImportDefinition.put(importDefinition.getKey().getQName().getLocalPart(), tImportDefinition);
}
if (!tMapImportDefinition.isEmpty()) {
imports.add(tMapImportDefinition);
return imports;
} else {
return null;
}
}
use of org.eclipse.winery.model.tosca.yaml.YTImportDefinition in project winery by eclipse.
the class FromCanonical method prepareExistingImports.
private YTMapImportDefinition prepareExistingImports(Map<String, QName> importDefinitions) {
YTMapImportDefinition tMapImportDefinition = new YTMapImportDefinition();
importDefinitions.forEach((key, value) -> {
YTImportDefinition tImportDefinition = new YTImportDefinition.Builder(key).setNamespacePrefix(getNamespacePrefix(value.getNamespaceURI())).setNamespaceUri(value.getNamespaceURI()).build();
tMapImportDefinition.put(value.getLocalPart(), tImportDefinition);
});
return tMapImportDefinition;
}
Aggregations