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