8e589efe96289ba2e5b709d37fcd8aea5a3a6034
[music.git] / src / main / java / org / onap / music / response / jsonobjects / JsonResponse.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
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  * 
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22
23 package org.onap.music.response.jsonobjects;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
29 import org.onap.music.main.ResultType;
30
31
32 import io.swagger.annotations.ApiModel;
33 import io.swagger.annotations.ApiModelProperty;
34
35 @ApiModel(value = "JsonResponse", description = "General Response JSON")
36 public class JsonResponse {
37
38     /* Status is required */
39     private ResultType status;
40     
41     /* Standard informational fields */
42     private String error;
43     private String message;
44     
45     /* versioning */
46     private String musicVersion;
47     
48     /* Data Fields */
49     private Map<String, HashMap<String, Object>> dataResult;
50     
51     /* Locking fields */
52     private String lock;
53     private LockStatus lockStatus;
54     private String lockHolder;
55     private String lockLease;
56
57
58     /**
59      * Create a JSONLock Response
60      * Use setters to provide more information as in
61      * JsonLockResponse(ResultType.SUCCESS).setMessage("We did it").setLock(mylockname)
62      * @param status
63      */
64     public JsonResponse(ResultType status) {
65         this.status = status;
66     }
67
68      /**
69      * 
70      * @return
71      */
72     @ApiModelProperty(value = "Overall status of the response.",
73                     allowableValues = "Success,Failure")
74     public ResultType getStatus() {
75         return status;
76     }
77
78     /**
79      * 
80      * @param status
81      */
82     public JsonResponse setStatus(ResultType status) {
83         this.status = status;
84         return this;
85     }
86
87     /**
88      * 
89      * @return the error
90      */
91     @ApiModelProperty(value = "Error value")
92     public String getError() {
93         return error;
94     }
95
96     /**
97      * 
98      * @param error
99      */
100     public JsonResponse setError(String error) {
101         this.error = error;
102         return this;
103     }
104     
105     /**
106      * 
107      * @return the message
108      */
109     @ApiModelProperty(value = "Message value")
110     public String getMessage() {
111         return message;
112     }
113
114     /**
115      * 
116      * @param message
117      */
118     public JsonResponse setMessage(String message) {
119         this.message = message;
120         return this;
121     }
122     
123     
124     /**
125      * 
126      * @return the music version
127      */
128     public String getMusicVersion() {
129         return this.musicVersion;
130     }
131     
132     /**
133      * 
134      * @param version of music
135      * @return
136      */
137     public JsonResponse setMusicVersion(String version) {
138         this.musicVersion = version;
139         return this;
140     }
141
142     public Map<String, HashMap<String, Object>> getDataResult() {
143         return this.dataResult;
144     }
145     
146     public JsonResponse setDataResult(Map<String, HashMap<String, Object>> map) {
147         this.dataResult = map;
148         return this;
149     }
150
151     /**
152      * 
153      * @return
154      */
155     public String getLock() {
156         return lock;
157     }
158
159     /**
160      * 
161      * @param lock
162      */
163     public JsonResponse setLock(String lock) {
164         this.lock = lock;
165         return this;
166     }
167     
168     /**
169      * 
170      * @return the lockStatus
171      */
172     @ApiModelProperty(value = "Status of the lock")
173     public LockStatus getLockStatus() {
174         return lockStatus;
175     }
176
177     /**
178      * 
179      * @param lockStatus
180      */
181     public JsonResponse setLockStatus(LockStatus lockStatus) {
182         this.lockStatus = lockStatus;
183         return this;
184     }
185
186     /**
187      * 
188      * 
189      * @return the lockHolder
190      */
191     @ApiModelProperty(value = "Holder of the Lock")
192     public String getLockHolder() {
193         return lockHolder;
194     }
195
196     /**
197      * 
198      * @param lockHolder
199      */
200     public JsonResponse setLockHolder(String lockHolder) {
201         this.lockHolder = lockHolder;
202         return this;
203     }
204
205
206
207     /**
208      * @return the lockLease
209      */
210     public String getLockLease() {
211         return lockLease;
212     }
213
214     /**
215      * @param lockLease the lockLease to set
216      */
217     public JsonResponse setLockLease(String lockLease) {
218         this.lockLease = lockLease;
219         return this;
220     }
221
222     /**
223      * Convert to Map
224      * 
225      * @return
226      */
227     public Map<String, Object> toMap() {
228         Map<String, Object> fullMap = new HashMap<>();
229         fullMap.put("status", status);
230 /*<<<<<<< HEAD
231         if (error!=null) {
232             fullMap.put("error", error);
233         }
234         if (message!=null) {
235             fullMap.put("message", message);
236         }
237 =======*/
238         if (error!=null && !"".equals(error)) {fullMap.put("error", error);}
239         if (message!=null) {fullMap.put("message", message);}
240         
241         if (musicVersion!=null) {
242             fullMap.put("version", musicVersion);
243         }
244         
245         if (dataResult!=null) {
246             fullMap.put("result", dataResult);
247         }
248         
249         if (lock!=null) {
250             Map<String, Object> lockMap = new HashMap<>();
251             if (lock!=null) {
252                 lockMap.put("lock", lock);
253             }
254             if (lockStatus!=null) {
255                 lockMap.put("lock-status", lockStatus);
256             }
257             if (lockHolder!=null) {
258                 lockMap.put("lock-holder", lockHolder);
259             }
260             if (lockLease!=null) {
261                 lockMap.put("lock-lease", lockLease);
262             }
263             fullMap.put("lock", lockMap);
264         }
265
266         return fullMap;
267     }
268
269     /**
270      * Convert to String
271      */
272     @Override
273     public String toString() {
274         return "JsonLockResponse [status=" + status + ", error=" + error + ", message=" + message
275                         + ", lock=" + lock + ", lockStatus=" + lockStatus + ", lockHolder="
276                         + lockHolder + "]";
277     }
278
279 }