Search in sources :

Example 1 with CapabilityTypeId

use of org.eclipse.winery.common.ids.definitions.CapabilityTypeId in project winery by eclipse.

the class IGenericRepository 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<>();
    TComplianceRule 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
                TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
                if (deploymentArtifacts != null) {
                    List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
                    for (TDeploymentArtifact da : das) {
                        ids.add(new ArtifactTypeId(da.getArtifactType()));
                        if ((qname = da.getArtifactRef()) != null) {
                            ids.add(new ArtifactTemplateId(qname));
                        }
                    }
                }
                // crawl through reqs/caps
                TNodeTemplate.Requirements requirements = n.getRequirements();
                if (requirements != null) {
                    for (TRequirement req : requirements.getRequirement()) {
                        QName type = req.getType();
                        RequirementTypeId rtId = new RequirementTypeId(type);
                        ids.add(rtId);
                    }
                }
                TNodeTemplate.Capabilities capabilities = n.getCapabilities();
                if (capabilities != null) {
                    for (TCapability cap : capabilities.getCapability()) {
                        QName type = cap.getType();
                        CapabilityTypeId ctId = new CapabilityTypeId(type);
                        ids.add(ctId);
                    }
                }
                // crawl through policies
                org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
                if (policies != null) {
                    for (TPolicy pol : policies.getPolicy()) {
                        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 : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TComplianceRule(org.eclipse.winery.model.tosca.TComplianceRule) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) TCapability(org.eclipse.winery.model.tosca.TCapability) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) TPolicy(org.eclipse.winery.model.tosca.TPolicy) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Example 2 with CapabilityTypeId

use of org.eclipse.winery.common.ids.definitions.CapabilityTypeId in project winery by eclipse.

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeId id) {
    Collection<DefinitionsChildId> ids = new ArrayList<>();
    Collection<NodeTypeImplementationId> allNodeTypeImplementations = this.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, id.getQName());
    for (NodeTypeImplementationId ntiId : allNodeTypeImplementations) {
        ids.add(ntiId);
    }
    final TNodeType nodeType = this.getElement(id);
    // add all referenced requirement types
    TNodeType.RequirementDefinitions reqDefsContainer = nodeType.getRequirementDefinitions();
    if (reqDefsContainer != null) {
        List<TRequirementDefinition> reqDefs = reqDefsContainer.getRequirementDefinition();
        for (TRequirementDefinition reqDef : reqDefs) {
            RequirementTypeId reqTypeId = new RequirementTypeId(reqDef.getRequirementType());
            ids.add(reqTypeId);
        }
    }
    // add all referenced capability types
    TNodeType.CapabilityDefinitions capDefsContainer = nodeType.getCapabilityDefinitions();
    if (capDefsContainer != null) {
        List<TCapabilityDefinition> capDefs = capDefsContainer.getCapabilityDefinition();
        for (TCapabilityDefinition capDef : capDefs) {
            CapabilityTypeId capTypeId = new CapabilityTypeId(capDef.getCapabilityType());
            ids.add(capTypeId);
        }
    }
    return ids;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) ArrayList(java.util.ArrayList) TNodeType(org.eclipse.winery.model.tosca.TNodeType) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) TCapabilityDefinition(org.eclipse.winery.model.tosca.TCapabilityDefinition)

Example 3 with CapabilityTypeId

use of org.eclipse.winery.common.ids.definitions.CapabilityTypeId in project winery by eclipse.

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RelationshipTypeId id) {
    Collection<DefinitionsChildId> ids = new ArrayList<>();
    // add all implementations
    Collection<RelationshipTypeImplementationId> allTypeImplementations = this.getAllElementsReferencingGivenType(RelationshipTypeImplementationId.class, id.getQName());
    for (RelationshipTypeImplementationId ntiId : allTypeImplementations) {
        ids.add(ntiId);
    }
    final TRelationshipType relationshipType = this.getElement(id);
    TRelationshipType.ValidSource validSource = relationshipType.getValidSource();
    if (validSource != null) {
        QName typeRef = validSource.getTypeRef();
        // can be a node type or a requirement type
        // similar code as for valid target (difference: req/cap)
        NodeTypeId ntId = new NodeTypeId(typeRef);
        if (this.exists(ntId)) {
            ids.add(ntId);
        } else {
            RequirementTypeId rtId = new RequirementTypeId(typeRef);
            ids.add(rtId);
        }
    }
    TRelationshipType.ValidTarget validTarget = relationshipType.getValidTarget();
    if (validTarget != null) {
        QName typeRef = validTarget.getTypeRef();
        // can be a node type or a capability type
        // similar code as for valid target (difference: req/cap)
        NodeTypeId ntId = new NodeTypeId(typeRef);
        if (this.exists(ntId)) {
            ids.add(ntId);
        } else {
            CapabilityTypeId capId = new CapabilityTypeId(typeRef);
            ids.add(capId);
        }
    }
    return ids;
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) ArrayList(java.util.ArrayList) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId) RelationshipTypeImplementationId(org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId)

