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;
62 * Create a JSONLock Response
63 * Use setters to provide more information as in
64 * JsonLockResponse(ResultType.SUCCESS).setMessage("We did it").setLock(mylockname)
67 public JsonResponse(ResultType status) {
75 @ApiModelProperty(value = "Overall status of the response.",
76 allowableValues = "Success,Failure")
77 public ResultType getStatus() {
85 public JsonResponse setStatus(ResultType status) {
94 @ApiModelProperty(value = "Error value")
95 public String getError() {
103 public JsonResponse setError(String error) {
110 * @return the message
112 @ApiModelProperty(value = "Message value")
113 public String getMessage() {
121 public JsonResponse setMessage(String message) {
122 this.message = message;
129 * @return the music version
131 public String getMusicVersion() {
132 return this.musicVersion;
137 * @param version of music
140 public JsonResponse setMusicVersion(String version) {
141 this.musicVersion = version;
147 * @return the music version
149 public String getMusicBuild() {
150 return this.musicBuild;
155 * @param build of music
158 public JsonResponse setMusicBuild(String build) {
159 this.musicBuild = build;
164 public Map<String, HashMap<String, Object>> getDataResult() {
165 return this.dataResult;
168 public JsonResponse setDataResult(Map<String, HashMap<String, Object>> map) {
169 this.dataResult = map;
177 public String getLock() {
185 public JsonResponse setLock(String lock) {
192 * @return the lockStatus
194 @ApiModelProperty(value = "Status of the lock")
195 public LockStatus getLockStatus() {
203 public JsonResponse setLockStatus(LockStatus lockStatus) {
204 this.lockStatus = lockStatus;
211 * @return the lockHolder
213 @ApiModelProperty(value = "Holder of the Lock")
214 public List<String> getLockHolder() {
222 public JsonResponse setLockHolder(String lockHolder) {
223 this.lockHolders = new ArrayList<String>();
224 this.lockHolders.add(lockHolder);
228 public JsonResponse setLockHolder(List<String> lockHolders) {
229 this.lockHolders = lockHolders;
235 * @return the lockLease
237 public String getLockLease() {
242 * @param lockLease the lockLease to set
244 public JsonResponse setLockLease(String lockLease) {
245 this.lockLease = lockLease;
254 public Map<String, Object> toMap() {
255 Map<String, Object> fullMap = new HashMap<>();
256 fullMap.put("status", status);
257 if (error != null && !"".equals(error)) {
258 fullMap.put("error", error);
260 if (message != null) {
261 fullMap.put("message", message);
264 if (musicVersion != null) {
265 fullMap.put("version", musicVersion);
268 if (musicBuild != null) {
269 fullMap.put("build", musicBuild);
272 if (dataResult != null) {
273 fullMap.put("result", dataResult);
277 Map<String, Object> lockMap = new HashMap<>();
279 lockMap.put("lock", lock);
281 if (lockStatus != null) {
282 lockMap.put("lock-status", lockStatus);
284 if (lockHolders != null && !lockHolders.isEmpty()) {
285 if (lockHolders.size()==1) {
286 //for backwards compatability
287 lockMap.put("lock-holder", lockHolders.get(0));
289 lockMap.put("lock-holder", lockHolders);
292 if (lockLease != null) {
293 lockMap.put("lock-lease", lockLease);
295 fullMap.put("lock", lockMap);
305 public String toString() {
306 return "JsonLockResponse [status=" + status + ", error=" + error + ", message=" + message
307 + ", lock=" + lock + ", lockStatus=" + lockStatus + ", lockHolder="