Search in sources :

Example 1 with YTMapRequirementAssignment

use of org.eclipse.winery.model.tosca.yaml.support.YTMapRequirementAssignment 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)

Example 2 with YTMapRequirementAssignment

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

the class YamlBuilder method buildMapRequirementAssignment.

@Nullable
public YTMapRequirementAssignment buildMapRequirementAssignment(Object object, Parameter<YTMapRequirementAssignment> parameter) {
    if (Objects.isNull(object)) {
        return null;
    }
    YTMapRequirementAssignment result = new YTMapRequirementAssignment();
    put(result, stringValue(parameter.getValue()), buildRequirementAssignment(object, new Parameter<>(parameter.getContext())));
    return result;
}
Also used : YTMapRequirementAssignment(org.eclipse.winery.model.tosca.yaml.support.YTMapRequirementAssignment) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

YTMapRequirementAssignment (org.eclipse.winery.model.tosca.yaml.support.YTMapRequirementAssignment)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Nullable (org.eclipse.jdt.annotation.Nullable)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