2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
7 * Modifications Copyright (C) 2019 IBM.
8 * ===================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=============================================
22 * ====================================================================
25 package org.onap.music.response.jsonobjects;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
32 import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
33 import org.onap.music.main.ResultType;
36 import io.swagger.annotations.ApiModel;
37 import io.swagger.annotations.ApiModelProperty;
39 @ApiModel(value = "JsonResponse", description = "General Response JSON")
40 public class JsonResponse {
42 /* Status is required */
43 private ResultType status;
45 /* Standard informational fields */
47 private String message;
50 private String musicVersion;
51 private String musicBuild;
54 private Map<String, HashMap<String, Object>> dataResult;
58 private LockStatus lockStatus;
59 private List<String> lockHolders;
60 private String lockLease;
61 private boolean isLockHolders=false;
64 * Create a JSONLock Response
65 * Use setters to provide more information as in
66 * JsonLockResponse(ResultType.SUCCESS).setMessage("We did it").setLock(mylockname)
69 public JsonResponse(ResultType status) {
73 public boolean isLockHolders() {
77 public JsonResponse setisLockHolders(boolean isLockHolders) {
78 this.isLockHolders = isLockHolders;
86 @ApiModelProperty(value = "Overall status of the response.",
87 allowableValues = "Success,Failure")
88 public ResultType getStatus() {
96 public JsonResponse setStatus(ResultType status) {
105 @ApiModelProperty(value = "Error value")
106 public String getError() {
114 public JsonResponse setError(String error) {
121 * @return the message
123 @ApiModelProperty(value = "Message value")
124 public String getMessage() {
132 public JsonResponse setMessage(String message) {
133 this.message = message;
140 * @return the music version
142 public String getMusicVersion() {
143 return this.musicVersion;
148 * @param version of music
151 public JsonResponse setMusicVersion(String version) {
152 this.musicVersion = version;
158 * @return the music version
160 public String getMusicBuild() {
161 return this.musicBuild;
166 * @param build of music
169 public JsonResponse setMusicBuild(String build) {
170 this.musicBuild = build;
175 public Map<String, HashMap<String, Object>> getDataResult() {
176 return this.dataResult;
179 public JsonResponse setDataResult(Map<String, HashMap<String, Object>> map) {
180 this.dataResult = map;
188 public String getLock() {
196 public JsonResponse setLock(String lock) {
203 * @return the lockStatus
205 @ApiModelProperty(value = "Status of the lock")
206 public LockStatus getLockStatus() {
214 public JsonResponse setLockStatus(LockStatus lockStatus) {
215 this.lockStatus = lockStatus;
222 * @return the lockHolder
224 @ApiModelProperty(value = "Holder of the Lock")
225 public List<String> getLockHolder() {
233 public JsonResponse setLockHolder(String lockHolder) {
234 this.lockHolders = new ArrayList<String>();
235 this.lockHolders.add(lockHolder);
239 public JsonResponse setLockHolder(List<String> lockHolders) {
240 this.lockHolders = lockHolders;
246 * @return the lockLease
248 public String getLockLease() {
253 * @param lockLease the lockLease to set
255 public JsonResponse setLockLease(String lockLease) {
256 this.lockLease = lockLease;
265 public Map<String, Object> toMap() {
266 Map<String, Object> fullMap = new HashMap<>();
267 fullMap.put("status", status);
268 if (error != null && !"".equals(error)) {
269 fullMap.put("error", error);
271 if (message != null) {
272 fullMap.put("message", message);
275 if (musicVersion != null) {
276 fullMap.put("version", musicVersion);
279 if (musicBuild != null) {
280 fullMap.put("build", musicBuild);
283 if (dataResult != null) {
284 fullMap.put("result", dataResult);
288 Map<String, Object> lockMap = new HashMap<>();
290 lockMap.put("lock", lock);
292 if (lockStatus != null) {
293 lockMap.put("lock-status", lockStatus);
295 if (lockHolders != null && !lockHolders.isEmpty()) {
296 if (lockHolders.size()==1 && !isLockHolders) {
297 //for backwards compatability
298 lockMap.put("lock-holder", lockHolders.get(0));
300 lockMap.put("lock-holder", lockHolders);
303 if (lockLease != null) {
304 lockMap.put("lock-lease", lockLease);
306 fullMap.put("lock", lockMap);
316 public String toString() {
317 return "JsonLockResponse [status=" + status + ", error=" + error + ", message=" + message
318 + ", lock=" + lock + ", lockStatus=" + lockStatus + ", lockHolder="