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.HashMap;
28 import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
29 import org.onap.music.main.ResultType;
32 import io.swagger.annotations.ApiModel;
33 import io.swagger.annotations.ApiModelProperty;
35 @ApiModel(value = "JsonResponse", description = "General Response JSON")
36 public class JsonResponse {
38 /* Status is required */
39 private ResultType status;
41 /* Standard informational fields */
43 private String message;
46 private String musicVersion;
49 private Map<String, HashMap<String, Object>> dataResult;
53 private LockStatus lockStatus;
54 private String lockHolder;
55 private String lockLease;
59 * Create a JSONLock Response
60 * Use setters to provide more information as in
61 * JsonLockResponse(ResultType.SUCCESS).setMessage("We did it").setLock(mylockname)
64 public JsonResponse(ResultType status) {
72 @ApiModelProperty(value = "Overall status of the response.",
73 allowableValues = "Success,Failure")
74 public ResultType getStatus() {
82 public JsonResponse setStatus(ResultType status) {
91 @ApiModelProperty(value = "Error value")
92 public String getError() {
100 public JsonResponse setError(String error) {
107 * @return the message
109 @ApiModelProperty(value = "Message value")
110 public String getMessage() {
118 public JsonResponse setMessage(String message) {
119 this.message = message;
126 * @return the music version
128 public String getMusicVersion() {
129 return this.musicVersion;
134 * @param version of music
137 public JsonResponse setMusicVersion(String version) {
138 this.musicVersion = version;
142 public Map<String, HashMap<String, Object>> getDataResult() {
143 return this.dataResult;
146 public JsonResponse setDataResult(Map<String, HashMap<String, Object>> map) {
147 this.dataResult = map;
155 public String getLock() {
163 public JsonResponse setLock(String lock) {
170 * @return the lockStatus
172 @ApiModelProperty(value = "Status of the lock")
173 public LockStatus getLockStatus() {
181 public JsonResponse setLockStatus(LockStatus lockStatus) {
182 this.lockStatus = lockStatus;
189 * @return the lockHolder
191 @ApiModelProperty(value = "Holder of the Lock")
192 public String getLockHolder() {
200 public JsonResponse setLockHolder(String lockHolder) {
201 this.lockHolder = lockHolder;
208 * @return the lockLease
210 public String getLockLease() {
215 * @param lockLease the lockLease to set
217 public JsonResponse setLockLease(String lockLease) {
218 this.lockLease = lockLease;
227 public Map<String, Object> toMap() {
228 Map<String, Object> fullMap = new HashMap<>();
229 fullMap.put("status", status);
232 fullMap.put("error", error);
235 fullMap.put("message", message);
238 if (error!=null && !"".equals(error)) {fullMap.put("error", error);}
239 if (message!=null) {fullMap.put("message", message);}
241 if (musicVersion!=null) {
242 fullMap.put("version", musicVersion);
245 if (dataResult!=null) {
246 fullMap.put("result", dataResult);
250 Map<String, Object> lockMap = new HashMap<>();
252 lockMap.put("lock", lock);
254 if (lockStatus!=null) {
255 lockMap.put("lock-status", lockStatus);
257 if (lockHolder!=null) {
258 lockMap.put("lock-holder", lockHolder);
260 if (lockLease!=null) {
261 lockMap.put("lock-lease", lockLease);
263 fullMap.put("lock", lockMap);
273 public String toString() {
274 return "JsonLockResponse [status=" + status + ", error=" + error + ", message=" + message
275 + ", lock=" + lock + ", lockStatus=" + lockStatus + ", lockHolder="