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