Enhancements for the aai-common library
[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
21 package org.onap.aai.rest.db;
22
23 import java.net.URI;
24 import java.util.Optional;
25
26 import javax.ws.rs.core.HttpHeaders;
27 import javax.ws.rs.core.UriInfo;
28
29 import org.onap.aai.aailog.logs.DBRequestWrapper;
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 implements DBRequestWrapper {
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      * Instantiates a new DB request.
60      *
61      * @param method the method
62      * @param uri the uri
63      * @param parser the parser
64      * @param obj the obj
65      * @param headers the headers
66      * @param info the info
67      * @param transactionId the transaction id
68      */
69     private DBRequest(Builder builder) {
70         this.method = builder.getMethod();
71         this.parser = builder.getParser();
72         this.introspector = builder.getIntrospector();
73         this.headers = builder.getHeaders();
74         this.transactionId = builder.getTransactionId();
75         this.info = builder.getInfo();
76         this.uri = builder.getUri();
77         this.marshallerProperties = builder.getMarshallerProperties();
78         this.rawRequestContent = builder.getRawRequestContent();
79     }
80
81     /**
82      * Gets the headers.
83      *
84      * @return the headers
85      */
86     public HttpHeaders getHeaders() {
87         return headers;
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     public static class Builder {
158
159         private QueryParser parser = null;
160
161         private Introspector introspector = null;
162
163         private HttpHeaders headers = null;
164
165         private String transactionId = null;
166
167         private UriInfo info = null;
168
169         private HttpMethod method = null;
170
171         private URI uri = null;
172
173         private Optional<MarshallerProperties> marshallerProperties = Optional.empty();
174
175         private Optional<String> rawRequestContent = Optional.empty();
176
177         /**
178          * Instantiates a new DB request.
179          *
180          * @param method the method
181          * @param uri the uri
182          * @param parser the parser
183          * @param obj the obj
184          * @param headers the headers
185          * @param info the info
186          * @param transactionId the transaction id
187          */
188         public Builder(HttpMethod method, URI uri, QueryParser parser, Introspector obj, HttpHeaders headers,
189                 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
238         protected Optional<MarshallerProperties> getMarshallerProperties() {
239             return marshallerProperties;
240         }
241
242         protected Optional<String> getRawRequestContent() {
243             return rawRequestContent;
244         }
245
246         public DBRequest build() {
247
248             return new DBRequest(this);
249         }
250
251     }
252 }