code coverage for M3
[dcaegen2/services/son-handler.git] / src / main / java / org / onap / dcaegen2 / services / sonhms / child / ChildThreadUtils.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 com.fasterxml.jackson.annotation.JsonInclude.Include;
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import org.onap.dcaegen2.services.sonhms.ConfigPolicy;
28 import org.onap.dcaegen2.services.sonhms.model.CellConfig;
29 import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
30 import org.onap.dcaegen2.services.sonhms.model.Common;
31 import org.onap.dcaegen2.services.sonhms.model.Configurations;
32 import org.onap.dcaegen2.services.sonhms.model.Data;
33 import org.onap.dcaegen2.services.sonhms.model.FapService;
34 import org.onap.dcaegen2.services.sonhms.model.Lte;
35 import org.onap.dcaegen2.services.sonhms.model.Payload;
36 import org.onap.dcaegen2.services.sonhms.model.PolicyNotification;
37 import org.onap.dcaegen2.services.sonhms.model.Ran;
38 import org.onap.dcaegen2.services.sonhms.model.X0005b9Lte;
39 import java.util.ArrayList;
40 import java.util.List;
41 import org.slf4j.Logger;
42
43 public class ChildThreadUtils {
44     
45     private static final Logger log = org.slf4j.LoggerFactory.getLogger(ChildThreadUtils.class);
46     ConfigPolicy configPolicy;
47     
48     public ChildThreadUtils(ConfigPolicy configPolicy) {
49         this.configPolicy = configPolicy;
50     }
51     
52     
53     /**
54      * get policy notification string from oof result.
55      *
56      */
57     public String getNotificationString(String pnfName, List<CellPciPair> cellPciPairs, String requestId,
58             Long alarmStartTime) {
59         ArrayList<Configurations> configurations = new ArrayList<>();
60         for (CellPciPair cellPciPair : cellPciPairs) {
61             String cellId = cellPciPair.getCellId();
62             int pci = cellPciPair.getPhysicalCellId();
63             Configurations configuration = new Configurations(new Data(new FapService(cellId,
64                     new X0005b9Lte(pci, pnfName), new CellConfig(new Lte(new Ran(new Common(cellId)))))));
65             configurations.add(configuration);
66         }
67
68         Payload payload = new Payload(configurations);
69         ObjectMapper mapper = new ObjectMapper();
70         String payloadString = "";
71         try {
72             payloadString = mapper.writeValueAsString(payload);
73         } catch (JsonProcessingException e) {
74             log.debug("JSON processing exception: {}", e);
75         }
76         
77         String closedLoopControlName = (String) configPolicy.getConfig().get("PCI_MODCONFIG_POLICY_NAME");
78         PolicyNotification policyNotification = new PolicyNotification(closedLoopControlName, 
79                 requestId, alarmStartTime, pnfName);
80         
81         policyNotification.setClosedLoopControlName(closedLoopControlName);
82         policyNotification.setPayload(payloadString);
83
84         mapper.setSerializationInclusion(Include.NON_NULL);
85         String notification = "";
86         try {
87             notification = mapper.writeValueAsString(policyNotification);
88         } catch (JsonProcessingException e1) {
89             log.debug("JSON processing exception: {}", e1);
90         }
91         return notification;
92     }
93     
94 }