Example 4 with CapabilityTypeId

use of org.eclipse.winery.common.ids.definitions.CapabilityTypeId in project winery by eclipse.

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ServiceTemplateId 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<>();
    TServiceTemplate serviceTemplate = this.getElement(id);
    // add included things to export queue
    TBoundaryDefinitions boundaryDefs;
    if ((boundaryDefs = serviceTemplate.getBoundaryDefinitions()) != null) {
        TBoundaryDefinitions.Policies policies = boundaryDefs.getPolicies();
        if (policies != null) {
            for (TPolicy policy : policies.getPolicy()) {
                PolicyTypeId policyTypeId = new PolicyTypeId(policy.getPolicyType());
                ids.add(policyTypeId);
                PolicyTemplateId policyTemplateId = new PolicyTemplateId(policy.getPolicyRef());
                ids.add(policyTemplateId);
            }
        }
    // reqs and caps don't have to be exported here as they are references to existing reqs/caps (of nested node templates)
    }
    if (serviceTemplate.getTopologyTemplate() != null) {
        for (TEntityTemplate entityTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
            QName qname = entityTemplate.getType();
            if (entityTemplate instanceof TNodeTemplate) {
                ids.add(new NodeTypeId(qname));
                TNodeTemplate n = (TNodeTemplate) entityTemplate;
                // crawl through deployment artifacts
                TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
                if (deploymentArtifacts != null) {
                    List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
                    for (TDeploymentArtifact da : das) {
                        ids.add(new ArtifactTypeId(da.getArtifactType()));
                        if ((qname = da.getArtifactRef()) != null) {
                            ids.add(new ArtifactTemplateId(qname));
                        }
                    }
                }
                // crawl through reqs/caps
                TNodeTemplate.Requirements requirements = n.getRequirements();
                if (requirements != null) {
                    for (TRequirement req : requirements.getRequirement()) {
                        QName type = req.getType();
                        RequirementTypeId rtId = new RequirementTypeId(type);
                        ids.add(rtId);
                    }
                }
                TNodeTemplate.Capabilities capabilities = n.getCapabilities();
                if (capabilities != null) {
                    for (TCapability cap : capabilities.getCapability()) {
                        QName type = cap.getType();
                        CapabilityTypeId ctId = new CapabilityTypeId(type);
                        ids.add(ctId);
                    }
                }
                // crawl through policies
                org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
                if (policies != null) {
                    for (TPolicy pol : policies.getPolicy()) {
                        QName type = pol.getPolicyType();
                        PolicyTypeId ctId = new PolicyTypeId(type);
                        ids.add(ctId);
                        QName template = pol.getPolicyRef();
                        if (template != null) {
                            PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
                            ids.add(policyTemplateId);
                        }
                    }
                }
            } else {
                assert (entityTemplate instanceof TRelationshipTemplate);
                ids.add(new RelationshipTypeId(qname));
            }
        }
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) TCapability(org.eclipse.winery.model.tosca.TCapability) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) TPolicy(org.eclipse.winery.model.tosca.TPolicy) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Example 5 with CapabilityTypeId

use of org.eclipse.winery.common.ids.definitions.CapabilityTypeId in project winery by eclipse.

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RequirementTypeId id) {
    Collection<DefinitionsChildId> ids = new ArrayList<>(1);
    final TRequirementType element = this.getElement(id);
    QName requiredCapabilityType = element.getRequiredCapabilityType();
    if (requiredCapabilityType != null) {
        CapabilityTypeId capId = new CapabilityTypeId(requiredCapabilityType);
        ids.add(capId);
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType)

Aggregations

CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)5 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)5 QName (javax.xml.namespace.QName)4 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)4 ArrayList (java.util.ArrayList)3 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)3 HashSet (java.util.HashSet)2 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)2 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)2 PolicyTypeId (org.eclipse.winery.common.ids.definitions.PolicyTypeId)2 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)2 TCapability (org.eclipse.winery.model.tosca.TCapability)2 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)2 TDeploymentArtifacts (org.eclipse.winery.model.tosca.TDeploymentArtifacts)2 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)2 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)2 TPolicy (org.eclipse.winery.model.tosca.TPolicy)2 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)2 TRequirement (org.eclipse.winery.model.tosca.TRequirement)2 NodeTypeImplementationId (org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId)1