Search in sources :

Example 6 with RequirementTypeId

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

the class Splitting method getMatchingRelationshipType.

/**
 * @param requirement
 * @param capability
 * @return
 */
private TRelationshipType getMatchingRelationshipType(TRequirement requirement, TCapability capability) {
    TRelationshipType matchingRelationshipType = null;
    SortedSet<RelationshipTypeId> relTypeIds = RepositoryFactory.getRepository().getAllDefinitionsChildIds(RelationshipTypeId.class);
    List<TRelationshipType> relationshipTypes = new ArrayList<>();
    for (RelationshipTypeId id : relTypeIds) {
        relationshipTypes.add(RepositoryFactory.getRepository().getElement(id));
    }
    Map<String, String> requirementProperties = ModelUtilities.getPropertiesKV(requirement);
    Map<String, String> capabilityProperties = ModelUtilities.getPropertiesKV(capability);
    /* If the property "requiredRelationshipType" is defined for the requirement and the capability this relationship type
           has to be taken - if the specified relationship type is not available, no relationship type is chosen */
    if (requirementProperties != null && capabilityProperties != null && requirementProperties.containsKey("requiredRelationshipType") && capabilityProperties.containsKey("requiredRelationshipType") && requirementProperties.get("requiredRelationshipType").equals(capabilityProperties.get("requiredRelationshipType")) && requirementProperties.get("requiredRelationshipType") != null) {
        QName referencedRelationshipType = QName.valueOf(requirementProperties.get("requiredRelationshipType"));
        RelationshipTypeId relTypeId = new RelationshipTypeId(referencedRelationshipType);
        if (relTypeIds.stream().anyMatch(rti -> rti.equals(relTypeId))) {
            return RepositoryFactory.getRepository().getElement(relTypeId);
        }
    } else {
        QName requirementTypeQName = requirement.getType();
        RequirementTypeId reqTypeId = new RequirementTypeId(requirement.getType());
        TRequirementType requirementType = RepositoryFactory.getRepository().getElement(reqTypeId);
        QName capabilityTypeQName = capability.getType();
        CapabilityTypeId capTypeId = new CapabilityTypeId(capability.getType());
        TCapabilityType capabilityType = RepositoryFactory.getRepository().getElement(capTypeId);
        List<TRelationshipType> availableMatchingRelationshipTypes = new ArrayList<>();
        availableMatchingRelationshipTypes.clear();
        while (requirementType != null && capabilityType != null) {
            // relationship type with valid source origin requirement type or empty and valid target origin capability type
            for (TRelationshipType rt : relationshipTypes) {
                if ((rt.getValidSource() == null || rt.getValidSource().getTypeRef().equals(requirementTypeQName)) && (rt.getValidTarget() != null && rt.getValidTarget().getTypeRef().equals(capabilityTypeQName))) {
                    availableMatchingRelationshipTypes.add(rt);
                }
            }
            if (!availableMatchingRelationshipTypes.isEmpty() && availableMatchingRelationshipTypes.size() == 1) {
                return availableMatchingRelationshipTypes.get(0);
            } else if (!availableMatchingRelationshipTypes.isEmpty() && availableMatchingRelationshipTypes.size() > 1) {
                return null;
            } else if (requirementType.getDerivedFrom() != null || capabilityType.getDerivedFrom() != null) {
                TCapabilityType derivedFromCapabilityType = null;
                TRequirementType derivedFromRequirementType = null;
                availableMatchingRelationshipTypes.clear();
                List<TRelationshipType> additionalMatchingRelationshipTypes = new ArrayList<>();
                if (capabilityType.getDerivedFrom() != null) {
                    QName derivedFromCapabilityTypeRef = capabilityType.getDerivedFrom().getTypeRef();
                    CapabilityTypeId derivedFromCapTypeId = new CapabilityTypeId(derivedFromCapabilityTypeRef);
                    derivedFromCapabilityType = RepositoryFactory.getRepository().getElement(derivedFromCapTypeId);
                    for (TRelationshipType rt : relationshipTypes) {
                        if ((rt.getValidSource() == null || rt.getValidSource().getTypeRef().equals(requirementTypeQName)) && (rt.getValidTarget() != null && rt.getValidTarget().getTypeRef().equals(derivedFromCapabilityTypeRef))) {
                            availableMatchingRelationshipTypes.add(rt);
                        }
                    }
                }
                if (requirementType.getDerivedFrom() != null) {
                    QName derivedFromRequirementTypeRef = requirementType.getDerivedFrom().getTypeRef();
                    RequirementTypeId derivedFromReqTypeId = new RequirementTypeId(derivedFromRequirementTypeRef);
                    derivedFromRequirementType = RepositoryFactory.getRepository().getElement(derivedFromReqTypeId);
                    for (TRelationshipType rt : relationshipTypes) {
                        if ((rt.getValidSource() != null && rt.getValidSource().getTypeRef().equals(derivedFromRequirementTypeRef)) && (rt.getValidTarget() != null && rt.getValidTarget().getTypeRef().equals(capabilityTypeQName))) {
                            additionalMatchingRelationshipTypes.add(rt);
                        }
                    }
                }
                availableMatchingRelationshipTypes.addAll(additionalMatchingRelationshipTypes);
                if (!availableMatchingRelationshipTypes.isEmpty() && availableMatchingRelationshipTypes.size() == 1) {
                    return availableMatchingRelationshipTypes.get(0);
                } else if (!availableMatchingRelationshipTypes.isEmpty() && availableMatchingRelationshipTypes.size() > 1) {
                    return null;
                }
                requirementType = derivedFromRequirementType;
                capabilityType = derivedFromCapabilityType;
            }
        }
        TCapabilityType basisCapabilityType = getBasisCapabilityType(capability.getType());
        for (TRelationshipType relationshipType : relationshipTypes) {
            if (basisCapabilityType != null && basisCapabilityType.getName().equalsIgnoreCase("container") && relationshipType.getName().equalsIgnoreCase("hostedon") && relationshipType.getValidSource() == null && (relationshipType.getValidTarget() == null || relationshipType.getValidTarget().getTypeRef().getLocalPart().equalsIgnoreCase("container"))) {
                return relationshipType;
            }
            if (basisCapabilityType != null && basisCapabilityType.getName().equalsIgnoreCase("endpoint") && relationshipType.getName().equalsIgnoreCase("connectsto") && relationshipType.getValidSource() == null && (relationshipType.getValidTarget() == null || relationshipType.getValidTarget().getTypeRef().getLocalPart().equalsIgnoreCase("endpoint"))) {
                return relationshipType;
            }
        }
    }
    return matchingRelationshipType;
}
Also used : RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId)

