Search in sources :

Example 1 with ArtifactTypeId

use of org.eclipse.winery.model.ids.definitions.ArtifactTypeId in project winery by eclipse.

the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.

public static TDefinitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
    final TDefinitions definitions = createWrapperDefinitions(id, repository);
    HasIdInIdOrNameField element;
    if (id instanceof RelationshipTypeImplementationId) {
        element = new TRelationshipTypeImplementation();
    } else if (id instanceof NodeTypeImplementationId) {
        element = new TNodeTypeImplementation();
    } else if (id instanceof RequirementTypeId) {
        element = new TRequirementType();
    } else if (id instanceof NodeTypeId) {
        element = new TNodeType();
    } else if (id instanceof RelationshipTypeId) {
        element = new TRelationshipType();
    } else if (id instanceof CapabilityTypeId) {
        element = new TCapabilityType();
    } else if (id instanceof DataTypeId) {
        element = new TDataType();
    } else if (id instanceof ArtifactTypeId) {
        element = new TArtifactType();
    } else if (id instanceof PolicyTypeId) {
        element = new TPolicyType();
    } else if (id instanceof PolicyTemplateId) {
        element = new TPolicyTemplate();
    } else if (id instanceof ServiceTemplateId) {
        element = new TServiceTemplate();
    } else if (id instanceof ArtifactTemplateId) {
        element = new TArtifactTemplate();
    } else if (id instanceof ComplianceRuleId) {
        element = new OTComplianceRule(new OTComplianceRule.Builder(id.getXmlId().getDecoded()));
    } else if (id instanceof PatternRefinementModelId) {
        element = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder());
    } else if (id instanceof TopologyFragmentRefinementModelId) {
        element = new OTTopologyFragmentRefinementModel(new OTPatternRefinementModel.Builder());
    } else if (id instanceof TestRefinementModelId) {
        element = new OTTestRefinementModel(new OTTestRefinementModel.Builder());
    } else if (id instanceof InterfaceTypeId) {
        element = new TInterfaceType();
    } else if (id instanceof XSDImportId) {
        // TImport has no id; thus directly generating it without setting an id
        TImport tImport = new TImport();
        definitions.setElement(tImport);
        return definitions;
    } else {
        throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
    }
    copyIdToFields(element, id);
    definitions.setElement((TExtensibleElements) element);
    return definitions;
}
Also used : OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TestRefinementModelId(org.eclipse.winery.model.ids.extensions.TestRefinementModelId) TImport(org.eclipse.winery.model.tosca.TImport) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TDataType(org.eclipse.winery.model.tosca.TDataType) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) XSDImportId(org.eclipse.winery.model.ids.definitions.imports.XSDImportId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) TInterfaceType(org.eclipse.winery.model.tosca.TInterfaceType) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 2 with ArtifactTypeId

use of org.eclipse.winery.model.ids.definitions.ArtifactTypeId in project winery by eclipse.

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeId id) {
    Collection<NodeTypeImplementationId> allNodeTypeImplementations = this.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, id.getQName());
    Collection<DefinitionsChildId> ids = new HashSet<>(allNodeTypeImplementations);
    final TNodeType nodeType = this.getElement(id);
    // Add all referenced requirement types, but only in XML mode.
    // For YAML mode add referenced RelationshipType and CapabilityType, if present
    List<TRequirementDefinition> reqDefs = nodeType.getRequirementDefinitions();
    if (reqDefs != null) {
        for (TRequirementDefinition reqDef : reqDefs) {
            // if either of these is set, we're dealing with a type defined in YAML
            if (Objects.nonNull(reqDef.getRelationship()) || Objects.nonNull(reqDef.getCapability()) || Objects.nonNull(reqDef.getNode())) {
                if (Objects.nonNull(reqDef.getRelationship())) {
                    ids.add(new RelationshipTypeId(reqDef.getRelationship()));
                }
                if (Objects.nonNull(reqDef.getCapability())) {
                    ids.add(new CapabilityTypeId(reqDef.getCapability()));
                }
                if (Objects.nonNull(reqDef.getNode())) {
                    ids.add(new NodeTypeId(reqDef.getNode()));
                }
            } else {
                RequirementTypeId reqTypeId = new RequirementTypeId(reqDef.getRequirementType());
                ids.add(reqTypeId);
            }
        }
    }
    // add all referenced capability types
    List<TCapabilityDefinition> capabilityDefinitions = nodeType.getCapabilityDefinitions();
    if (capabilityDefinitions != null) {
        for (TCapabilityDefinition capDef : capabilityDefinitions) {
            CapabilityTypeId capTypeId = new CapabilityTypeId(capDef.getCapabilityType());
            ids.add(capTypeId);
            // Add all types referenced in valid source types
            if (Objects.nonNull(capDef.getValidSourceTypes())) {
                capDef.getValidSourceTypes().forEach(sourceType -> ids.add(new NodeTypeId(sourceType)));
            }
        }
    }
    List<TInterfaceDefinition> interfaceDefinitions = nodeType.getInterfaceDefinitions();
    if (Objects.nonNull(interfaceDefinitions) && !interfaceDefinitions.isEmpty()) {
        for (TInterfaceDefinition intDef : interfaceDefinitions) {
            InterfaceTypeId interfaceTypeId = new InterfaceTypeId(intDef.getType());
            ids.add(interfaceTypeId);
        }
    }
    // Store all referenced artifact types
    List<TArtifact> artifacts = nodeType.getArtifacts();
    if (Objects.nonNull(artifacts)) {
        artifacts.forEach(a -> ids.add(new ArtifactTypeId(a.getType())));
    }
    getReferencedDefinitionsOfProperties(ids, nodeType.getProperties());
    return ids;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) TArtifact(org.eclipse.winery.model.tosca.TArtifact) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) TCapabilityDefinition(org.eclipse.winery.model.tosca.TCapabilityDefinition) TInterfaceDefinition(org.eclipse.winery.model.tosca.TInterfaceDefinition) HashSet(java.util.HashSet)

