use of com.google.common.collect.Maps.newLinkedHashMap in project alien4cloud by alien4cloud.
the class ReplaceNodeProcessor method removeTheRelationshipsOnSource.
/**
* If the node to replace is an target of relationship, we should swapped the relationship on source and clean used workflow steps
*/
private Map<String, Map<String, RelationshipTemplate>> removeTheRelationshipsOnSource(Topology topology, Csar csar, String nodeToReplace) {
Map<String, Map<String, RelationshipTemplate>> relationshipDeleted = Maps.newLinkedHashMap();
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
if (!nodeToReplace.equals(nodeTemplate.getName())) {
List<String> relationshipsToRemove = Lists.newArrayList();
for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
if (nodeToReplace.equals(relationshipTemplate.getTarget())) {
relationshipsToRemove.add(relationshipTemplate.getName());
if (!relationshipDeleted.containsKey(relationshipTemplate.getName())) {
Map<String, RelationshipTemplate> relationships = Maps.newHashMap();
// we save the RelationshipTemplate, so we will preserve the current properties of this relationship
relationshipDeleted.put(nodeTemplate.getName(), relationships);
}
relationshipDeleted.get(nodeTemplate.getName()).put(relationshipTemplate.getName(), relationshipTemplate);
// we should remove this relationship to maintain a great a workflow
workflowBuilderService.removeRelationship(topology, csar, nodeTemplate.getName(), relationshipTemplate.getName(), relationshipTemplate);
}
}
}
}
return relationshipDeleted;
}
Aggregations