Merge "Add debugging of REST call"
[policy/drools-applications.git] / controlloop / common / model-impl / appc / src / main / java / org / onap / policy / appc / Response.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * appc
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
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 package org.onap.policy.appc;
22
23 import com.google.gson.annotations.SerializedName;
24
25 import java.io.Serializable;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 public class Response implements Serializable {
30     private static final long serialVersionUID = 434953706339865151L;
31
32     @SerializedName("CommonHeader")
33     private CommonHeader commonHeader;
34
35     @SerializedName("Status")
36     private ResponseStatus status = new ResponseStatus();
37
38     @SerializedName("Payload")
39     private HashMap<String, Object> payload = new HashMap<>();
40
41     public Response() {
42
43     }
44
45     /**
46      * Construct an instance from an existing instance.
47      * 
48      * @param request the existing instance
49      */
50     public Response(Request request) {
51         if (request.getCommonHeader() != null) {
52             this.commonHeader = new CommonHeader(request.getCommonHeader());
53         }
54         if (request.getPayload() != null) {
55             this.payload.putAll(request.getPayload());
56         }
57     }
58
59     public CommonHeader getCommonHeader() {
60         return commonHeader;
61     }
62
63     public void setCommonHeader(CommonHeader commonHeader) {
64         this.commonHeader = commonHeader;
65     }
66
67     public ResponseStatus getStatus() {
68         return status;
69     }
70
71     public void setStatus(ResponseStatus status) {
72         this.status = status;
73     }
74
75     public Map<String, Object> getPayload() {
76         return payload;
77     }
78
79     public void setPayload(Map<String, Object> payload) {
80         this.payload = new HashMap<>(payload);
81     }
82
83     @Override
84     public String toString() {
85         return "Response [CommonHeader=" + commonHeader + ", Status=" + status + ", Payload=" + payload + "]";
86     }
87
88     @Override
89     public int hashCode() {
90         final int prime = 31;
91         int result = 1;
92         result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
93         result = prime * result + ((payload == null) ? 0 : payload.hashCode());
94         result = prime * result + ((status == null) ? 0 : status.hashCode());
95         return result;
96     }
97
98     @Override
99     public boolean equals(Object obj) {
100         if (this == obj) {
101             return true;
102         }
103         if (obj == null) {
104             return false;
105         }
106         if (getClass() != obj.getClass()) {
107             return false;
108         }
109         Response other = (Response) obj;
110         if (commonHeader == null) {
111             if (other.commonHeader != null) {
112                 return false;
113             }
114         } else if (!commonHeader.equals(other.commonHeader)) {
115             return false;
116         }
117         if (payload == null) {
118             if (other.payload != null) {
119                 return false;
120             }
121         } else if (!payload.equals(other.payload)) {
122             return false;
123         }
124         if (status == null) {
125             if (other.status != null) {
126                 return false;
127             }
128         } else if (!status.equals(other.status)) {
129             return false;
130         }
131         return true;
132     }
133
134
135
136 }