use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.
the class YamlRepository method readServiceTemplate.
/**
* Reads service template from target path
*
* @param targetPath target path of service template
* @return yaml service template
*/
private YTServiceTemplate readServiceTemplate(Path targetPath) throws IOException, MultiException {
InputStream in = newInputStream(targetPath);
LOGGER.debug("Reading service template from {}", targetPath);
return new YamlReader().parse(in);
}
use of org.eclipse.winery.repository.converter.reader.YamlReader 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;
}
use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.
the class SchemaVisitor method visit.
@Override
public Result visit(YTDataType node, Parameter parameter) {
SchemaBuilder builder;
if (this.schemaBuilders.containsKey(parameter.getNamespace())) {
builder = this.schemaBuilders.get(parameter.getNamespace());
} else {
builder = new SchemaBuilder(parameter.getNamespace());
this.schemaBuilders.put(parameter.getNamespace(), builder);
}
Map<String, QName> buildPlan = new LinkedHashMap<>();
for (Map.Entry<String, YTPropertyDefinition> entry : node.getProperties().entrySet()) {
QName type = entry.getValue().getType();
buildPlan.put(entry.getKey(), entry.getValue().getType());
// Add default YAML types
if (type.getNamespaceURI().equals(Namespaces.YAML_NS)) {
builder.addElements(entry.getKey(), entry.getValue());
} else // if parameter.datatype is not defined and property type is defined in this schema -> add
if (parameter.getDatatype() == null && type.getNamespaceURI().equals(parameter.getNamespace()) && this.localDatatypeNames.contains(type.getLocalPart())) {
builder.addElements(entry.getKey(), entry.getValue());
} else // if parameter.datatype is defined and property type is not in this service template
if (!type.getNamespaceURI().equals(parameter.getNamespace()) || !this.localDatatypeNames.contains(type.getLocalPart())) {
for (Map.Entry<String, YTImportDefinition> importDefinition : imports.get(type.getNamespaceURI())) {
try {
YamlReader reader = new YamlReader();
YTServiceTemplate serviceTemplate = reader.parse(importDefinition.getValue(), parameter.getPath(), importDefinition.getValue().getNamespaceUri());
visit(serviceTemplate, new Parameter(parameter.getPath(), type.getNamespaceURI()).setDatatype(type).setBuildSchema(false));
// TODO getAbsoluteFilePath
builder.addImports(importDefinition.getValue().getNamespaceUri(), getRelativeFileName(importDefinition.getValue().getNamespaceUri()));
builder.addElements(entry.getKey(), entry.getValue());
} catch (MultiException e) {
setException(e);
}
}
} else // if parameter.datatype is defined and property type is in this service template but not read
if (!(this.schemaTypes.containsKey(parameter.getNamespace()) && this.schemaTypes.get(parameter.getNamespace()).contains(type.getLocalPart()))) {
this.data_types.get(type.getLocalPart()).accept(this, parameter.copy().addContext(type.getLocalPart()).setDatatype(type));
builder.addElements(entry.getKey(), entry.getValue());
}
}
this.addSchemaTypes(parameter.getNamespace(), parameter.getKey());
this.propertyDefinition.put(new QName(parameter.getNamespace(), parameter.getKey()), buildPlan);
if (parameter.getBuildComplexType()) {
builder.buildComplexType(parameter.getKey(), false);
}
return null;
}
use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.
the class YamlReaderTest method testPolicyDefinitionsAsMap.
@Test
public void testPolicyDefinitionsAsMap() throws Exception {
YamlReader reader = new YamlReader();
InputStream is = getClass().getClassLoader().getResourceAsStream("yaml/simple-tests/wrong-policy-map-in-tt.yml");
YTServiceTemplate template = reader.parse(is);
Assertions.assertNotNull(template);
YTTopologyTemplateDefinition topologyTemplate = template.getTopologyTemplate();
Assertions.assertNotNull(topologyTemplate);
Assertions.assertEquals(0, topologyTemplate.getPolicies().size());
}
use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.
the class YamlReaderTest method testBuilder.
@DisplayName("Simple YAML Reader Test")
@ParameterizedTest
@MethodSource("getYamlFiles")
public void testBuilder(Path filename) throws Exception {
YamlReader reader = new YamlReader();
InputStream is = new FileInputStream(new File(path.toFile(), filename.toString()));
Assertions.assertNotNull(reader.parse(is));
}
Aggregations