Some bug fixes and Minor Chages.
[music.git] / src / main / java / org / onap / music / response / jsonobjects / JsonResponse.java
index 207911d..f0793dc 100644 (file)
  * ============LICENSE_END=============================================
  * ====================================================================
  */
+
 package org.onap.music.response.jsonobjects;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
+import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
 import org.onap.music.main.ResultType;
 
 
@@ -34,7 +37,7 @@ import io.swagger.annotations.ApiModelProperty;
 @ApiModel(value = "JsonResponse", description = "General Response JSON")
 public class JsonResponse {
 
-       /* Status is required */
+    /* Status is required */
     private ResultType status;
     
     /* Standard informational fields */
@@ -43,6 +46,7 @@ public class JsonResponse {
     
     /* versioning */
     private String musicVersion;
+    private String musicBuild;
     
     /* Data Fields */
     private Map<String, HashMap<String, Object>> dataResult;
@@ -50,11 +54,21 @@ public class JsonResponse {
     /* Locking fields */
     private String lock;
     private LockStatus lockStatus;
-    private String lockHolder;
+    private List<String> lockHolders;
     private String lockLease;
+    private boolean isLockHolders=false;
 
 
-    /**
+    public boolean isLockHolders() {
+               return isLockHolders;
+       }
+
+       public JsonResponse setisLockHolders(boolean isLockHolders) {
+               this.isLockHolders = isLockHolders;
+               return this;
+       }
+
+       /**
      * Create a JSONLock Response
      * Use setters to provide more information as in
      * JsonLockResponse(ResultType.SUCCESS).setMessage("We did it").setLock(mylockname)
@@ -64,7 +78,7 @@ public class JsonResponse {
         this.status = status;
     }
 
-       /**
+    /**
      * 
      * @return
      */
@@ -121,33 +135,52 @@ public class JsonResponse {
     
     
     /**
-     * 
+     * .
      * @return the music version
      */
     public String getMusicVersion() {
-       return this.musicVersion;
+        return this.musicVersion;
     }
     
     /**
-     * 
+     * .
      * @param version of music
      * @return
      */
     public JsonResponse setMusicVersion(String version) {
-       this.musicVersion = version;
-       return this;
+        this.musicVersion = version;
+        return this;
+    }
+
+    /**
+     * .
+     * @return the music version
+     */
+    public String getMusicBuild() {
+        return this.musicBuild;
     }
+    
+    /**
+     * .
+     * @param build of music
+     * @return
+     */
+    public JsonResponse setMusicBuild(String build) {
+        this.musicBuild = build;
+        return this;
+    }
+
 
     public Map<String, HashMap<String, Object>> getDataResult() {
-       return this.dataResult;
+        return this.dataResult;
     }
     
     public JsonResponse setDataResult(Map<String, HashMap<String, Object>> map) {
-       this.dataResult = map;
-       return this;
+        this.dataResult = map;
+        return this;
     }
 
-       /**
+    /**
      * 
      * @return
      */
@@ -188,8 +221,8 @@ public class JsonResponse {
      * @return the lockHolder
      */
     @ApiModelProperty(value = "Holder of the Lock")
-    public String getLockHolder() {
-        return lockHolder;
+    public List<String> getLockHolder() {
+        return lockHolders;
     }
 
     /**
@@ -197,10 +230,15 @@ public class JsonResponse {
      * @param lockHolder
      */
     public JsonResponse setLockHolder(String lockHolder) {
-        this.lockHolder = lockHolder;
+        this.lockHolders = new ArrayList<String>();
+        this.lockHolders.add(lockHolder);
         return this;
     }
 
+    public JsonResponse setLockHolder(List<String> lockHolders) {
+        this.lockHolders = lockHolders;
+        return this;
+    }
 
 
     /**
@@ -226,36 +264,45 @@ public class JsonResponse {
     public Map<String, Object> toMap() {
         Map<String, Object> fullMap = new HashMap<>();
         fullMap.put("status", status);
-        if (error!=null) {
-            fullMap.put("error", error);
+        if (error != null && !"".equals(error)) { 
+            fullMap.put("error", error); 
         }
-        if (message!=null) {
-            fullMap.put("message", message);
+        if (message != null) { 
+            fullMap.put("message", message); 
         }
         
-        if (musicVersion!=null) {
+        if (musicVersion != null) {
             fullMap.put("version", musicVersion);
         }
         
-        if (dataResult!=null) {
-               fullMap.put("result", dataResult);
+        if (musicBuild != null) {
+            fullMap.put("build", musicBuild);
+        }
+    
+        if (dataResult != null) {
+            fullMap.put("result", dataResult);
         }
         
-        if (lock!=null) {
-               Map<String, Object> lockMap = new HashMap<>();
-               if (lock!=null) {
-                   lockMap.put("lock", lock);
-               }
-               if (lockStatus!=null) {
-                   lockMap.put("lock-status", lockStatus);
-               }
-               if (lockHolder!=null) {
-                   lockMap.put("lock-holder", lockHolder);
-               }
-               if (lockLease!=null) {
-                   lockMap.put("lock-lease", lockLease);
-               }
-               fullMap.put("lock", lockMap);
+        if (lock != null) {
+            Map<String, Object> lockMap = new HashMap<>();
+            if (lock != null) {
+                lockMap.put("lock", lock);
+            }
+            if (lockStatus != null) {
+                lockMap.put("lock-status", lockStatus);
+            }
+            if (lockHolders != null && !lockHolders.isEmpty()) {
+                if (lockHolders.size()==1 && !isLockHolders) {
+                    //for backwards compatability
+                    lockMap.put("lock-holder", lockHolders.get(0));
+                } else {
+                    lockMap.put("lock-holder", lockHolders);
+                }
+            }
+            if (lockLease != null) {
+                lockMap.put("lock-lease", lockLease);
+            }
+            fullMap.put("lock", lockMap);
         }
 
         return fullMap;
@@ -268,7 +315,7 @@ public class JsonResponse {
     public String toString() {
         return "JsonLockResponse [status=" + status + ", error=" + error + ", message=" + message
                         + ", lock=" + lock + ", lockStatus=" + lockStatus + ", lockHolder="
-                        + lockHolder + "]";
+                        + lockHolders + "]";
     }
 
 }