d44f9fe725ba41c636b485e840e5d6aa33141d87
[music.git] / src / main / java / org / onap / music / response / jsonobjects / JsonResponse.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
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
10  * 
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  * 
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.
18  * 
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22 package org.onap.music.response.jsonobjects;
23
24
25 import java.util.HashMap;
26 import java.util.Map;
27 import io.swagger.annotations.ApiModel;
28 import io.swagger.annotations.ApiModelProperty;
29
30 @ApiModel(value = "JsonResponse", description = "General Response JSON")
31 public class JsonResponse {
32
33     private Boolean status = false;
34     private String error = "";
35     private String version = "";
36
37     public JsonResponse(Boolean status, String error, String version) {
38         this.status = status;
39         this.error = error;
40         this.version = version;
41     }
42
43     public JsonResponse() {
44         this.status = false;
45         this.error = "";
46         this.version = "";
47     }
48
49     @ApiModelProperty(value = "Status value")
50     public Boolean getStatus() {
51         return status;
52     }
53
54     /**
55      * 
56      * @param statusIn
57      * @return
58      */
59     private String fixStatus(String statusIn) {
60         if (statusIn.equalsIgnoreCase("false")) {
61             return "FAILURE";
62         }
63         return "SUCCESS";
64     }
65
66     public void setStatus(Boolean status) {
67         this.status = status;
68     }
69
70     @ApiModelProperty(value = "Error value")
71     public String getError() {
72         return error;
73     }
74
75     public void setError(String error) {
76         this.error = error;
77     }
78
79     @ApiModelProperty(value = "Version value")
80     public String getVersion() {
81         return version;
82     }
83
84     public void setVersion(String version) {
85         this.version = version;
86     }
87
88     public Map<String, Object> toMap() {
89         Map<String, Object> newMap = new HashMap<>();
90         newMap.put("status", fixStatus(String.valueOf(status)));
91         newMap.put("error", error);
92         newMap.put("version", version);
93         return newMap;
94     }
95 }