Docker Updates for CSIT
[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
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 io.swagger.annotations.ApiModel;
32 import io.swagger.annotations.ApiModelProperty;
33
34 @ApiModel(value = "JsonResponse", description = "General Response JSON")
35 public class JsonLockResponse {
36
37     private ResultType status;
38     private String error;
39     private String message;
40     private String lock;
41     private LockStatus lockStatus;
42     private String lockHolder;
43     private String lockLease;
44
45
46     /**
47      * Create a JSONLock Response
48      * Use setters to provide more information as in
49      * JsonLockResponse(ResultType.SUCCESS).setMessage("We did it").setLock(mylockname)
50      * @param status
51      */
52     public JsonLockResponse(ResultType status) {
53         this.status = status;
54     }
55     
56
57
58         /**
59      * 
60      * @return
61      */
62     public String getLock() {
63         return lock;
64     }
65
66     /**
67      * 
68      * @param lock
69      */
70     public JsonLockResponse setLock(String lock) {
71         this.lock = lock;
72         return this;
73     }
74
75     /**
76      * 
77      * @return
78      */
79     @ApiModelProperty(value = "Overall status of the response.",
80                     allowableValues = "Success,Failure")
81     public ResultType getStatus() {
82         return status;
83     }
84
85     /**
86      * 
87      * @param status
88      */
89     public JsonLockResponse setStatus(ResultType status) {
90         this.status = status;
91         return this;
92     }
93
94     /**
95      * 
96      * @return the error
97      */
98     @ApiModelProperty(value = "Error value")
99     public String getError() {
100         return error;
101     }
102
103     /**
104      * 
105      * @param error
106      */
107     public JsonLockResponse setError(String error) {
108         this.error = error;
109         return this;
110     }
111
112     /**
113      * 
114      * @return the message
115      */
116     @ApiModelProperty(value = "Message if any need to be conveyed about the lock")
117     public String getMessage() {
118         return message;
119     }
120
121     /**
122      * 
123      * @param message
124      */
125     public JsonLockResponse setMessage(String message) {
126         this.message = message;
127         return this;
128     }
129
130     /**
131      * 
132      * @return the lockStatus
133      */
134     @ApiModelProperty(value = "Status of the lock")
135     public LockStatus getLockStatus() {
136         return lockStatus;
137     }
138
139     /**
140      * 
141      * @param lockStatus
142      */
143     public JsonLockResponse setLockStatus(LockStatus lockStatus) {
144         this.lockStatus = lockStatus;
145         return this;
146     }
147
148     /**
149      * 
150      * 
151      * @return the lockHolder
152      */
153     @ApiModelProperty(value = "Holder of the Lock")
154     public String getLockHolder() {
155         return lockHolder;
156     }
157
158     /**
159      * 
160      * @param lockHolder
161      */
162     public JsonLockResponse setLockHolder(String lockHolder) {
163         this.lockHolder = lockHolder;
164         return this;
165     }
166
167
168
169     /**
170      * @return the lockLease
171      */
172     public String getLockLease() {
173         return lockLease;
174     }
175
176     /**
177      * @param lockLease the lockLease to set
178      */
179     public JsonLockResponse setLockLease(String lockLease) {
180         this.lockLease = lockLease;
181         return this;
182     }
183
184     /**
185      * Convert to Map
186      * 
187      * @return
188      */
189     public Map<String, Object> toMap() {
190         Map<String, Object> fullMap = new HashMap<>();
191         Map<String, Object> lockMap = new HashMap<>();
192         if (lockStatus!=null) {lockMap.put("lock-status", lockStatus); }
193         if (lock!=null) {lockMap.put("lock", lock);}
194         if (message!=null) {lockMap.put("message", message);}
195         if (lockHolder!=null) {lockMap.put("lock-holder", lockHolder);}
196         if (lockLease!=null) {lockMap.put("lock-lease", lockLease);}
197         
198         fullMap.put("status", status);
199         fullMap.put("lock", lockMap);
200         if (error!=null) {fullMap.put("error", error);}
201         return fullMap;
202     }
203
204     /**
205      * Convert to String
206      */
207     @Override
208     public String toString() {
209         return "JsonLockResponse [status=" + status + ", error=" + error + ", message=" + message
210                         + ", lock=" + lock + ", lockStatus=" + lockStatus + ", lockHolder="
211                         + lockHolder + "]";
212     }
213
214 }