Merge from ECOMP's repository
[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
52     /** The status. */
53         @JsonProperty("status")
54         private int status;
55         
56         /** The entity. */
57         @JsonProperty("entity")
58         private String entity;
59
60         /**
61          * Gets the entity.
62          *
63          * @return the entity
64          */
65         @Override
66         @JsonProperty("entity")
67     public String getEntity() {
68         return entity;
69     }
70
71         /**
72          * Gets the status.
73          *
74          * @return the status
75          */
76         @Override
77         @JsonProperty("status")
78     public int getStatus() {
79         return status;
80     }
81         
82         /**
83          * Sets the status.
84          *
85          * @param v the new status
86          */
87         @JsonProperty("status")
88     public void setStatus(int v) {
89         this.status = v;
90     }
91         
92         /**
93          * Sets the entity.
94          *
95          * @param v the new entity
96          */
97         @JsonProperty("entity")
98     public void setEntity(String v) {
99         this.entity = v;
100     }
101     
102     /* (non-Javadoc)
103      * @see java.lang.Object#toString()
104      */
105     @Override
106     public String toString() {
107         return ToStringBuilder.reflectionToString(this);
108     }
109     
110     /**
111      * Gets the response.
112      *
113      * @return the response
114      */
115     @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 }