Example 7 with RequirementTypeId

use of org.eclipse.winery.common.ids.definitions.RequirementTypeId 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 8 with RequirementTypeId

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

the class ProviderRepository method getAllTopologyFragmentsForLocationAndOfferingCapability.

/**
 * Pointing to a concrete node template has to be done by putting this node template into a separeate namespace <p>
 * The given targetLocation is appended to {@see NS_NAME_START} to gain the namespace. All NodeTemplates in this
 * namespace and all "lower" namespaces (e.g., starting with that string) are returned.
 *
 * @return All node templates available for the given targetLocation.
 */
public List<TTopologyTemplate> getAllTopologyFragmentsForLocationAndOfferingCapability(String targetLocation, TRequirement requirement) {
    QName reqTypeQName = requirement.getType();
    RequirementTypeId reqTypeId = new RequirementTypeId(reqTypeQName);
    QName requiredCapabilityType = RepositoryFactory.getRepository().getElement(reqTypeId).getRequiredCapabilityType();
    return getAllTopologyFragmentsForLocation(targetLocation).stream().filter(tf -> {
        Optional<TNodeTemplate> nodeTemplate = ModelUtilities.getAllNodeTemplates(tf).stream().filter(nt -> nt.getCapabilities() != null).filter(nt -> nt.getCapabilities().getCapability().stream().anyMatch(cap -> cap.getType().equals(requiredCapabilityType))).findAny();
        if (nodeTemplate.isPresent()) {
            return true;
        } else {
            return false;
        }
    }).collect(Collectors.toList());
}
Also used : RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) TDocumentation(org.eclipse.winery.model.tosca.TDocumentation) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) Collectors(java.util.stream.Collectors) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) ArrayList(java.util.ArrayList) List(java.util.List) Optional(java.util.Optional) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TRequirement(org.eclipse.winery.model.tosca.TRequirement) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Optional(java.util.Optional) QName(javax.xml.namespace.QName) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId)

Aggregations

RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)8 QName (javax.xml.namespace.QName)6 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)6 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)4 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)4 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)4 ArrayList (java.util.ArrayList)3 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)3 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)3 PolicyTypeId (org.eclipse.winery.common.ids.definitions.PolicyTypeId)3 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)3 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)3 TRequirement (org.eclipse.winery.model.tosca.TRequirement)3 HashSet (java.util.HashSet)2 NodeTypeImplementationId (org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId)2 PolicyTemplateId (org.eclipse.winery.common.ids.definitions.PolicyTemplateId)2 RelationshipTypeImplementationId (org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId)2 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)2 TCapability (org.eclipse.winery.model.tosca.TCapability)2