2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.instar.interfaceImpl;
27 import org.json.JSONArray;
28 import org.json.JSONObject;
29 import org.openecomp.appc.instar.interfaces.ResponseHandlerInterface;
30 import org.openecomp.appc.instar.utils.InstarClientConstant;
31 import org.openecomp.sdnc.config.params.data.ResponseKey;
32 import org.openecomp.sdnc.sli.SvcLogicContext;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
37 public class InstarResponseHandlerImpl implements ResponseHandlerInterface {
39 private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarResponseHandlerImpl.class);
41 ResponseKey resKey = null;
42 SvcLogicContext ctxt = null;
44 public InstarResponseHandlerImpl(ResponseKey filterKeys, SvcLogicContext context) {
45 this.resKey = filterKeys;
51 public Object processResponse(String instarResponse, String instarKey) {
52 String fn = " InstarResponseHandlerImpl.processResponse ";
53 log.info(fn + " Instar Response :" + instarResponse);
55 JSONObject instarKeyValues;
57 log.info("Instar Data in Context : "+ ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
58 if(ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES) != null){
59 instarKeyValues = new JSONObject(ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
60 log.info("Instar data already exsits : " + instarKeyValues.toString());
63 instarKeyValues = new JSONObject();
64 JSONArray instarResponses = new JSONObject(instarResponse).getJSONArray(InstarClientConstant.INSTAR_RESPONSE_BLOCK_NAME);
65 for (int i = 0; i < instarResponses.length(); i++){
66 JSONObject res = instarResponses.getJSONObject(i);
67 log.info(fn + "Instar Block :" + i + " Values :" + res.toString());
68 log.info(fn + "Appc Filter Key :" + ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey.getUniqueKeyValue());
70 if(res.getString(InstarClientConstant.FDQN) != null &&
71 res.getString(InstarClientConstant.FDQN).equalsIgnoreCase(ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey.getUniqueKeyValue())){
72 if(resKey.getFieldKeyName().equals(InstarClientConstant.V4_ADDRESS))
73 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_ADDRESS));
74 else if(resKey.getFieldKeyName().equals(InstarClientConstant.V6_ADDRESS))
75 instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_ADDRESS));
79 log.info(fn + "Instar KeyValues :" + instarKeyValues);
80 ctxt.setAttribute(InstarClientConstant.INSTAR_KEY_VALUES, instarKeyValues.toString());
83 return instarKeyValues;