Fix bugs and formatting issues
[dcaegen2/services/son-handler.git] / src / main / java / org / onap / dcaegen2 / services / sonhms / child / PnfUtils.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  son-handler
4  *  ================================================================================
5  *   Copyright (C) 2019 Wipro Limited.
6  *   ==============================================================================
7  *     Licensed under the Apache License, Version 2.0 (the "License");
8  *     you may not use this file except in compliance with the License.
9  *     You may obtain a copy of the License at
10  *  
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *  
13  *     Unless required by applicable law or agreed to in writing, software
14  *     distributed under the License is distributed on an "AS IS" BASIS,
15  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *     See the License for the specific language governing permissions and
17  *     limitations under the License.
18  *     ============LICENSE_END=========================================================
19  *  
20  *******************************************************************************/
21
22 package org.onap.dcaegen2.services.sonhms.child;
23
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Optional;
29
30 import org.onap.dcaegen2.services.sonhms.dao.CellInfoRepository;
31 import org.onap.dcaegen2.services.sonhms.entity.CellInfo;
32 import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException;
33 import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
34 import org.onap.dcaegen2.services.sonhms.restclient.AnrSolutions;
35 import org.onap.dcaegen2.services.sonhms.restclient.PciSolutions;
36 import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
37 import org.onap.dcaegen2.services.sonhms.restclient.Solutions;
38 import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
39 import org.slf4j.Logger;
40
41
42
43 public class PnfUtils {
44
45     private static final Logger log = org.slf4j.LoggerFactory.getLogger(ChildThreadUtils.class);
46
47     /**
48      * get pnfs.
49      *
50      */
51     public Map<String, List<CellPciPair>> getPnfs(Solutions solutions) throws ConfigDbNotFoundException {
52
53         Map<String, List<CellPciPair>> pnfs = new HashMap<>(); 
54         List<PciSolutions> pciSolutions = solutions.getPciSolutions();
55         for (PciSolutions pciSolution : pciSolutions) {
56                 String cellId = pciSolution.getCellId();
57                 int pci = pciSolution.getPci();
58
59                 String pnfName = "";
60                 CellInfoRepository cellInfoRepository = BeanUtil.getBean(CellInfoRepository.class);
61                 Optional<CellInfo> cellInfo = cellInfoRepository.findById(cellId);
62                 if (cellInfo.isPresent()) {
63                     pnfName = cellInfo.get().getPnfName();
64                 } else {
65                     pnfName = SdnrRestClient.getPnfName(cellId);
66                     cellInfoRepository.save(new CellInfo(cellId, pnfName));
67                 }
68                 if (pnfs.containsKey(pnfName)) {
69                     pnfs.get(pnfName).add(new CellPciPair(cellId, pci));
70                 } else {
71                     List<CellPciPair> cellPciPairs = new ArrayList<>();
72                     cellPciPairs.add(new CellPciPair(cellId, pci));
73                     pnfs.put(pnfName, cellPciPairs);
74                 }
75
76         }
77         return pnfs;
78     }
79     
80     /**
81      * get pnfs for ANR solutions
82      * 
83      */
84     public Map<String, List<Map<String,List<String>>>> getPnfsForAnrSolutions(List<AnrSolutions> anrSolutions) throws ConfigDbNotFoundException {
85         
86         Map<String, List<Map<String,List<String>>>> anrPnfs = new HashMap<>();
87         
88         List<String> removeableNeighbors;
89         for(AnrSolutions anrSolution : anrSolutions) {
90             String cellId = anrSolution.getCellId();
91             String pnfName = SdnrRestClient.getPnfName(cellId);
92             removeableNeighbors = anrSolution.getRemoveableNeighbors();
93             Map<String,List<String>> cellRemNeighborsPair = new HashMap<>();
94             cellRemNeighborsPair.put(cellId, removeableNeighbors);
95             if(anrPnfs.containsKey(pnfName)) {
96                 anrPnfs.get(pnfName).add(cellRemNeighborsPair);
97             }else {
98                 List<Map<String,List<String>>> anrCells = new ArrayList<>();
99                 anrCells.add(cellRemNeighborsPair);
100                 anrPnfs.put(pnfName, anrCells);
101             }
102         }
103         log.info("anr Pnfs {}",anrPnfs.toString());
104         return anrPnfs;
105         
106     }
107 }