Update license header in appc-inbound files
[appc.git] / appc-inbound / appc-design-services / provider / src / main / java / org / onap / appc / design / xinterface / XResponseProcessor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.design.xinterface;
25
26 import java.util.HashMap;
27
28 import org.onap.appc.design.services.util.DesignServiceConstants;
29 import org.onap.appc.instar.dme2client.Dme2Client;
30
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
33 import com.fasterxml.jackson.databind.JsonNode;
34 import com.fasterxml.jackson.databind.ObjectMapper;
35
36 public class XResponseProcessor {
37
38    private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class);
39     Dme2Client dme2Client;
40
41     public String parseResponse(String execute, String action) throws Exception {
42         ObjectMapper objectMapper = new ObjectMapper();
43         JsonNode payloadObject = objectMapper.readTree(execute);
44         log.info("payloadObject " + payloadObject);
45
46         //String queryParam = null;
47         String instarResponse = null;
48         HashMap<String, String> payload = null;
49         String ipAddress = null;
50         String mask = null;
51
52         try {
53
54             // check the payload whether its having ipaddr along with subnet
55             ipAddress = payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS) != null
56                     ? payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS).textValue()
57                     : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) !=null)
58                         ?payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue().toUpperCase()
59                                 :null;
60
61             mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null
62                     ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue()
63                     : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null)
64                             ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase()
65                             : null;
66
67             // TODO -short format
68
69             /*if (mask != null) {
70                 queryParam = ipAddress + "," +mask ;
71                 log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask );
72             } else {
73                 queryParam = "ipAddress "+ipAddress ;
74                 log.info("Calling Instar with IpAddress "+ ipAddress);
75             }*/
76
77             payload = new HashMap<String, String>();
78             payload.put("ipAddress", ipAddress);
79             payload.put("mask", mask);
80             log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask );
81             dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload);
82
83             instarResponse = dme2Client.send();
84
85             log.debug("Resposne from Instar = " + instarResponse);
86             if (instarResponse == null || instarResponse.length() < 0)
87                 throw new Exception("No Data received from Instar for this action " + action);
88         } catch (Exception e) {
89             e.printStackTrace();
90             throw e;
91         }
92         return instarResponse;
93     }
94 }