Search in sources :

Example 6 with YTMapImportDefinition

use of org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition 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 7 with YTMapImportDefinition

use of org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition 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)

Example 8 with YTMapImportDefinition

use of org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition in project winery by eclipse.

the class FromCanonical method convert.

/**
 * Converts canonical TDefinitions to a TOSCA YAML ServiceTemplate
 */
@NonNull
public YTServiceTemplate convert(TDefinitions node, boolean convertImports) {
    LOGGER.debug("Convert TServiceTemplate: {}", node.getIdFromIdOrNameField());
    YTServiceTemplate.Builder builder = new YTServiceTemplate.Builder(Defaults.TOSCA_DEFINITIONS_VERSION).setDescription(convertDocumentation(node.getElement().getDocumentation())).setArtifactTypes(convert(node.getArtifactTypes())).setCapabilityTypes(convert(node.getCapabilityTypes())).setRelationshipTypes(convert(node.getRelationshipTypes())).setNodeTypes(convert(node.getNodeTypes())).setPolicyTypes(convert(node.getPolicyTypes())).setInterfaceTypes(convert(node.getInterfaceTypes())).setDataTypes(convert(node.getDataTypes())).setGroupTypes(convert(node.getGroupTypes()));
    if (node.getServiceTemplates().size() == 1) {
        builder.setTopologyTemplate(convert(node.getServiceTemplates().get(0)));
        builder.addMetadata("targetNamespace", node.getTargetNamespace());
    }
    if (convertImports) {
        List<YTMapImportDefinition> imports = convertImports();
        YTMapImportDefinition existingImports = prepareExistingImports(node.getImportDefinitions());
        if (Objects.nonNull(imports)) {
            imports.stream().findFirst().ifPresent(def -> def.putAll(existingImports));
        } else if (!existingImports.isEmpty()) {
            imports = new ArrayList<>();
            imports.add(existingImports);
        }
        builder.setImports(imports);
    }
    return builder.build();
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) ArrayList(java.util.ArrayList) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 9 with YTMapImportDefinition

use of org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition in project winery by eclipse.

the class SchemaVisitor method visit.

public Map<QName, Map<String, QName>> visit(YTServiceTemplate node, Path path, Path outpath, String namespace) {
    for (YTMapImportDefinition map : node.getImports()) {
        for (Map.Entry<String, YTImportDefinition> entry : map.entrySet()) {
            YamlReader reader = new YamlReader();
            try {
                YTServiceTemplate serviceTemplate = reader.parse(entry.getValue(), path, entry.getValue().getNamespaceUri());
                visit(serviceTemplate, new Parameter(outpath, entry.getValue().getNamespaceUri()).setBuildSchema(false));
            } catch (MultiException e) {
                setException(e);
            }
        }
    }
    this.visit(node, new Parameter(outpath, namespace));
    return propertyDefinition;
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) YTImportDefinition(org.eclipse.winery.model.tosca.yaml.YTImportDefinition) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException)

Aggregations

YTMapImportDefinition (org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition)9 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 YTImportDefinition (org.eclipse.winery.model.tosca.yaml.YTImportDefinition)6 YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)3 AbstractMap (java.util.AbstractMap)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashBiMap (org.eclipse.collections.impl.bimap.mutable.HashBiMap)2 Path (java.nio.file.Path)1 QName (javax.xml.namespace.QName)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 MultiException (org.eclipse.winery.model.converter.support.exception.MultiException)1 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)1 CapabilityTypeId (org.eclipse.winery.model.ids.definitions.CapabilityTypeId)1 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)1 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)1 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)1 PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)1