Search in sources :

Example 26 with TEntityTemplate

use of org.eclipse.winery.model.tosca.TEntityTemplate in project winery by eclipse.

the class ModelUtilities method findNodeTemplateOrRequirementOfNodeTemplateOrCapabilityOfNodeTemplateOrRelationshipTemplate.

/**
 * locates targetObjectRef inside a topology template
 *
 * @param topologyTemplate the topology template to search in
 * @param targetObjectRef  the object ref as String
 * @return null if not found, otherwise the entity template in the topology
 */
public static TEntityTemplate findNodeTemplateOrRequirementOfNodeTemplateOrCapabilityOfNodeTemplateOrRelationshipTemplate(TTopologyTemplate topologyTemplate, String targetObjectRef) {
    // Other option: modify the stored XML directly. This is more error prune than walking through the whole topology
    for (TEntityTemplate t : topologyTemplate.getNodeTemplateOrRelationshipTemplate()) {
        if (t.getId().equals(targetObjectRef)) {
            return t;
        }
        if (t instanceof TNodeTemplate) {
            TNodeTemplate nt = (TNodeTemplate) t;
            TRequirement req = resolveRequirement(targetObjectRef, nt);
            if (req != null) {
                return req;
            }
            TCapability cap = resolveCapability(targetObjectRef, nt);
            if (cap != null) {
                return cap;
            }
        }
    }
    // no return hit inside the loop: nothing was found
    return null;
}
Also used : TRequirement(org.eclipse.winery.model.tosca.TRequirement) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TCapability(org.eclipse.winery.model.tosca.TCapability) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 27 with TEntityTemplate

use of org.eclipse.winery.model.tosca.TEntityTemplate in project winery by eclipse.

the class BackendUtils method clone.

/**
 * @param topologyTemplate which should be cloned
 * @return Copy od topologyTemplate
 */
public static TTopologyTemplate clone(TTopologyTemplate topologyTemplate) {
    @SuppressWarnings("deprecated") TTopologyTemplate topologyTemplateClone = new TTopologyTemplate();
    List<TEntityTemplate> entityTemplate = topologyTemplate.getNodeTemplateOrRelationshipTemplate();
    topologyTemplateClone.getNodeTemplateOrRelationshipTemplate().addAll(entityTemplate);
    return topologyTemplateClone;
}
Also used : TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate)

Example 28 with TEntityTemplate

use of org.eclipse.winery.model.tosca.TEntityTemplate in project winery by eclipse.

the class BackendUtils method initializeProperties.

/**
 * Properties need to be initialized in the case of K/V Properties
 *
 * @param repository     The repository to work on
 * @param entityTemplate the entity template to update
 */
public static void initializeProperties(IRepository repository, TEntityTemplate entityTemplate) {
    Objects.requireNonNull(repository);
    Objects.requireNonNull(entityTemplate);
    Objects.requireNonNull(entityTemplate.getType());
    final TEntityType entityType = repository.getTypeForTemplate(entityTemplate);
    final WinerysPropertiesDefinition winerysPropertiesDefinition = entityType.getWinerysPropertiesDefinition();
    if (winerysPropertiesDefinition == null) {
        return;
    }
    final LinkedHashMap<String, String> emptyKVProperties = new LinkedHashMap<>();
    for (PropertyDefinitionKV definitionKV : winerysPropertiesDefinition.getPropertyDefinitions()) {
        emptyKVProperties.put(definitionKV.getKey(), "");
    }
    TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
    properties.setNamespace(winerysPropertiesDefinition.getNamespace());
    properties.setElementName(winerysPropertiesDefinition.getElementName());
    properties.setKVProperties(emptyKVProperties);
    entityTemplate.setProperties(properties);
}
Also used : PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TEntityType(org.eclipse.winery.model.tosca.TEntityType) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) LinkedHashMap(java.util.LinkedHashMap)

Example 29 with TEntityTemplate

use of org.eclipse.winery.model.tosca.TEntityTemplate in project winery by eclipse.

the class BackendUtils method getAllNestedNodeTemplates.

/**
 * Returns a list of the topology template nested in the given service template
 */
