blob: 1723c444c95d7cec0c9306f71803f583ebfc2d21 [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
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
22
23package org.onap.osam.mso;
24
25import com.fasterxml.jackson.annotation.JsonIgnore;
26import com.fasterxml.jackson.annotation.JsonInclude;
27import com.fasterxml.jackson.annotation.JsonProperty;
28import com.fasterxml.jackson.annotation.JsonPropertyOrder;
29import org.apache.commons.lang.builder.ToStringBuilder;
30
31import javax.ws.rs.core.Response;
32
33@JsonInclude(JsonInclude.Include.NON_NULL)
34@JsonPropertyOrder({
35 "status",
36 "entity"
37})
38
39public 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 @JsonProperty("status")
52 private int status;
53
54 /** The entity. */
55 @JsonProperty("entity")
56 private String entity;
57
58 /**
59 * Gets the entity.
60 *
61 * @return the entity
62 */
63 @Override
64 @JsonProperty("entity")
65 public String getEntity() {
66 return entity;
67 }
68
69 /**
70 * Gets the status.
71 *
72 * @return the status
73 */
74 @Override
75 @JsonProperty("status")
76 public int getStatus() {
77 return status;
78 }
79
80 /**
81 * Sets the status.
82 *
83 * @param v the new status
84 */
85 @JsonProperty("status")
86 public void setStatus(int v) {
87 this.status = v;
88 }
89
90 /**
91 * Sets the entity.
92 *
93 * @param v the new entity
94 */
95 @JsonProperty("entity")
96 public void setEntity(String v) {
97 this.entity = v;
98 }
99
100 /* (non-Javadoc)
101 * @see java.lang.Object#toString()
102 */
103 @Override
104 public String toString() {
105 return ToStringBuilder.reflectionToString(this);
106 }
107
108 /**
109 * Gets the response.
110 *
111 * @return the response
112 */
113 @JsonIgnore
114 public String getResponse () {
115
116 StringBuilder b = new StringBuilder ("{ \"status\": ");
117 b.append(getStatus()).append(", \"entity\": " );
118 if (this.getEntity() == null || this.getEntity().isEmpty()) {
119 b.append("\"\"");
120 } else {
121 b.append(this.getEntity());
122 }
123 b.append("}");
124 return (b.toString());
125 }
126
127}