2 * ============LICENSE_START==========================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ============LICENSE_END=============================================
20 * ====================================================================
23 package org.onap.music.response.jsonobjects;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
30 import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
31 import org.onap.music.main.ResultType;
34 import io.swagger.annotations.ApiModel;
35 import io.swagger.annotations.ApiModelProperty;
37 @ApiModel(value = "JsonResponse", description = "General Response JSON")
38 public class JsonResponse {
40 /* Status is required */
41 private ResultType status;
43 /* Standard informational fields */
45 private String message;
48 private String musicVersion;
49 private String musicBuild;
52 private Map<String, HashMap<String, Object>> dataResult;
56 private LockStatus lockStatus;
57 private List<String> lockHolders;
58 private String lockLease;
59 private boolean isLockHolders=false;
62 public boolean isLockHolders() {
66 public JsonResponse setisLockHolders(boolean isLockHolders) {
67 this.isLockHolders = isLockHolders;
72 * Create a JSONLock Response
73 * Use setters to provide more information as in
74 * JsonLockResponse(ResultType.SUCCESS).setMessage("We did it").setLock(mylockname)
77 public JsonResponse(ResultType status) {
85 @ApiModelProperty(value = "Overall status of the response.",
86 allowableValues = "Success,Failure")
87 public ResultType getStatus() {
95 public JsonResponse setStatus(ResultType status) {
104 @ApiModelProperty(value = "Error value")
105 public String getError() {
113 public JsonResponse setError(String error) {
120 * @return the message
122 @ApiModelProperty(value = "Message value")
123 public String getMessage() {
131 public JsonResponse setMessage(String message) {
132 this.message = message;
139 * @return the music version
141 public String getMusicVersion() {
142 return this.musicVersion;
147 * @param version of music
150 public JsonResponse setMusicVersion(String version) {
151 this.musicVersion = version;
157 * @return the music version
159 public String getMusicBuild() {
160 return this.musicBuild;
165 * @param build of music
168 public JsonResponse setMusicBuild(String build) {
169 this.musicBuild = build;
174 public Map<String, HashMap<String, Object>> getDataResult() {
175 return this.dataResult;
178 public JsonResponse setDataResult(Map<String, HashMap<String, Object>> map) {
179 this.dataResult = map;
187 public String getLock() {
195 public JsonResponse setLock(String lock) {
202 * @return the lockStatus
204 @ApiModelProperty(value = "Status of the lock")
205 public LockStatus getLockStatus() {
213 public JsonResponse setLockStatus(LockStatus lockStatus) {
214 this.lockStatus = lockStatus;
221 * @return the lockHolder
223 @ApiModelProperty(value = "Holder of the Lock")
224 public List<String> getLockHolder() {
232 public JsonResponse setLockHolder(String lockHolder) {
233 this.lockHolders = new ArrayList<String>();
234 this.lockHolders.add(lockHolder);
238 public JsonResponse setLockHolder(List<String> lockHolders) {
239 this.lockHolders = lockHolders;
245 * @return the lockLease
247 public String getLockLease() {
252 * @param lockLease the lockLease to set
254 public JsonResponse setLockLease(String lockLease) {
255 this.lockLease = lockLease;
264 public Map<String, Object> toMap() {
265 Map<String, Object> fullMap = new HashMap<>();
266 fullMap.put("status", status);
267 if (error != null && !"".equals(error)) {
268 fullMap.put("error", error);
270 if (message != null) {
271 fullMap.put("message", message);
274 if (musicVersion != null) {
275 fullMap.put("version", musicVersion);
278 if (musicBuild != null) {
279 fullMap.put("build", musicBuild);
282 if (dataResult != null) {
283 fullMap.put("result", dataResult);
287 Map<String, Object> lockMap = new HashMap<>();
289 lockMap.put("lock", lock);
291 if (lockStatus != null) {
292 lockMap.put("lock-status", lockStatus);
294 if (lockHolders != null && !lockHolders.isEmpty()) {
295 if (lockHolders.size()==1 && !isLockHolders) {
296 //for backwards compatability
297 lockMap.put("lock-holder", lockHolders.get(0));
299 lockMap.put("lock-holder", lockHolders);
302 if (lockLease != null) {
303 lockMap.put("lock-lease", lockLease);
305 fullMap.put("lock", lockMap);
315 public String toString() {
316 return "JsonLockResponse [status=" + status + ", error=" + error + ", message=" + message
317 + ", lock=" + lock + ", lockStatus=" + lockStatus + ", lockHolder="