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