b890114b501ffbb46e63c863451960b181451607
[vid.git] / vid-app-common / src / main / java / org / onap / vid / mso / MsoResponseWrapper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.mso;
22
23 import com.fasterxml.jackson.annotation.JsonInclude;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
26 import org.apache.commons.lang.builder.ToStringBuilder;
27
28 import javax.ws.rs.core.Response;
29
30 /**
31  * This wrapper encapsulates the MSO response in the format expected by the pages.
32  */
33 @JsonInclude(JsonInclude.Include.NON_NULL)
34 @JsonPropertyOrder({
35             "status",
36             "entity"
37 })
38
39 public class MsoResponseWrapper implements MsoResponseWrapperInterface {
40
41
42     public MsoResponseWrapper() {
43     }
44
45     public MsoResponseWrapper(Response response) {
46         setEntity(response.readEntity(String.class));
47         setStatus(response.getStatus());
48     }
49
50
51     /** The status. */
52         @JsonProperty("status")
53         private int status;
54         
55         /** The entity. */
56         @JsonProperty("entity")
57         private String entity;
58
59         /**
60          * Gets the entity.
61          *
62          * @return the entity
63          */
64         @Override
65         @JsonProperty("entity")
66     public String getEntity() {
67         return entity;
68     }
69
70         /**
71          * Gets the status.
72          *
73          * @return the status
74          */
75         @Override
76         @JsonProperty("status")
77     public int getStatus() {
78         return status;
79     }
80         
81         /**
82          * Sets the status.
83          *
84          * @param v the new status
85          */
86         @JsonProperty("status")
87     public void setStatus(int v) {
88         this.status = v;
89     }
90         
91         /**
92          * Sets the entity.
93          *
94          * @param v the new entity
95          */
96         @JsonProperty("entity")
97     public void setEntity(String v) {
98         this.entity = v;
99     }
100     
101     /* (non-Javadoc)
102      * @see java.lang.Object#toString()
103      */
104     @Override
105     public String toString() {
106         return ToStringBuilder.reflectionToString(this);
107     }
108     
109     /**
110      * Gets the response.
111      *
112      * @return the response
113      */
114     @org.codehaus.jackson.annotate.JsonIgnore
115     @com.fasterxml.jackson.annotation.JsonIgnore
116     public String getResponse () {
117         
118         StringBuilder b = new StringBuilder ("{ \"status\": ");
119         b.append(getStatus()).append(", \"entity\": " );
120         if (this.getEntity() == null || this.getEntity().isEmpty()) {
121                 b.append("\"\"");
122                 } else {
123                         b.append(this.getEntity());
124                 }
125         b.append("}");
126         return (b.toString());
127     }
128     
129 }