/** * Get the first capability that match the given type. * * @param nodeTemplate The node template in witch to lookup for the capability. * @param capabilityTypeName The capability type to look for. * @return The capability matching the type or null if no capability of the requested type is defined. */ public static Capability getCapabilityByType(NodeTemplate nodeTemplate, String capabilityTypeName) { Entry<String, Capability> capabilityEntry = getCapabilitEntryyByType(nodeTemplate, capabilityTypeName); return capabilityEntry == null ? null : capabilityEntry.getValue(); }
private void updateRelationshipsCapabilitiesRelationships(Topology topology, NodeTemplate nodeTemplate) { List<RelationshipEntry> targetRelationships = TopologyUtils.getTargetRelationships(nodeTemplate.getName(), topology.getNodeTemplates()); for (RelationshipEntry targetRelationshipEntry : targetRelationships) { RelationshipTemplate targetRelationship = targetRelationshipEntry.getRelationship(); Capability capability = safe(nodeTemplate.getCapabilities()).get(targetRelationship.getTargetedCapabilityName()); if (capability == null || isCapabilityNotOfType(capability, targetRelationship.getRequirementType())) { Entry<String, Capability> capabilityEntry = NodeTemplateUtils.getCapabilitEntryyByType(nodeTemplate, targetRelationship.getRequirementType()); targetRelationship.setTargetedCapabilityName(capabilityEntry.getKey()); // check that the relationship type is still valid with the new capability RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, targetRelationship.getType()); if (!isValidRelationship(relationshipType, capabilityEntry.getValue())) { NodeType sourceNodeType = ToscaContext.get(NodeType.class, targetRelationshipEntry.getSource().getType()); RequirementDefinition requirementDefinition = NodeTypeUtils.getRequirementById(sourceNodeType, targetRelationshipEntry.getRelationship().getRequirementName()); NodeType targetNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType()); CapabilityDefinition capabilityDefinition = NodeTypeUtils.getCapabilityById(targetNodeType, capabilityEntry.getKey()); RelationshipType validRelationshipType = danglingRequirementService.fetchValidRelationshipType(requirementDefinition, capabilityDefinition); targetRelationship.setType(validRelationshipType.getElementId()); targetRelationship.setType(validRelationshipType.getElementId()); targetRelationship.setArtifacts(newLinkedHashMap(safe(validRelationshipType.getArtifacts()))); targetRelationship.setAttributes(newLinkedHashMap(safe(validRelationshipType.getAttributes()))); Map<String, AbstractPropertyValue> properties = new LinkedHashMap(); TemplateBuilder.fillProperties(properties, validRelationshipType.getProperties(), null); targetRelationship.setProperties(properties); } } } }