use of org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition in project winery by eclipse.
the class ToCanonical method fillEntityTypeProperties.
private <Builder extends TEntityType.Builder<Builder>, Value extends XTEntityType> void fillEntityTypeProperties(Builder builder, Value xml) {
if (xml.getTags() != null) {
builder.addTags(xml.getTags().stream().map(this::convert).collect(Collectors.toList()));
}
if (xml.getDerivedFrom() != null) {
TEntityType.DerivedFrom derived = new TEntityType.DerivedFrom();
derived.setTypeRef(xml.getDerivedFrom().getTypeRef());
builder.setDerivedFrom(derived);
}
if (xml.getPropertiesDefinition() != null) {
if (xml.getPropertiesDefinition().getElement() != null) {
builder.setProperties(new TEntityType.XmlElementDefinition(xml.getPropertiesDefinition().getElement()));
} else if (xml.getPropertiesDefinition().getType() != null) {
builder.setProperties(new TEntityType.XmlTypeDefinition(xml.getPropertiesDefinition().getType()));
} else {
throw new IllegalStateException("If a PropertiesDefinition is given, either Element or Type must be specified!");
}
}
if (xml.getAny().stream().anyMatch(anyElement -> anyElement instanceof WinerysPropertiesDefinition)) {
WinerysPropertiesDefinition def = xml.getAny().stream().filter(el -> el instanceof WinerysPropertiesDefinition).map(WinerysPropertiesDefinition.class::cast).findFirst().orElse(null);
builder.setProperties(def);
// remove the element we've recognized as a property to avoid duplicating it in the canonical model
xml.getAny().remove(def);
}
builder.setAbstract(xml.getAbstract() == XTBoolean.YES);
builder.setFinal(xml.getFinal() == XTBoolean.YES);
builder.setTargetNamespace(xml.getTargetNamespace());
fillExtensibleElementsProperties(builder, xml);
}
use of org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition in project winery by eclipse.
the class ToscaExportUtil method exportEntityType.
protected void exportEntityType(TDefinitions entryDefinitions, URI uri, DefinitionsChildId tcId) {
TEntityType entityType = (TEntityType) entryDefinitions.getElement();
// we have an entity type with a possible properties definition
WinerysPropertiesDefinition wpd = entityType.getWinerysPropertiesDefinition();
if (wpd != null) {
if (wpd.getIsDerivedFromXSD() == null) {
// Write WPD only to file if it exists and is NOT derived from an XSD (which may happen during import)
String wrapperElementNamespace = wpd.getNamespace();
String wrapperElementLocalName = wpd.getElementName();
// BEGIN: add import and put into CSAR
TImport imp = new TImport();
entryDefinitions.getImport().add(imp);
// fill known import values
imp.setImportType(XMLConstants.W3C_XML_SCHEMA_NS_URI);
imp.setNamespace(wrapperElementNamespace);
// add "winerysPropertiesDefinition" flag to import tag to support
Map<QName, String> otherAttributes = imp.getOtherAttributes();
otherAttributes.put(QNames.QNAME_WINERYS_PROPERTIES_DEFINITION_ATTRIBUTE, "true");
// Determine location
String loc = BackendUtils.getImportLocationForWinerysPropertiesDefinitionXSD((EntityTypeId) tcId, uri, wrapperElementLocalName);
if (uri == null) {
ToscaExportUtil.LOGGER.trace("CSAR Export mode. Putting XSD into CSAR");
// CSAR Export mode
// XSD has to be put into the CSAR
Document document = ModelUtilities.getWinerysPropertiesDefinitionXsdAsDocument(wpd);
// loc in import is URL encoded, loc on filesystem isn't
String locInCSAR = EncodingUtil.URLdecode(loc);
// furthermore, the path has to start from the root of the CSAR; currently, it starts from Definitions/
locInCSAR = locInCSAR.substring(3);
ToscaExportUtil.LOGGER.trace("Location in CSAR: {}", locInCSAR);
CsarContentProperties csarContentProperties = new CsarContentProperties(locInCSAR);
this.referencesToPathInCSARMap.put(csarContentProperties, new DocumentBasedCsarEntry(document));
}
imp.setLocation(loc);
// END: add import and put into CSAR
// BEGIN: generate TOSCA conforming PropertiesDefinition
// Winerys properties definitions are serialized as an XSD.
// As such their TOSCA representation is a type reference, so we generate that here.
// Of course that breaks when we export as YAML, but this exporter basically targets XML in the first place
// TODO: future work — deal with WPD when exporting to YAML
// (a map[string, string] can be represented as a TDataType)
TEntityType.XmlTypeDefinition propertiesDefinition = new TEntityType.XmlTypeDefinition();
propertiesDefinition.setType(new QName(wrapperElementNamespace, wrapperElementLocalName));
entityType.setProperties(propertiesDefinition);
// END: generate TOSCA conforming PropertiesDefinition
} else {
// otherwise WPD exists, but is derived from XSD
// we DO NOT have to remove the winery properties definition from the output to allow "debugging" of the CSAR
}
}
}
Aggregations