Update the license for 2017-2018 license
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / rest / db / DBRequest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 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 package org.onap.aai.rest.db;
21
22 import java.net.URI;
23 import java.util.Optional;
24
25 import javax.ws.rs.core.HttpHeaders;
26 import javax.ws.rs.core.UriInfo;
27
28 import org.onap.aai.introspection.Introspector;
29 import org.onap.aai.introspection.MarshallerProperties;
30 import org.onap.aai.parsers.query.QueryParser;
31 import org.onap.aai.restcore.HttpMethod;
32
33 /**
34  * The Class DBRequest.
35  */
36 public class DBRequest {
37
38         private final QueryParser parser;
39         
40         private final Introspector introspector;
41         
42         private final HttpHeaders headers;
43         
44         private final String transactionId;
45         
46         private final UriInfo info;
47         
48         private final HttpMethod method;
49         
50         private final URI uri;
51         
52         private final Optional<String> rawRequestContent;
53         
54         private final Optional<MarshallerProperties> marshallerProperties;
55
56         
57         /**
58          * Instantiates a new DB request.
59          *
60          * @param method the method
61          * @param uri the uri
62          * @param parser the parser
63          * @param obj the obj
64          * @param headers the headers
65          * @param info the info
66          * @param transactionId the transaction id
67          */
68         private DBRequest(Builder builder) {
69                 this.method = builder.getMethod();
70                 this.parser = builder.getParser();
71                 this.introspector = builder.getIntrospector();
72                 this.headers = builder.getHeaders();
73                 this.transactionId = builder.getTransactionId();
74                 this.info = builder.getInfo();
75                 this.uri = builder.getUri();
76                 this.marshallerProperties = builder.getMarshallerProperties();
77                 this.rawRequestContent = builder.getRawRequestContent();
78         }
79         
80         /**
81          * Gets the headers.
82          *
83          * @return the headers
84          */
85         public HttpHeaders getHeaders() {
86                 return headers;
87         }
88         
89         
90         /**
91          * Gets the transaction id.
92          *
93          * @return the transaction id
94          */
95         public String getTransactionId() {
96                 return transactionId;
97         }
98         
99         /**
100          * Gets the info.
101          *
102          * @return the info
103          */
104         public UriInfo getInfo() {
105                 return info;
106         }
107         
108         /**
109          * Gets the parser.
110          *
111          * @return the parser
112          */
113         public QueryParser getParser() {
114                 return parser;
115         }
116
117         /**
118          * Gets the introspector.
119          *
120          * @return the introspector
121          */
122         public Introspector getIntrospector() {
123                 return introspector;
124         }
125
126         /**
127          * Gets the method.
128          *
129          * @return the method
130          */
131         public HttpMethod getMethod() {
132                 return method;
133         }
134
135         /**
136          * Gets the uri.
137          *
138          * @return the uri
139          */
140         public URI getUri() {
141                 return uri;
142         }
143         
144         /**
145          * Gets the raw content.
146          *
147          * @return the raw content
148          */
149         public Optional<String> getRawRequestContent() {
150                 return rawRequestContent;
151         }
152         
153         public Optional<MarshallerProperties> getMarshallerProperties() {
154                 return marshallerProperties;
155         }
156
157
158
159         public static class Builder {
160
161                 private QueryParser parser = null;
162                 
163                 private Introspector introspector = null;
164                 
165                 private HttpHeaders headers = null;
166                 
167                 private String transactionId = null;
168                 
169                 private UriInfo info = null;
170                 
171                 private HttpMethod method = null;
172                 
173                 private URI uri = null;
174                                 
175                 private Optional<MarshallerProperties> marshallerProperties = Optional.empty();
176                 
177                 private Optional<String> rawRequestContent = Optional.empty();
178                 /**
179                  * Instantiates a new DB request.
180                  *
181                  * @param method the method
182                  * @param uri the uri
183                  * @param parser the parser
184                  * @param obj the obj
185                  * @param headers the headers
186                  * @param info the info
187                  * @param transactionId the transaction id
188                  */
189                 public Builder(HttpMethod method, URI uri, QueryParser parser, Introspector obj, HttpHeaders headers, UriInfo info, String transactionId) {
190                         this.method = method;
191                         this.parser = parser;
192                         this.introspector = obj;
193                         this.headers = headers;
194                         this.transactionId = transactionId;
195                         this.info = info;
196                         this.uri = uri;
197                         
198                 }
199
200                 public QueryParser getParser() {
201                         return parser;
202                 }
203
204                 public Introspector getIntrospector() {
205                         return introspector;
206                 }
207
208                 public HttpHeaders getHeaders() {
209                         return headers;
210                 }
211
212                 public String getTransactionId() {
213                         return transactionId;
214                 }
215
216                 public UriInfo getInfo() {
217                         return info;
218                 }
219
220                 public HttpMethod getMethod() {
221                         return method;
222                 }
223
224                 public URI getUri() {
225                         return uri;
226                 }
227                 
228                 public Builder customMarshaller(MarshallerProperties properties) {
229                         this.marshallerProperties = Optional.of(properties);
230                         return this;
231                 }
232                 
233                 public Builder rawRequestContent(String content) {
234                         this.rawRequestContent = Optional.of(content);
235                         return this;
236                 }
237                 protected Optional<MarshallerProperties> getMarshallerProperties() {
238                         return marshallerProperties;
239                 }
240                 protected Optional<String> getRawRequestContent() {
241                         return rawRequestContent;
242                 }
243                 public DBRequest build() {
244                         
245                         return new DBRequest(this);
246                 }
247                 
248                 
249         }
250 }