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.onap.sdnc.config.audit.node;
 
  28 import com.att.eelf.configuration.EELFLogger;
 
  29 import com.att.eelf.configuration.EELFManager;
 
  30 import java.util.HashMap;
 
  32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  33 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
  34 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
 
  36 public class CompareNode implements SvcLogicJavaPlugin {
 
  38     private static final EELFLogger log = EELFManager.getInstance().getLogger(CompareNode.class);
 
  40     public void compare(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
 
  41         log.debug("Starting Compare Node Analysis");
 
  43         Map<String, String> status = new HashMap<>();
 
  44         Parameters params = new Parameters(inParams);
 
  46             if (params.getCompareDataType() != null) {
 
  47                 if (params.getPayloadX() != null && params.getPayloadY() != null) {
 
  48                     status = getCompareResults(params);
 
  49                     log.debug("Compare Result : " + status);
 
  51                     status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
 
  52                     status.put(CompareConstants.ERROR_CODE, "200");
 
  53                     status.put(CompareConstants.ERROR_MESSAGE, "One of the Data Received by CompareNode is Empty");
 
  56                 status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
 
  57                 status.put(CompareConstants.ERROR_CODE, "200");
 
  58                 status.put(CompareConstants.ERROR_MESSAGE,
 
  59                     "Missing compareDataType value in input request: Expecting at least one of  CLI/RESTCONF/XML");
 
  62         } catch (Exception e) {
 
  63             status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
 
  64             status.put(CompareConstants.ERROR_CODE, "200");
 
  65             status.put(CompareConstants.ERROR_MESSAGE, CompareConstants.ERROR_MESSAGE_DETAIL);
 
  66             log.debug("Error in Comapre Node Execution", e);
 
  68         createContextResponse(status, ctx, params.getRequestIdentifier());
 
  71     private HashMap<String, String> getCompareResults(Parameters params) throws Exception {
 
  72         HashMap<String, String> resultMap = new HashMap<>();
 
  74         CompareDataInterface handler;
 
  76         if (params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_JSON)) {
 
  77             handler = new CompareJsonData(params.getPayloadX(), params.getPayloadY());
 
  78         } else if ((params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_XML))
 
  79             || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.NETCONF_XML))
 
  80             || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.RESTCONF_XML))) {
 
  81             handler = new CompareXmlData(params.getPayloadX(), params.getPayloadY());
 
  82         } else if (params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_CLI)) {
 
  83             handler = new CompareCliData(params.getPayloadX(), params.getPayloadY());
 
  85             throw new SvcLogicException("Format " + params.getCompareDataType() + " not supported");
 
  88             log.debug("Received Format to compare : " + params.getCompareDataType());
 
  90             cmpResult = handler.compare();
 
  92                 resultMap.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_SUCCESS);
 
  95                 resultMap.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
 
  96                 resultMap.put(CompareConstants.ERROR_CODE, "500");
 
  97                 resultMap.put(CompareConstants.ERROR_MESSAGE, CompareConstants.NO_MATCH_MESSAGE);
 
  99         } catch (Exception e) {
 
 105     private void createContextResponse(Map<String, String> status, SvcLogicContext ctx, String requestIdentifier) {
 
 106         String requestId = requestIdentifier == null ? "" : requestIdentifier + ".";
 
 108         ctx.setAttribute(requestId.concat(CompareConstants.RESPONSE_STATUS),
 
 109             status.get(CompareConstants.RESPONSE_STATUS));
 
 110         ctx.setAttribute(requestId.concat(CompareConstants.ERROR_CODE),
 
 111             status.get(CompareConstants.ERROR_CODE));
 
 112         ctx.setAttribute(requestId.concat(CompareConstants.ERROR_MESSAGE),
 
 113             status.get(CompareConstants.ERROR_MESSAGE));