12f526fbe0d6328878b1805ed9901da0c1f5af45
[policy/models.git] / models-interactions / model-actors / actor.so / src / main / java / org / onap / policy / controlloop / actor / so / RestManagerResponse.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020-2021 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.policy.controlloop.actor.so;
22
23 import java.lang.annotation.Annotation;
24 import java.net.URI;
25 import java.util.Date;
26 import java.util.Locale;
27 import java.util.Map;
28 import java.util.Set;
29 import javax.ws.rs.core.EntityTag;
30 import javax.ws.rs.core.GenericType;
31 import javax.ws.rs.core.Link;
32 import javax.ws.rs.core.Link.Builder;
33 import javax.ws.rs.core.MediaType;
34 import javax.ws.rs.core.MultivaluedMap;
35 import javax.ws.rs.core.NewCookie;
36 import javax.ws.rs.core.Response;
37 import lombok.AllArgsConstructor;
38 import lombok.Getter;
39 import org.onap.policy.common.utils.coder.Coder;
40 import org.onap.policy.common.utils.coder.CoderException;
41
42 /**
43  * RestManager Response suitable for use with subclasses of HttpOperation. Only a couple
44  * of methods are implemented; the rest throw {@link UnsupportedOperationException}.
45  */
46 @AllArgsConstructor
47 public class RestManagerResponse extends Response {
48     // TODO move to actorServices
49
50     @Getter
51     private final int status;
52
53     private final String body;
54     private final Coder coder;
55
56     @Override
57     public void close() {
58         // do nothing
59     }
60
61     @Override
62     public <T> T readEntity(Class<T> entityType) {
63         if (entityType == String.class) {
64             return entityType.cast(body);
65         }
66
67         try {
68             return coder.decode(body, entityType);
69         } catch (CoderException e) {
70             throw new IllegalArgumentException("cannot decode response", e);
71         }
72     }
73
74     @Override
75     public <T> T readEntity(GenericType<T> entityType) {
76         throw new UnsupportedOperationException();
77     }
78
79     @Override
80     public <T> T readEntity(Class<T> entityType, Annotation[] annotations) {
81         throw new UnsupportedOperationException();
82     }
83
84     @Override
85     public <T> T readEntity(GenericType<T> entityType, Annotation[] annotations) {
86         throw new UnsupportedOperationException();
87     }
88
89     @Override
90     public StatusType getStatusInfo() {
91         throw new UnsupportedOperationException();
92     }
93
94     @Override
95     public Object getEntity() {
96         throw new UnsupportedOperationException();
97     }
98
99     @Override
100     public boolean hasEntity() {
101         throw new UnsupportedOperationException();
102     }
103
104     @Override
105     public boolean bufferEntity() {
106         throw new UnsupportedOperationException();
107     }
108
109     @Override
110     public MediaType getMediaType() {
111         throw new UnsupportedOperationException();
112     }
113
114     @Override
115     public Locale getLanguage() {
116         throw new UnsupportedOperationException();
117     }
118
119     @Override
120     public int getLength() {
121         throw new UnsupportedOperationException();
122     }
123
124     @Override
125     public Set<String> getAllowedMethods() {
126         throw new UnsupportedOperationException();
127     }
128
129     @Override
130     public Map<String, NewCookie> getCookies() {
131         throw new UnsupportedOperationException();
132     }
133
134     @Override
135     public EntityTag getEntityTag() {
136         throw new UnsupportedOperationException();
137     }
138
139     @Override
140     public Date getDate() {
141         throw new UnsupportedOperationException();
142     }
143
144     @Override
145     public Date getLastModified() {
146         throw new UnsupportedOperationException();
147     }
148
149     @Override
150     public URI getLocation() {
151         throw new UnsupportedOperationException();
152     }
153
154     @Override
155     public Set<Link> getLinks() {
156         throw new UnsupportedOperationException();
157     }
158
159     @Override
160     public boolean hasLink(String relation) {
161         throw new UnsupportedOperationException();
162     }
163
164     @Override
165     public Link getLink(String relation) {
166         throw new UnsupportedOperationException();
167     }
168
169     @Override
170     public Builder getLinkBuilder(String relation) {
171         throw new UnsupportedOperationException();
172     }
173
174     @Override
175     public MultivaluedMap<String, Object> getMetadata() {
176         throw new UnsupportedOperationException();
177     }
178
179     @Override
180     public MultivaluedMap<String, String> getStringHeaders() {
181         throw new UnsupportedOperationException();
182     }
183
184     @Override
185     public String getHeaderString(String name) {
186         throw new UnsupportedOperationException();
187     }
188 }