Search in sources :

Example 6 with RequirementTypeId

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

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

the class VersionSupport method getDefinitionInTheGivenVersion.

public static DefinitionsChildId getDefinitionInTheGivenVersion(DefinitionsChildId childId, WineryVersion otherVersion) {
    if (childId.getVersion().compareTo(otherVersion) == 0) {
        return childId;
    }
    String localPart = childId.getNameWithoutVersion() + (otherVersion.toString().length() > 0 ? WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + otherVersion.toString() : "");
    QName qName = new QName(childId.getNamespace().getDecoded(), localPart);
    if (childId instanceof RelationshipTypeImplementationId) {
        return new RelationshipTypeImplementationId(qName);
    } else if (childId instanceof NodeTypeImplementationId) {
        return new NodeTypeImplementationId(qName);
    } else if (childId instanceof RequirementTypeId) {
        return new RequirementTypeId(qName);
    } else if (childId instanceof NodeTypeId) {
        return new NodeTypeId(qName);
    } else if (childId instanceof RelationshipTypeId) {
        return new RelationshipTypeId(qName);
    } else if (childId instanceof CapabilityTypeId) {
        return new CapabilityTypeId(qName);
    } else if (childId instanceof ArtifactTypeId) {
        return new ArtifactTypeId(qName);
    } else if (childId instanceof PolicyTypeId) {
        return new PolicyTypeId(qName);
    } else if (childId instanceof PolicyTemplateId) {
        return new PolicyTemplateId(qName);
    } else if (childId instanceof ServiceTemplateId) {
        return new ServiceTemplateId(qName);
    } else if (childId instanceof ArtifactTemplateId) {
        return new ArtifactTemplateId(qName);
    } else {
        throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
    }
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId)

Example 8 with RequirementTypeId

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

the class YamlRepository method getRequestedDefinition.

/**
 * Parses only requested Definition from converted yaml service template
 *
 * @param id          Definitions Child id
 * @param definitions converted definitions
 * @return requested definitions
 */
private TDefinitions getRequestedDefinition(DefinitionsChildId id, TDefinitions definitions) {
    if (id instanceof ArtifactTemplateId) {
        String artifactName = getNameOfArtifactFromArtifactName(id.getQName().getLocalPart());
        List<TArtifactTemplate> artifactTemplates = definitions.getArtifactTemplates();
        List<TArtifactTemplate> requestedArtifactTemplates = new ArrayList<>();
        for (TArtifactTemplate artifactTemplate : artifactTemplates) {
            if (artifactTemplate.getId().equalsIgnoreCase(artifactName)) {
                requestedArtifactTemplates.add(artifactTemplate);
                TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
                requestedDefinitions.addArtifactTemplates(requestedArtifactTemplates);
                return requestedDefinitions.build();
            }
        }
        // we did not find the artifact template id (this should not happen!)
        LOGGER.error("requested artifact template id (" + id.toReadableString() + ") cannot be extracted from definitions object!");
        return definitions;
    } else {
        TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
        if (id instanceof NodeTypeId) {
            requestedDefinitions.addNodeTypes(definitions.getNodeTypes());
        } else if (id instanceof RelationshipTypeId) {
            requestedDefinitions.addRelationshipTypes(definitions.getRelationshipTypes());
        } else if (id instanceof NodeTypeImplementationId) {
            requestedDefinitions.addNodeTypeImplementations(definitions.getNodeTypeImplementations());
        } else if (id instanceof RelationshipTypeImplementationId) {
            requestedDefinitions.addRelationshipTypeImplementations(definitions.getRelationshipTypeImplementations());
        } else if (id instanceof ArtifactTypeId) {
            requestedDefinitions.addArtifactTypes(definitions.getArtifactTypes());
        } else if (id instanceof CapabilityTypeId) {
            requestedDefinitions.addCapabilityTypes(definitions.getCapabilityTypes());
        } else if (id instanceof DataTypeId) {
            requestedDefinitions.addDataTypes(definitions.getDataTypes());
        } else if (id instanceof RequirementTypeId) {
            requestedDefinitions.addRequirementTypes(definitions.getRequirementTypes());
        } else if (id instanceof PolicyTypeId) {
            requestedDefinitions.addPolicyTypes(definitions.getPolicyTypes());
        } else if (id instanceof InterfaceTypeId) {
            requestedDefinitions.addInterfaceTypes(definitions.getInterfaceTypes());
        } else {
            // we do not need to filter anything
            return definitions;
        }
        return requestedDefinitions.build();
    }
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ArrayList(java.util.ArrayList) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions)

Example 9 with RequirementTypeId

use of org.eclipse.winery.model.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 separate 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 -> tf.getNodeTemplates().stream().filter(nt -> nt.getCapabilities() != null).anyMatch(nt -> nt.getCapabilities().stream().anyMatch(cap -> cap.getType().equals(requiredCapabilityType)))).collect(Collectors.toList());
}
Also used : Iterator(java.util.Iterator) TDocumentation(org.eclipse.winery.model.tosca.TDocumentation) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) Collection(java.util.Collection) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Set(java.util.Set) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) 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) QName(javax.xml.namespace.QName) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId)

Aggregations

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