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;
47 private String musicBuild;
50 private Map<String, HashMap<String, Object>> dataResult;
54 private LockStatus lockStatus;
55 private String lockHolder;
56 private String lockLease;
60 * Create a JSONLock Response
61 * Use setters to provide more information as in
62 * JsonLockResponse(ResultType.SUCCESS).setMessage("We did it").setLock(mylockname)
65 public JsonResponse(ResultType status) {
73 @ApiModelProperty(value = "Overall status of the response.",
74 allowableValues = "Success,Failure")
75 public ResultType getStatus() {
83 public JsonResponse setStatus(ResultType status) {
92 @ApiModelProperty(value = "Error value")
93 public String getError() {
101 public JsonResponse setError(String error) {
108 * @return the message
110 @ApiModelProperty(value = "Message value")
111 public String getMessage() {
119 public JsonResponse setMessage(String message) {
120 this.message = message;
127 * @return the music version
129 public String getMusicVersion() {
130 return this.musicVersion;
135 * @param version of music
138 public JsonResponse setMusicVersion(String version) {
139 this.musicVersion = version;
145 * @return the music version
147 public String getMusicBuild() {
148 return this.musicBuild;
153 * @param build of music
156 public JsonResponse setMusicBuild(String build) {
157 this.musicBuild = build;
162 public Map<String, HashMap<String, Object>> getDataResult() {
163 return this.dataResult;
166 public JsonResponse setDataResult(Map<String, HashMap<String, Object>> map) {
167 this.dataResult = map;
175 public String getLock() {
183 public JsonResponse setLock(String lock) {
190 * @return the lockStatus
192 @ApiModelProperty(value = "Status of the lock")
193 public LockStatus getLockStatus() {
201 public JsonResponse setLockStatus(LockStatus lockStatus) {
202 this.lockStatus = lockStatus;
209 * @return the lockHolder
211 @ApiModelProperty(value = "Holder of the Lock")
212 public String getLockHolder() {
220 public JsonResponse setLockHolder(String lockHolder) {
221 this.lockHolder = lockHolder;
228 * @return the lockLease
230 public String getLockLease() {
235 * @param lockLease the lockLease to set
237 public JsonResponse setLockLease(String lockLease) {
238 this.lockLease = lockLease;
247 public Map<String, Object> toMap() {
248 Map<String, Object> fullMap = new HashMap<>();
249 fullMap.put("status", status);
250 if (error != null && !"".equals(error)) {
251 fullMap.put("error", error);
253 if (message != null) {
254 fullMap.put("message", message);
257 if (musicVersion != null) {
258 fullMap.put("version", musicVersion);
261 if (musicBuild != null) {
262 fullMap.put("build", musicBuild);
265 if (dataResult != null) {
266 fullMap.put("result", dataResult);
270 Map<String, Object> lockMap = new HashMap<>();
272 lockMap.put("lock", lock);
274 if (lockStatus != null) {
275 lockMap.put("lock-status", lockStatus);
277 if (lockHolder != null) {
278 lockMap.put("lock-holder", lockHolder);
280 if (lockLease != null) {
281 lockMap.put("lock-lease", lockLease);
283 fullMap.put("lock", lockMap);
293 public String toString() {
294 return "JsonLockResponse [status=" + status + ", error=" + error + ", message=" + message
295 + ", lock=" + lock + ", lockStatus=" + lockStatus + ", lockHolder="