use of org.eclipse.winery.model.tosca.yaml.TServiceTemplate in project winery by eclipse.
the class Datatypes method testDataTypesRecursive.
@Test
public void testDataTypesRecursive() throws Exception {
String name = "data_types-recursive";
String namespace = "http://www.example.com/DataTypesRecursive";
TServiceTemplate serviceTemplate = readServiceTemplate(name, namespace);
Definitions definitions = convert(serviceTemplate, name, namespace);
writeXml(definitions, name, namespace);
Assert.assertNotNull(definitions);
}
use of org.eclipse.winery.model.tosca.yaml.TServiceTemplate in project winery by eclipse.
the class Datatypes method testDataTypesWithImport.
@Test
public void testDataTypesWithImport() throws Exception {
String name = "data_types-with_import";
String namespace = "http://www.example.com/DataTypesWithImportTest";
TServiceTemplate serviceTemplate = readServiceTemplate(name, namespace);
Definitions definitions = convert(serviceTemplate, name, namespace);
writeXml(definitions, name, namespace);
Assert.assertNotNull(definitions);
}
use of org.eclipse.winery.model.tosca.yaml.TServiceTemplate in project winery by eclipse.
the class ImportVisitor method visit.
@Override
public Result visit(TImportDefinition node, Parameter parameter) {
Reader reader = Reader.getReader();
String importNamespace = node.getNamespaceUri() == null ? this.namespace : node.getNamespaceUri();
try {
TServiceTemplate serviceTemplate = reader.parse(node, path, importNamespace);
if (serviceTemplate != null) {
String tmpNamespace = this.namespace;
this.namespace = importNamespace;
this.visit(serviceTemplate, new Parameter());
this.namespace = tmpNamespace;
}
super.visit(node, parameter);
} catch (MultiException e) {
this.setException(e);
}
return null;
}
use of org.eclipse.winery.model.tosca.yaml.TServiceTemplate in project winery by eclipse.
the class YamlWriterTest method roundTripSingleTest.
@DisplayName("Test read and write single round trip")
@ParameterizedTest(name = "{index} name=''{0}''")
@ValueSource(strings = { "example_16-topology_templates-1_1" })
public void roundTripSingleTest(String file) throws Exception {
Path fileName = getYamlFile(file);
TServiceTemplate serviceTemplate = this.getYamlServiceTemplate(fileName);
writeYamlServiceTemplate(serviceTemplate, temporaryFolder.resolve(fileName));
TServiceTemplate out = this.getYamlServiceTemplate(fileName, temporaryFolder);
Assertions.assertEquals(serviceTemplate, out);
}
use of org.eclipse.winery.model.tosca.yaml.TServiceTemplate in project winery by eclipse.
the class X2YConverter method convert.
/**
* Converts TOSCA XML Definitions to TOSCA YAML ServiceTemplates
*/
@NonNull
public Map<Path, TServiceTemplate> convert(Definitions node, Path outPath, QName name) throws MultiException {
if (Objects.isNull(node))
return new LinkedHashMap<>();
QName tmpName = name;
LOGGER.debug("Convert TServiceTemplate: {}", node.getIdFromIdOrNameField());
TServiceTemplate.Builder builder = new TServiceTemplate.Builder(Defaults.TOSCA_DEFINITIONS_VERSION).setDescription(convertDocumentation(node.getDocumentation())).setArtifactTypes(convert(node.getArtifactTypes())).setCapabilityTypes(convert(node.getCapabilityTypes())).setRelationshipTypes(convert(node.getRelationshipTypes())).setNodeTypes(convert(node.getNodeTypes())).setPolicyTypes(convert(node.getPolicyTypes()));
if (node.getServiceTemplates().size() == 1) {
builder.setTopologyTemplate(convert(node.getServiceTemplates().get(0)));
if (Objects.nonNull(node.getServiceTemplates().get(0).getName())) {
tmpName = new QName(node.getServiceTemplates().get(0).getName());
}
builder.addMetadata("targetNamespace", node.getTargetNamespace());
}
MultiException exception = importDefinitions.entrySet().stream().map((entry) -> {
Path path = this.path.resolve(entry.getKey().getGroup()).resolve(entry.getKey().getNamespace().getEncoded());
try {
Map<Path, TServiceTemplate> map = new X2YConverter(repository, this.path).convert(entry.getValue(), path, entry.getKey().getQName());
Optional.ofNullable(map).orElse(new LinkedHashMap<>()).forEach((Path key, TServiceTemplate value) -> builder.addImports(key.toFile().getName(), new TImportDefinition.Builder(this.path.relativize(key).toString()).setNamespaceUri(entry.getValue().getTargetNamespace()).setNamespacePrefix(getNamespacePrefix(entry.getValue().getTargetNamespace())).build()));
} catch (MultiException e) {
return e;
}
return null;
}).filter(Objects::nonNull).reduce(new MultiException(), (a, b) -> a.add(b.getException()));
if (exception.hasException()) {
throw exception;
}
TServiceTemplate serviceTemplate = builder.build();
Path filePath = outPath.resolve(tmpName.getLocalPart().concat(".yml"));
try {
Files.createDirectories(filePath.getParent());
Writer writer = new Writer();
writer.write(serviceTemplate, filePath);
return Collections.singletonMap(filePath, serviceTemplate);
} catch (IOException e) {
LOGGER.error("Could not create file path {}", filePath.getParent());
}
return new LinkedHashMap<>();
}
Aggregations