Search in sources :

Example 46 with DefinitionsChildId

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

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RelationshipTypeId id) {
    // add all implementations
    Collection<DefinitionsChildId> ids = new ArrayList<>(this.getAllElementsReferencingGivenType(RelationshipTypeImplementationId.class, id.getQName()));
    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);
        }
    }
    List<QName> validTargetList = relationshipType.getValidTargetList();
    if (validTargetList != null) {
        for (QName typeRef : validTargetList) {
            CapabilityTypeId capId = new CapabilityTypeId(typeRef);
            if (this.exists(capId)) {
                ids.add(capId);
            }
        }
    }
    getReferencedDefinitionsOfProperties(ids, relationshipType.getProperties());
    return ids;
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) ArrayList(java.util.ArrayList) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)

Example 47 with DefinitionsChildId

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

the class IRepository method getReferencedDefinitionsChildIds.

/**
 * Determines the referenced definition children Ids. Does NOT return the included files.
 *
 * @return a collection of referenced definition child Ids
 */
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ArtifactTemplateId id) throws RepositoryCorruptException {
    Collection<DefinitionsChildId> ids = new ArrayList<>();
    final TArtifactTemplate artifactTemplate = this.getElement(id);
    // "Export" type
    QName type = artifactTemplate.getType();
    if (type == null) {
        throw new RepositoryCorruptException("Type is null for " + id.toReadableString());
    } else {
        ids.add(new ArtifactTypeId(type));
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException)

Example 48 with DefinitionsChildId

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

the class IRepository method getDefinitionsChildIdOfParent.

/**
 * Determines the id of the parent in the inheritance hierarchy (if exists).
 *
 * @return the id of the parent class
 */
default Optional<DefinitionsChildId> getDefinitionsChildIdOfParent(HasInheritanceId id) {
    final HasInheritance element = (HasInheritance) this.getDefinitions(id).getElement();
    final HasType derivedFrom = element.getDerivedFrom();
    QName derivedFromType = null;
    if (derivedFrom != null) {
        derivedFromType = derivedFrom.getTypeAsQName();
    }
    if (derivedFromType == null) {
        return Optional.empty();
    } else {
        // Instantiate an id with the same class as the current id
        DefinitionsChildId parentId;
        Constructor<? extends DefinitionsChildId> constructor;
        try {
            constructor = id.getClass().getConstructor(QName.class);
        } catch (NoSuchMethodException | SecurityException e1) {
            throw new IllegalStateException("Could get constructor to instantiate parent id", e1);
        }
        try {
            parentId = constructor.newInstance(derivedFromType);
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            throw new IllegalStateException("Could not instantiate id for parent", e);
        }
        return Optional.of(parentId);
    }
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) InvocationTargetException(java.lang.reflect.InvocationTargetException) HasInheritance(org.eclipse.winery.model.tosca.HasInheritance) HasType(org.eclipse.winery.model.tosca.HasType)

Example 49 with DefinitionsChildId

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

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(DataTypeId id) {
    Set<DefinitionsChildId> ids = new HashSet<>();
    TDataType definition = this.getElement(id);
    // cast is safe because TDataType can only use YamlPropertiesDefinitions
    getReferencedDefinitionsOfProperties(ids, definition.getProperties());
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TDataType(org.eclipse.winery.model.tosca.TDataType) HashSet(java.util.HashSet)

Example 50 with DefinitionsChildId

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

the class IRepository 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) {
        List<TPolicy> policies = boundaryDefs.getPolicies();
        if (policies != null) {
            for (TPolicy policy : policies) {
                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)
    }
    final TTopologyTemplate topology = serviceTemplate.getTopologyTemplate();
    if (topology != null) {
        if (Objects.nonNull(topology.getPolicies())) {
            topology.getPolicies().stream().filter(Objects::nonNull).forEach(p -> {
                QName type = p.getPolicyType();
                PolicyTypeId policyTypeIdId = new PolicyTypeId(type);
                ids.add(policyTypeIdId);
            });
        }
        for (TEntityTemplate entityTemplate : topology.getNodeTemplateOrRelationshipTemplate()) {
            QName qname = entityTemplate.getType();
            if (entityTemplate instanceof TNodeTemplate) {
                ids.add(new NodeTypeId(qname));
                TNodeTemplate n = (TNodeTemplate) entityTemplate;
                // 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);
                        QName template = pol.getPolicyRef();
                        if (template != null) {
                            PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
                            ids.add(policyTemplateId);
                        }
                    }
                }
                // Crawl RequirementTypes and Capabilities for their references
                getReferencedRequirementTypeIds(ids, n);
                getCapabilitiesReferences(ids, n);
                // TODO: this information is collected differently for YAML and XML modes
                // crawl through deployment artifacts
                List<TDeploymentArtifact> deploymentArtifacts = n.getDeploymentArtifacts();
                if (deploymentArtifacts != null) {
                    for (TDeploymentArtifact da : deploymentArtifacts) {
                        if (da.getArtifactType() != null) {
                            // This is considered Nullable, because the test case ConsistencyCheckerTest#hasError
                            // expects an empty artifactType and thus it may be null.
                            ids.add(new ArtifactTypeId(da.getArtifactType()));
                        }
                        if (da.getArtifactRef() != null) {
                            ids.add(new ArtifactTemplateId(da.getArtifactRef()));
                        }
                    }
                }
                // Store all referenced artifact types
                List<TArtifact> artifacts = n.getArtifacts();
                if (Objects.nonNull(artifacts)) {
                    artifacts.forEach(a -> ids.add(new ArtifactTypeId(a.getType())));
                }
                TNodeType nodeType = this.getElement(new NodeTypeId(qname));
                if (Objects.nonNull(nodeType.getInterfaceDefinitions())) {
                    nodeType.getInterfaceDefinitions().stream().filter(Objects::nonNull).forEach(iDef -> {
                        if (Objects.nonNull(iDef.getType())) {
                            ids.add(new InterfaceTypeId(iDef.getType()));
                        }
                    });
                }
            } 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) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) TArtifact(org.eclipse.winery.model.tosca.TArtifact) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Aggregations

DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)77 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)29 Test (org.junit.jupiter.api.Test)21 QName (javax.xml.namespace.QName)19 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)16 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)16 HashMap (java.util.HashMap)15 IRepository (org.eclipse.winery.repository.backend.IRepository)14 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13 Path (java.nio.file.Path)12 Map (java.util.Map)12 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)12 TExtensibleElements (org.eclipse.winery.model.tosca.TExtensibleElements)12 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 InputStream (java.io.InputStream)10 HashSet (java.util.HashSet)10 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)10