Example 3 with ArtifactTypeId

use of org.eclipse.winery.model.ids.definitions.ArtifactTypeId in project winery by eclipse.

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ComplianceRuleId id) {
    // We have to use a HashSet to ensure that no duplicate ids are added
    // E.g., there may be multiple relationship templates having the same type
    Collection<DefinitionsChildId> ids = new HashSet<>();
    OTComplianceRule complianceRule = this.getElement(id);
    // TODO extend to required Structure
    if (complianceRule.getIdentifier() != null) {
        for (TEntityTemplate entityTemplate : complianceRule.getIdentifier().getNodeTemplateOrRelationshipTemplate()) {
            QName qname = entityTemplate.getType();
            if (entityTemplate instanceof TNodeTemplate) {
                ids.add(new NodeTypeId(qname));
                TNodeTemplate n = (TNodeTemplate) entityTemplate;
                // crawl through deployment artifacts
                List<TDeploymentArtifact> deploymentArtifacts = n.getDeploymentArtifacts();
                if (deploymentArtifacts != null) {
                    for (TDeploymentArtifact da : deploymentArtifacts) {
                        ids.add(new ArtifactTypeId(da.getArtifactType()));
                        if ((qname = da.getArtifactRef()) != null) {
                            ids.add(new ArtifactTemplateId(qname));
                        }
                    }
                }
                getReferencedRequirementTypeIds(ids, n);
                getCapabilitiesReferences(ids, n);
                // crawl through policies
                List<TPolicy> policies = n.getPolicies();
                if (policies != null) {
                    for (TPolicy pol : policies) {
                        QName type = pol.getPolicyType();
                        PolicyTypeId ctId = new PolicyTypeId(type);
                        ids.add(ctId);
                    }
                }
            } else {
                assert (entityTemplate instanceof TRelationshipTemplate);
                ids.add(new RelationshipTypeId(qname));
            }
        }
    }
    return ids;
}
Also used : RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) HashSet(java.util.HashSet)

Example 4 with ArtifactTypeId

use of org.eclipse.winery.model.ids.definitions.ArtifactTypeId in project winery by eclipse.

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeImplementationId id) {
    // We have to use a HashSet to ensure that no duplicate ids are added
    // There may be multiple DAs/IAs referencing the same type
    Collection<DefinitionsChildId> ids = new HashSet<>();
    final TNodeTypeImplementation element = this.getElement(id);
    // DAs
    List<TDeploymentArtifact> deploymentArtifacts = element.getDeploymentArtifacts();
    if (deploymentArtifacts != null) {
        for (TDeploymentArtifact da : deploymentArtifacts) {
            QName qname;
            if ((qname = da.getArtifactRef()) != null) {
                ids.add(new ArtifactTemplateId(qname));
            }
            ids.add(new ArtifactTypeId(da.getArtifactType()));
        }
    }
    // IAs
    return this.getReferencedTOSCAComponentImplementationArtifactIds(ids, element.getImplementationArtifacts(), id);
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) HashSet(java.util.HashSet)

Example 5 with ArtifactTypeId

use of org.eclipse.winery.model.ids.definitions.ArtifactTypeId in project winery by eclipse.

the class VersionSupportTest method getNewIdIfComponentVersionIsAvailable.

@Test
public void getNewIdIfComponentVersionIsAvailable() {
    String id = "myId_component-version-w1";
    String appendix = "test";
    String expectedId = "myId_component-version-w1-" + appendix + "-w1-wip1";
    ArtifactTypeId serviceTemplateId = new ArtifactTypeId("https://ex.org/tosca/sts", id, false);
    assertEquals(expectedId, VersionSupport.getNewComponentVersionId(serviceTemplateId, appendix));
}
Also used : ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) Test(org.junit.jupiter.api.Test)

Aggregations

ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)17 QName (javax.xml.namespace.QName)11 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)9 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)6 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)6 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)6 ArrayList (java.util.ArrayList)5 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)5 PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)5 HashSet (java.util.HashSet)4 CapabilityTypeId (org.eclipse.winery.model.ids.definitions.CapabilityTypeId)4 InterfaceTypeId (org.eclipse.winery.model.ids.definitions.InterfaceTypeId)4 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)4 RequirementTypeId (org.eclipse.winery.model.ids.definitions.RequirementTypeId)4 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)4 TArtifactType (org.eclipse.winery.model.tosca.TArtifactType)4 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)4 PolicyTemplateId (org.eclipse.winery.model.ids.definitions.PolicyTemplateId)3 RelationshipTypeImplementationId (org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)3 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)3