Merge "Add debugging of REST call"
[policy/drools-applications.git] / controlloop / common / model-impl / appclcm / src / main / java / org / onap / policy / appclcm / LcmResponse.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * appclcm
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.appclcm;
22
23 import com.google.gson.annotations.SerializedName;
24
25 import java.io.Serializable;
26
27 public class LcmResponse implements Serializable {
28
29     private static final long serialVersionUID = 6332508597287669750L;
30
31     @SerializedName(value = "common-header")
32     private LcmCommonHeader commonHeader;
33
34     @SerializedName(value = "status")
35     private LcmResponseStatus status = new LcmResponseStatus();
36
37     @SerializedName(value = "payload")
38     private String payload;
39
40     public LcmResponse() {
41         // EMPTY
42     }
43
44     /**
45      * Constructs a response using the common header of the request since they will be the same.
46      * 
47      * @param request an appc lcm request object specified by the lcm api guide
48      */
49     public LcmResponse(LcmRequest request) {
50         this.commonHeader = new LcmCommonHeader(request.getCommonHeader());
51         String requestPayload = request.getPayload();
52         if (requestPayload != null) {
53             this.payload = requestPayload;
54         }
55     }
56
57     /**
58      * Get the common header.
59      * 
60      * @return the commonHeader
61      */
62     public LcmCommonHeader getCommonHeader() {
63         return commonHeader;
64     }
65
66     /**
67      * Set the common header.
68      * 
69      * @param commonHeader the commonHeader to set
70      */
71     public void setCommonHeader(LcmCommonHeader commonHeader) {
72         this.commonHeader = commonHeader;
73     }
74
75     /**
76      * Get the status.
77      * 
78      * @return the status
79      */
80     public LcmResponseStatus getStatus() {
81         return status;
82     }
83
84     /**
85      * Set the status.
86      * 
87      * @param status the status to set
88      */
89     public void setStatus(LcmResponseStatus status) {
90         this.status = status;
91     }
92
93     /**
94      * Get the payload.
95      * 
96      * @return the payload
97      */
98     public String getPayload() {
99         return payload;
100     }
101
102     /**
103      * Set the payload.
104      * 
105      * @param payload the payload to set
106      */
107     public void setPayload(String payload) {
108         this.payload = payload;
109     }
110
111     @Override
112     public String toString() {
113         return "Response [commonHeader=" + commonHeader + ", status=" + status + ", payload=" + payload + "]";
114     }
115
116     @Override
117     public int hashCode() {
118         final int prime = 31;
119         int result = 1;
120         result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
121         result = prime * result + ((payload == null) ? 0 : payload.hashCode());
122         result = prime * result + ((status == null) ? 0 : status.hashCode());
123         return result;
124     }
125
126     @Override
127     public boolean equals(Object obj) {
128         if (this == obj) {
129             return true;
130         }
131         if (obj == null) {
132             return false;
133         }
134         if (getClass() != obj.getClass()) {
135             return false;
136         }
137         LcmResponse other = (LcmResponse) obj;
138         if (commonHeader == null) {
139             if (other.commonHeader != null) {
140                 return false;
141             }
142         } else if (!commonHeader.equals(other.commonHeader)) {
143             return false;
144         }
145         if (payload == null) {
146             if (other.payload != null) {
147                 return false;
148             }
149         } else if (!payload.equals(other.payload)) {
150             return false;
151         }
152         if (status == null) {
153             if (other.status != null) {
154                 return false;
155             }
156         } else if (!status.equals(other.status)) {
157             return false;
158         }
159         return true;
160     }
161 }