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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations