Search in sources :

Example 1 with YTRequirementAssignment

use of org.eclipse.winery.model.tosca.yaml.YTRequirementAssignment in project winery by eclipse.

the class ToCanonical method enhanceTopology.

/**
 * Determines and updates the source and target for relationship templates in the given canonical topology based on
 * the yaml node template definitions. Relationships are determined through the requirements of the given node
 * templates.
 *
 * @param topology      A canonical model TopologyTemplate
 * @param nodeTemplates The node templates of the yaml topology template that was originally converted into the
 *                      <tt>topology</tt>
 */
private void enhanceTopology(TTopologyTemplate topology, @NonNull Map<String, YTNodeTemplate> nodeTemplates) {
    if (topology == null) {
        return;
    }
    nodeTemplates.forEach((id, nt) -> {
        @NonNull List<YTMapRequirementAssignment> reqs = nt.getRequirements();
        if (reqs.isEmpty()) {
            return;
        }
        for (YTMapRequirementAssignment map : reqs) {
            for (Map.Entry<String, YTRequirementAssignment> data : map.getMap().entrySet()) {
                final YTRequirementAssignment req = data.getValue();
                TRelationshipTemplate relationship = topology.getRelationshipTemplate(req.getRelationship().getType().toString());
                if (relationship == null) {
                    // requirement with a type that is not a RelationshipTemplate in the topology
                    continue;
                }
                relationship.setTargetNodeTemplate(topology.getNodeTemplate(req.getNode().toString()));
                relationship.setSourceNodeTemplate(topology.getNodeTemplate(id));
            }
        }
    });
}
Also used : YTMapRequirementAssignment(org.eclipse.winery.model.tosca.yaml.support.YTMapRequirementAssignment) NonNull(org.eclipse.jdt.annotation.NonNull) YTRelationshipTemplate(org.eclipse.winery.model.tosca.yaml.YTRelationshipTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) YTRequirementAssignment(org.eclipse.winery.model.tosca.yaml.YTRequirementAssignment) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)1 YTRelationshipTemplate (org.eclipse.winery.model.tosca.yaml.YTRelationshipTemplate)1 YTRequirementAssignment (org.eclipse.winery.model.tosca.yaml.YTRequirementAssignment)1 YTMapRequirementAssignment (org.eclipse.winery.model.tosca.yaml.support.YTMapRequirementAssignment)1