Changes Listed below:
[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     private String musicBuild;
48     
49     /* Data Fields */
50     private Map<String, HashMap<String, Object>> dataResult;
51     
52     /* Locking fields */
53     private String lock;
54     private LockStatus lockStatus;
55     private String lockHolder;
56     private String lockLease;
57
58
59     /**
60      * Create a JSONLock Response
61      * Use setters to provide more information as in
62      * JsonLockResponse(ResultType.SUCCESS).setMessage("We did it").setLock(mylockname)
63      * @param status
64      */
65     public JsonResponse(ResultType status) {
66         this.status = status;
67     }
68
69     /**
70      * 
71      * @return
72      */
73     @ApiModelProperty(value = "Overall status of the response.",
74                     allowableValues = "Success,Failure")
75     public ResultType getStatus() {
76         return status;
77     }
78
79     /**
80      * 
81      * @param status
82      */
83     public JsonResponse setStatus(ResultType status) {
84         this.status = status;
85         return this;
86     }
87
88     /**
89      * 
90      * @return the error
91      */
92     @ApiModelProperty(value = "Error value")
93     public String getError() {
94         return error;
95     }
96
97     /**
98      * 
99      * @param error
100      */
101     public JsonResponse setError(String error) {
102         this.error = error;
103         return this;
104     }
105     
106     /**
107      * 
108      * @return the message
109      */
110     @ApiModelProperty(value = "Message value")
111     public String getMessage() {
112         return message;
113     }
114
115     /**
116      * 
117      * @param message
118      */
119     public JsonResponse setMessage(String message) {
120         this.message = message;
121         return this;
122     }
123     
124     
125     /**
126      * .
127      * @return the music version
128      */
129     public String getMusicVersion() {
130         return this.musicVersion;
131     }
132     
133     /**
134      * .
135      * @param version of music
136      * @return
137      */
138     public JsonResponse setMusicVersion(String version) {
139         this.musicVersion = version;
140         return this;
141     }
142
143     /**
144      * .
145      * @return the music version
146      */
147     public String getMusicBuild() {
148         return this.musicBuild;
149     }
150     
151     /**
152      * .
153      * @param build of music
154      * @return
155      */
156     public JsonResponse setMusicBuild(String build) {
157         this.musicBuild = build;
158         return this;
159     }
160
161
162     public Map<String, HashMap<String, Object>> getDataResult() {
163         return this.dataResult;
164     }
165     
166     public JsonResponse setDataResult(Map<String, HashMap<String, Object>> map) {
167         this.dataResult = map;
168         return this;
169     }
170
171     /**
172      * 
173      * @return
174      */
175     public String getLock() {
176         return lock;
177     }
178
179     /**
180      * 
181      * @param lock
182      */
183     public JsonResponse setLock(String lock) {
184         this.lock = lock;
185         return this;
186     }
187     
188     /**
189      * 
190      * @return the lockStatus
191      */
192     @ApiModelProperty(value = "Status of the lock")
193     public LockStatus getLockStatus() {
194         return lockStatus;
195     }
196
197     /**
198      * 
199      * @param lockStatus
200      */
201     public JsonResponse setLockStatus(LockStatus lockStatus) {
202         this.lockStatus = lockStatus;
203         return this;
204     }
205
206     /**
207      * 
208      * 
209      * @return the lockHolder
210      */
211     @ApiModelProperty(value = "Holder of the Lock")
212     public String getLockHolder() {
213         return lockHolder;
214     }
215
216     /**
217      * 
218      * @param lockHolder
219      */
220     public JsonResponse setLockHolder(String lockHolder) {
221         this.lockHolder = lockHolder;
222         return this;
223     }
224
225
226
227     /**
228      * @return the lockLease
229      */
230     public String getLockLease() {
231         return lockLease;
232     }
233
234     /**
235      * @param lockLease the lockLease to set
236      */
237     public JsonResponse setLockLease(String lockLease) {
238         this.lockLease = lockLease;
239         return this;
240     }
241
242     /**
243      * Convert to Map
244      * 
245      * @return
246      */
247     public Map<String, Object> toMap() {
248         Map<String, Object> fullMap = new HashMap<>();
249         fullMap.put("status", status);
250         if (error != null && !"".equals(error)) { 
251             fullMap.put("error", error); 
252         }
253         if (message != null) { 
254             fullMap.put("message", message); 
255         }
256         
257         if (musicVersion != null) {
258             fullMap.put("version", musicVersion);
259         }
260         
261         if (musicBuild != null) {
262             fullMap.put("build", musicBuild);
263         }
264     
265         if (dataResult != null) {
266             fullMap.put("result", dataResult);
267         }
268         
269         if (lock != null) {
270             Map<String, Object> lockMap = new HashMap<>();
271             if (lock != null) {
272                 lockMap.put("lock", lock);
273             }
274             if (lockStatus != null) {
275                 lockMap.put("lock-status", lockStatus);
276             }
277             if (lockHolder != null) {
278                 lockMap.put("lock-holder", lockHolder);
279             }
280             if (lockLease != null) {
281                 lockMap.put("lock-lease", lockLease);
282             }
283             fullMap.put("lock", lockMap);
284         }
285
286         return fullMap;
287     }
288
289     /**
290      * Convert to String
291      */
292     @Override
293     public String toString() {
294         return "JsonLockResponse [status=" + status + ", error=" + error + ", message=" + message
295                         + ", lock=" + lock + ", lockStatus=" + lockStatus + ", lockHolder="
296                         + lockHolder + "]";
297     }
298
299 }