use of org.eclipse.winery.model.tosca.yaml.YTDataType 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;
}
use of org.eclipse.winery.model.tosca.yaml.YTDataType in project winery by eclipse.
the class SchemaVisitor method visit.
@Override
public Result visit(YTEntityType node, Parameter parameter) {
if (node instanceof YTDataType || node.getProperties().isEmpty()) {
return null;
}
// BuildPlan for assignments
Map<String, QName> plan = new LinkedHashMap<>();
String name = parameter.getKey() + "_Properties";
SchemaBuilder builder = new SchemaBuilder(parameter.getNamespace());
Map<String, String> imports = new LinkedHashMap<>();
for (Map.Entry<String, YTPropertyDefinition> entry : node.getProperties().entrySet()) {
builder.addElements(entry.getKey(), entry.getValue());
QName type = entry.getValue().getType();
if (type.getNamespaceURI() != null && !type.getNamespaceURI().equals(Namespaces.YAML_NS)) {
imports.put(type.getNamespaceURI(), type.getLocalPart());
}
plan.put(entry.getKey(), entry.getValue().getType());
}
imports.forEach((key, value) -> builder.addImports(key, getRelativeFileName(key)));
Document document = builder.buildComplexType(name, true).build();
WriterUtils.saveType(document, parameter.getPath(), parameter.getNamespace(), name);
// FIXME this needs access to a repository
WriterUtils.storeTypes(null, parameter.getPath(), name, parameter.getNamespace(), name);
this.propertyDefinition.put(new QName(parameter.getNamespace(), name), plan);
return null;
}
use of org.eclipse.winery.model.tosca.yaml.YTDataType in project winery by eclipse.
the class ToCanonical method convert.
public TDataType convert(YTDataType node, String id) {
String name = fixNamespaceDuplication(id, node.getMetadata().get("targetNamespace"));
TDataType.Builder builder = new TDataType.Builder(name).addConstraints(convertList(node.getConstraints(), this::convert));
fillEntityTypeProperties(node, builder);
TDataType result = builder.build();
// FIXME need to actually transform the node.getProperties() to an xml schema
// to be able to import it and add a PropertiesDefinition reference to that schema
String namespace = this.namespace;
if (namespace == null) {
// attempt to patch namespace with the definitions' targetNamespace
namespace = result.getTargetNamespace();
}
if (namespace == null) {
LOGGER.warn("Could not determine namespace for DataType {}. Imports may be incorrect!", id);
return result;
}
TImport importDefinition = new TImport.Builder(Namespaces.XML_NS).setLocation(EncodingUtil.URLencode(namespace) + ".xsd").setNamespace(namespace).build();
if (!this.imports.contains(importDefinition)) {
this.imports.add(importDefinition);
}
return result;
}
Aggregations