7f3025408f66a9629d8c4e478e735f2cdf9f0593
[sdc.git] /
1 package org.openecomp.sdc.translator.services.heattotosca;
2
3 import org.apache.commons.collections4.MapUtils;
4 import org.openecomp.sdc.logging.api.Logger;
5 import org.openecomp.sdc.logging.api.LoggerFactory;
6 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeTemplateConsolidationData;
7
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13
14 /**
15  * Utility class for consolidation data collection helper methods.
16  */
17 public class UnifiedCompositionUtil {
18
19   protected static Logger logger = LoggerFactory.getLogger(UnifiedCompositionUtil.class);
20
21   /**
22    * Gets all ports per port type, which are connected to the computes from the input
23    * computeTemplateConsolidationDataCollection.
24    *
25    * @param computeTemplateConsolidationDataCollection collection of compute template
26    *                                                   consolidation data
27    * @return set of port ids, per port type
28    */
29   static Map<String, List<String>> collectAllPortsFromEachTypesFromComputes(
30       Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationDataCollection) {
31     Map<String, List<String>> portTypeToIds = new HashMap<>();
32
33     for (ComputeTemplateConsolidationData compute : computeTemplateConsolidationDataCollection) {
34       Map<String, List<String>> ports = compute.getPorts();
35       if (!MapUtils.isEmpty(ports)) {
36         addPortsToMap(portTypeToIds, ports);
37       }
38     }
39
40     return portTypeToIds;
41   }
42
43   private static void addPortsToMap(Map<String, List<String>> portTypeToIds,
44                                     Map<String, List<String>> ports) {
45     for (Map.Entry<String, List<String>> portTypeToIdEntry : ports.entrySet()) {
46       portTypeToIds.putIfAbsent(portTypeToIdEntry.getKey(), new ArrayList<>());
47       portTypeToIds.get(portTypeToIdEntry.getKey()).addAll(portTypeToIdEntry.getValue());
48     }
49   }
50
51
52 }