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