Search in sources :

Example 21 with WinerysPropertiesDefinition

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);
}
Also used : XHasId(org.eclipse.winery.model.tosca.xml.XHasId) XTPropertyConstraint(org.eclipse.winery.model.tosca.xml.XTPropertyConstraint) XTNodeType(org.eclipse.winery.model.tosca.xml.XTNodeType) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) TArtifact(org.eclipse.winery.model.tosca.TArtifact) XTCapabilityDefinition(org.eclipse.winery.model.tosca.xml.XTCapabilityDefinition) XTEntityType(org.eclipse.winery.model.tosca.xml.XTEntityType) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) XTInterface(org.eclipse.winery.model.tosca.xml.XTInterface) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) XTParameter(org.eclipse.winery.model.tosca.xml.XTParameter) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) XTConstraint(org.eclipse.winery.model.tosca.xml.XTConstraint) OTRelationDirection(org.eclipse.winery.model.tosca.extensions.OTRelationDirection) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TEntityType(org.eclipse.winery.model.tosca.TEntityType) XTNodeTypeImplementation(org.eclipse.winery.model.tosca.xml.XTNodeTypeImplementation) XTRequirement(org.eclipse.winery.model.tosca.xml.XTRequirement) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) XTRelationshipTemplate(org.eclipse.winery.model.tosca.xml.XTRelationshipTemplate) XTOperation(org.eclipse.winery.model.tosca.xml.XTOperation) XTRelationshipType(org.eclipse.winery.model.tosca.xml.XTRelationshipType) XOTPropertyKV(org.eclipse.winery.model.tosca.xml.extensions.XOTPropertyKV) Stream(java.util.stream.Stream) TCapability(org.eclipse.winery.model.tosca.TCapability) XOTRelationMapping(org.eclipse.winery.model.tosca.xml.extensions.XOTRelationMapping) XTPlan(org.eclipse.winery.model.tosca.xml.XTPlan) QName(javax.xml.namespace.QName) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) TExtension(org.eclipse.winery.model.tosca.TExtension) NonNull(org.eclipse.jdt.annotation.NonNull) OTStringList(org.eclipse.winery.model.tosca.extensions.OTStringList) XOTPatternRefinementModel(org.eclipse.winery.model.tosca.xml.extensions.XOTPatternRefinementModel) TPolicy(org.eclipse.winery.model.tosca.TPolicy) XTPolicyTemplate(org.eclipse.winery.model.tosca.xml.XTPolicyTemplate) XTDeploymentArtifact(org.eclipse.winery.model.tosca.xml.XTDeploymentArtifact) XTArtifactTemplate(org.eclipse.winery.model.tosca.xml.XTArtifactTemplate) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) OTDeploymentArtifactMapping(org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping) RelationshipSourceOrTarget(org.eclipse.winery.model.tosca.RelationshipSourceOrTarget) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) XTExportedInterface(org.eclipse.winery.model.tosca.xml.XTExportedInterface) XTRequirementDefinition(org.eclipse.winery.model.tosca.xml.XTRequirementDefinition) TExportedInterface(org.eclipse.winery.model.tosca.TExportedInterface) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) XOTPermutationMapping(org.eclipse.winery.model.tosca.xml.extensions.XOTPermutationMapping) TArtifactReference(org.eclipse.winery.model.tosca.TArtifactReference) XTPolicy(org.eclipse.winery.model.tosca.xml.XTPolicy) TCapabilityRef(org.eclipse.winery.model.tosca.TCapabilityRef) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTAttributeMappingType(org.eclipse.winery.model.tosca.extensions.OTAttributeMappingType) XOTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.xml.extensions.XOTTopologyFragmentRefinementModel) XOTComplianceRule(org.eclipse.winery.model.tosca.xml.extensions.XOTComplianceRule) TCapabilityDefinition(org.eclipse.winery.model.tosca.TCapabilityDefinition) XTTag(org.eclipse.winery.model.tosca.xml.XTTag) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) TRequirementRef(org.eclipse.winery.model.tosca.TRequirementRef) OTParticipant(org.eclipse.winery.model.tosca.extensions.OTParticipant) XTEntityTypeImplementation(org.eclipse.winery.model.tosca.xml.XTEntityTypeImplementation) TPropertyMapping(org.eclipse.winery.model.tosca.TPropertyMapping) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) XOTStringList(org.eclipse.winery.model.tosca.xml.extensions.XOTStringList) XTNodeTemplate(org.eclipse.winery.model.tosca.xml.XTNodeTemplate) XTRequiredContainerFeature(org.eclipse.winery.model.tosca.xml.XTRequiredContainerFeature) XOTAttributeMapping(org.eclipse.winery.model.tosca.xml.extensions.XOTAttributeMapping) XTArtifactReference(org.eclipse.winery.model.tosca.xml.XTArtifactReference) XTExtension(org.eclipse.winery.model.tosca.xml.XTExtension) OTPrmMapping(org.eclipse.winery.model.tosca.extensions.OTPrmMapping) XTCondition(org.eclipse.winery.model.tosca.xml.XTCondition) TOperation(org.eclipse.winery.model.tosca.TOperation) XTImplementationArtifact(org.eclipse.winery.model.tosca.xml.XTImplementationArtifact) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) TGroupDefinition(org.eclipse.winery.model.tosca.TGroupDefinition) LoggerFactory(org.slf4j.LoggerFactory) XTRequirementType(org.eclipse.winery.model.tosca.xml.XTRequirementType) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) OTBehaviorPatternMapping(org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) XTDocumentation(org.eclipse.winery.model.tosca.xml.XTDocumentation) Nullable(org.eclipse.jdt.annotation.Nullable) XTEntityTemplate(org.eclipse.winery.model.tosca.xml.XTEntityTemplate) TRequirement(org.eclipse.winery.model.tosca.TRequirement) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) XOTStayMapping(org.eclipse.winery.model.tosca.xml.extensions.XOTStayMapping) XTPolicyType(org.eclipse.winery.model.tosca.xml.XTPolicyType) XOTTestRefinementModel(org.eclipse.winery.model.tosca.xml.extensions.XOTTestRefinementModel) XTArtifact(org.eclipse.winery.model.tosca.xml.XTArtifact) TDocumentation(org.eclipse.winery.model.tosca.TDocumentation) TCondition(org.eclipse.winery.model.tosca.TCondition) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) HasId(org.eclipse.winery.model.tosca.HasId) TInterface(org.eclipse.winery.model.tosca.TInterface) XOTPrmMapping(org.eclipse.winery.model.tosca.xml.extensions.XOTPrmMapping) Objects(java.util.Objects) XTCapability(org.eclipse.winery.model.tosca.xml.XTCapability) List(java.util.List) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) TPlan(org.eclipse.winery.model.tosca.TPlan) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) XTCapabilityRef(org.eclipse.winery.model.tosca.xml.XTCapabilityRef) XOTBehaviorPatternMapping(org.eclipse.winery.model.tosca.xml.extensions.XOTBehaviorPatternMapping) OTPropertyKV(org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV) XTArtifactType(org.eclipse.winery.model.tosca.xml.XTArtifactType) XTServiceTemplate(org.eclipse.winery.model.tosca.xml.XTServiceTemplate) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) XTImport(org.eclipse.winery.model.tosca.xml.XTImport) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) XRelationshipSourceOrTarget(org.eclipse.winery.model.tosca.xml.XRelationshipSourceOrTarget) Function(java.util.function.Function) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) XTBoundaryDefinitions(org.eclipse.winery.model.tosca.xml.XTBoundaryDefinitions) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) XOTRefinementModel(org.eclipse.winery.model.tosca.xml.extensions.XOTRefinementModel) TPropertyConstraint(org.eclipse.winery.model.tosca.TPropertyConstraint) TParameter(org.eclipse.winery.model.tosca.TParameter) TInstanceState(org.eclipse.winery.model.tosca.TInstanceState) XOTDeploymentArtifactMapping(org.eclipse.winery.model.tosca.xml.extensions.XOTDeploymentArtifactMapping) TConstraint(org.eclipse.winery.model.tosca.TConstraint) XTDefinitions(org.eclipse.winery.model.tosca.xml.XTDefinitions) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) TEntityTypeImplementation(org.eclipse.winery.model.tosca.TEntityTypeImplementation) XTRequirementRef(org.eclipse.winery.model.tosca.xml.XTRequirementRef) TImport(org.eclipse.winery.model.tosca.TImport) XTExportedOperation(org.eclipse.winery.model.tosca.xml.XTExportedOperation) XTExtensibleElements(org.eclipse.winery.model.tosca.xml.XTExtensibleElements) XTBoolean(org.eclipse.winery.model.tosca.xml.XTBoolean) TRequiredContainerFeature(org.eclipse.winery.model.tosca.TRequiredContainerFeature) Logger(org.slf4j.Logger) TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) XTCapabilityType(org.eclipse.winery.model.tosca.xml.XTCapabilityType) XTTopologyTemplate(org.eclipse.winery.model.tosca.xml.XTTopologyTemplate) TTag(org.eclipse.winery.model.tosca.TTag) XTPropertyMapping(org.eclipse.winery.model.tosca.xml.XTPropertyMapping) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) XTRelationshipTypeImplementation(org.eclipse.winery.model.tosca.xml.XTRelationshipTypeImplementation) Collections(java.util.Collections) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) TExportedOperation(org.eclipse.winery.model.tosca.TExportedOperation) XTEntityType(org.eclipse.winery.model.tosca.xml.XTEntityType) TEntityType(org.eclipse.winery.model.tosca.TEntityType) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition)

Example 22 with WinerysPropertiesDefinition

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
        }
    }
}
Also used : DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) TEntityType(org.eclipse.winery.model.tosca.TEntityType) QName(javax.xml.namespace.QName) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) TImport(org.eclipse.winery.model.tosca.TImport) Document(org.w3c.dom.Document)

Aggregations

WinerysPropertiesDefinition (org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition)22 PropertyDefinitionKV (org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV)15 TEntityType (org.eclipse.winery.model.tosca.TEntityType)13 QName (javax.xml.namespace.QName)8 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)8 ArrayList (java.util.ArrayList)7 TNodeType (org.eclipse.winery.model.tosca.TNodeType)7 LinkedHashMap (java.util.LinkedHashMap)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)6 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)5 IOException (java.io.IOException)4 Produces (javax.ws.rs.Produces)4 TInterface (org.eclipse.winery.model.tosca.TInterface)4 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)4 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)4 TRequirement (org.eclipse.winery.model.tosca.TRequirement)4 IRepository (org.eclipse.winery.repository.backend.IRepository)4 Consumes (javax.ws.rs.Consumes)3 GET (javax.ws.rs.GET)3 POST (javax.ws.rs.POST)3