public static List<TNodeTemplate> getAllNestedNodeTemplates(TServiceTemplate serviceTemplate) {
    List<TNodeTemplate> l = new ArrayList<>();
    TTopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate();
    if (topologyTemplate == null) {
        return Collections.emptyList();
    }
    for (TEntityTemplate t : topologyTemplate.getNodeTemplateOrRelationshipTemplate()) {
        if (t instanceof TNodeTemplate) {
            l.add((TNodeTemplate) t);
        }
    }
    return l;
}
Also used : TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 30 with TEntityTemplate

use of org.eclipse.winery.model.tosca.TEntityTemplate in project winery by eclipse.

the class IRepository method getReferenceCount.

default int getReferenceCount(ArtifactTemplateId id) {
    // We do not use a database, therefore, we have to go through all possibilities pointing to the artifact template
    // DAs and IAs point to an artifact template
    // DAs are contained in Node Type Implementations and Node Templates
    // IAs are contained in Node Type Implementations and Relationship Type Implementations
    int count = 0;
    Collection<TDeploymentArtifact> allDAs = new HashSet<>();
    Collection<TImplementationArtifact> allIAs = new HashSet<>();
    // handle Node Type Implementation, which contains DAs and IAs
    SortedSet<NodeTypeImplementationId> nodeTypeImplementations = this.getAllDefinitionsChildIds(NodeTypeImplementationId.class);
    for (NodeTypeImplementationId ntiId : nodeTypeImplementations) {
        final TNodeTypeImplementation nodeTypeImplementation = this.getElement(ntiId);
        List<TDeploymentArtifact> deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
        if (deploymentArtifacts != null) {
            allDAs.addAll(deploymentArtifacts);
        }
        List<TImplementationArtifact> implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts();
        if (implementationArtifacts != null) {
            allIAs.addAll(implementationArtifacts);
        }
    }
    // check all RelationshipTypeImplementations for IAs
    SortedSet<RelationshipTypeImplementationId> relationshipTypeImplementations = this.getAllDefinitionsChildIds(RelationshipTypeImplementationId.class);
    for (RelationshipTypeImplementationId rtiId : relationshipTypeImplementations) {
        List<TImplementationArtifact> implementationArtifacts = this.getElement(rtiId).getImplementationArtifacts();
        if (implementationArtifacts != null) {
            allIAs.addAll(implementationArtifacts);
        }
    }
    // check all node templates for DAs
    SortedSet<ServiceTemplateId> serviceTemplates = this.getAllDefinitionsChildIds(ServiceTemplateId.class);
    for (ServiceTemplateId sid : serviceTemplates) {
        TTopologyTemplate topologyTemplate = this.getElement(sid).getTopologyTemplate();
        if (topologyTemplate != null) {
            List<TEntityTemplate> nodeTemplateOrRelationshipTemplate = topologyTemplate.getNodeTemplateOrRelationshipTemplate();
            for (TEntityTemplate template : nodeTemplateOrRelationshipTemplate) {
                if (template instanceof TNodeTemplate) {
                    TNodeTemplate nodeTemplate = (TNodeTemplate) template;
                    List<TDeploymentArtifact> deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
                    if (deploymentArtifacts != null) {
                        allDAs.addAll(deploymentArtifacts);
                    }
                }
            }
        }
    }
    // now we have all DAs and IAs
    QName ourQName = id.getQName();
    // check DAs for artifact templates
    for (TDeploymentArtifact da : allDAs) {
        QName artifactRef = da.getArtifactRef();
        if (ourQName.equals(artifactRef)) {
            count++;
        }
    }
    // check IAs for artifact templates
    for (TImplementationArtifact ia : allIAs) {
        QName artifactRef = ia.getArtifactRef();
        if (ourQName.equals(artifactRef)) {
            count++;
        }
    }
    return count;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) QName(javax.xml.namespace.QName) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet)

Aggregations

TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)42 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)19 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)14 QName (javax.xml.namespace.QName)13 ArrayList (java.util.ArrayList)9 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)9 Map (java.util.Map)8 HashSet (java.util.HashSet)7 List (java.util.List)7 Consumes (javax.ws.rs.Consumes)7 Produces (javax.ws.rs.Produces)7 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)7 TPolicy (org.eclipse.winery.model.tosca.TPolicy)7 PUT (javax.ws.rs.PUT)6 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)6 TEntityType (org.eclipse.winery.model.tosca.TEntityType)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4