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