Search in sources :

Example 1 with YTImportDefinition

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;
}
Also used : YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) YTImportDefinition(org.eclipse.winery.model.tosca.yaml.YTImportDefinition) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with YTImportDefinition

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;
}
Also used : YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) YTImportDefinition(org.eclipse.winery.model.tosca.yaml.YTImportDefinition) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashBiMap(org.eclipse.collections.impl.bimap.mutable.HashBiMap) HashMap(java.util.HashMap)

Example 3 with YTImportDefinition

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;
}
Also used : YTDataType(org.eclipse.winery.model.tosca.yaml.YTDataType) QName(javax.xml.namespace.QName) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) Document(org.w3c.dom.Document) AbstractMap(java.util.AbstractMap) YTImportDefinition(org.eclipse.winery.model.tosca.yaml.YTImportDefinition) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 4 with YTImportDefinition

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;
    }
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ArrayList(java.util.ArrayList) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) YTImportDefinition(org.eclipse.winery.model.tosca.yaml.YTImportDefinition) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashBiMap(org.eclipse.collections.impl.bimap.mutable.HashBiMap) HashMap(java.util.HashMap) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions)

Example 5 with YTImportDefinition

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;
}
Also used : YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) YTImportDefinition(org.eclipse.winery.model.tosca.yaml.YTImportDefinition)

Aggregations

YTImportDefinition (org.eclipse.winery.model.tosca.yaml.YTImportDefinition)7 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 YTMapImportDefinition (org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition)6 AbstractMap (java.util.AbstractMap)3 HashMap (java.util.HashMap)2 QName (javax.xml.namespace.QName)2 HashBiMap (org.eclipse.collections.impl.bimap.mutable.HashBiMap)2 MultiException (org.eclipse.winery.model.converter.support.exception.MultiException)2 YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)2 YamlReader (org.eclipse.winery.repository.converter.reader.YamlReader)2 ArrayList (java.util.ArrayList)1 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)1 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)1 YTDataType (org.eclipse.winery.model.tosca.yaml.YTDataType)1 YTPropertyDefinition (org.eclipse.winery.model.tosca.yaml.YTPropertyDefinition)1 Document (org.w3c.dom.Document)1