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