aa1964b5c1a84d5e6270e9caa96a90fff8cb00fa
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.sdnc.config.audit.node;
26
27 import java.io.IOException;
28 import java.util.Map;
29
30
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
33 import com.fasterxml.jackson.core.JsonParseException;
34 import com.fasterxml.jackson.databind.JsonMappingException;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36
37
38 public class CompareJsonData implements CompareDataInterface {
39
40     private static final EELFLogger log = EELFManager.getInstance().getLogger(CompareJsonData.class);
41
42     String payloadX;
43     String payloadY;
44
45     public CompareJsonData(String payloadX, String payloadY)
46     {
47         this.payloadX = payloadX;
48         this.payloadY = payloadY;
49     }
50
51     @Override
52     public boolean compare() throws Exception
53     {
54
55         ObjectMapper dataMapper = new ObjectMapper();
56         boolean match = false;
57         try
58         {
59             Map<String, Object> controlData = (Map<String, Object>)(dataMapper.readValue(payloadX, Map.class));
60             Map<String, Object>  testData = (Map<String, Object>)(dataMapper.readValue(payloadY, Map.class));
61
62             log.debug("Control Data :" + controlData);
63             log.debug("testData Data :" + testData);
64
65            if(controlData.equals(testData))
66                match=true;
67         }
68         catch(JsonParseException e)
69         {
70             throw new Exception(e.getMessage());
71         }
72         catch(JsonMappingException e)
73         {
74             throw new Exception(e.getMessage());
75         }
76         catch(IOException ioe)
77         {
78             throw new Exception(ioe.getMessage());
79         }
80
81         return match;
82     }
83 }