Initial code Import.
[music.git] / src / main / java / org / onap / music / response / jsonobjects / JsonLockResponse.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 import io.swagger.annotations.ApiModel;
27 import io.swagger.annotations.ApiModelProperty;
28
29 @ApiModel(value = "JsonResponse", description = "General Response JSON")
30 public class JsonLockResponse {
31
32     private String status = "";
33     private String error = "";
34     private String message = "";
35     private String lock = "";
36     private String lockStatus = "";
37     private String lockHolder = "";
38     private String lockLease = "";
39
40     /**
41      * 
42      * @param status
43      * @param error
44      * @param lock
45      */
46     public JsonLockResponse(String status, String error, String lock) {
47         this.status = fixStatus(status);
48         this.error = error;
49         this.lock = lock;
50     }
51
52     /**
53      * 
54      * @param status
55      * @param error
56      * @param lock
57      * @param lockStatus
58      * @param lockHolder
59      */
60     public JsonLockResponse(String status, String error, String lock, String lockStatus,
61                     String lockHolder) {
62         this.status = fixStatus(status);
63         this.error = error;
64         this.lock = lock;
65         this.lockStatus = lockStatus;
66         this.lockHolder = lockHolder;
67     }
68
69     /**
70      * 
71      * @param status
72      * @param error
73      * @param lock
74      * @param lockStatus
75      * @param lockHolder
76      * @param lockLease
77      */
78     public JsonLockResponse(String status, String error, String lock, String lockStatus,
79                     String lockHolder, String lockLease) {
80         this.status = fixStatus(status);
81         this.error = error;
82         this.lock = lock;
83         this.lockStatus = lockStatus;
84         this.lockHolder = lockHolder;
85     }
86
87
88     /**
89      * Lock
90      * 
91      * @return
92      */
93     public String getLock() {
94         return lock;
95     }
96
97     /**
98      * 
99      * @param lock
100      */
101     public void setLock(String lock) {
102         this.lock = lock;
103     }
104
105     /**
106      * 
107      */
108     public JsonLockResponse() {
109         this.status = "";
110         this.error = "";
111     }
112
113     /**
114      * 
115      * @param statusIn
116      * @return
117      */
118     private String fixStatus(String statusIn) {
119         if (statusIn.equalsIgnoreCase("false")) {
120             return "FAILURE";
121         }
122         return "SUCCESS";
123     }
124
125     /**
126      * 
127      * @return
128      */
129     @ApiModelProperty(value = "Overall status of the response.",
130                     allowableValues = "Success,Failure")
131     public String getStatus() {
132         return status;
133     }
134
135     /**
136      * 
137      * @param status
138      */
139     public void setStatus(String status) {
140         this.status = fixStatus(status);
141     }
142
143     /**
144      * 
145      * @return the error
146      */
147     @ApiModelProperty(value = "Error value")
148     public String getError() {
149         return error;
150     }
151
152     /**
153      * 
154      * @param error
155      */
156     public void setError(String error) {
157         this.error = error;
158     }
159
160     /**
161      * 
162      * @return the message
163      */
164     @ApiModelProperty(value = "Message if any need to be conveyed about the lock")
165     public String getMessage() {
166         return message;
167     }
168
169     /**
170      * 
171      * @param message
172      */
173     public void setMessage(String message) {
174         this.message = message;
175     }
176
177     /**
178      * 
179      * @return the lockStatus
180      */
181     @ApiModelProperty(value = "Status of the lock",
182                     allowableValues = "UNLOCKED,BEING_LOCKED,LOCKED")
183     public String getLockStatus() {
184         return lockStatus;
185     }
186
187     /**
188      * 
189      * @param lockStatus
190      */
191     public void setLockStatus(String lockStatus) {
192         this.lockStatus = lockStatus;
193     }
194
195     /**
196      * 
197      * 
198      * @return the lockHolder
199      */
200     @ApiModelProperty(value = "Holder of the Lock")
201     public String getLockHolder() {
202         return lockHolder;
203     }
204
205     /**
206      * 
207      * @param lockHolder
208      */
209     public void setLockHolder(String lockHolder) {
210         this.lockHolder = lockHolder;
211     }
212
213
214
215     /**
216      * @return the lockLease
217      */
218     public String getLockLease() {
219         return lockLease;
220     }
221
222     /**
223      * @param lockLease the lockLease to set
224      */
225     public void setLockLease(String lockLease) {
226         this.lockLease = lockLease;
227     }
228
229     /**
230      * Convert to Map
231      * 
232      * @return
233      */
234     public Map<String, Object> toMap() {
235         Map<String, Object> newMap = new HashMap<>();
236         Map<String, Object> lockMap = new HashMap<>();
237         lockMap.put("lock-status", lockStatus);
238         lockMap.put("lock", lock);
239         lockMap.put("message", message);
240         lockMap.put("lock-holder", lockHolder);
241         lockMap.put("lock-lease", lockLease);
242         newMap.put("status", status);
243         newMap.put("error", error);
244         newMap.put("lock", lockMap);
245         return newMap;
246     }
247
248     /**
249      * Convert to String
250      */
251     @Override
252     public String toString() {
253         return "JsonLockResponse [status=" + status + ", error=" + error + ", message=" + message
254                         + ", lock=" + lock + ", lockStatus=" + lockStatus + ", lockHolder="
255                         + lockHolder + "]";
256     }
257
258 }