1f94fbe2c7a7af41ff7d3b7a1169dd51bed83e03
[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.introspection.Introspector;
30 import org.onap.aai.introspection.MarshallerProperties;
31 import org.onap.aai.parsers.query.QueryParser;
32 import org.onap.aai.restcore.HttpMethod;
33
34 /**
35  * The Class DBRequest.
36  */
37 public class DBRequest {
38
39     private final QueryParser parser;
40
41     private final Introspector introspector;
42
43     private final HttpHeaders headers;
44
45     private final String transactionId;
46
47     private final UriInfo info;
48
49     private final HttpMethod method;
50
51     private final URI uri;
52
53     private final Optional<String> rawRequestContent;
54
55     private final Optional<MarshallerProperties> marshallerProperties;
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      * Gets the transaction id.
91      *
92      * @return the transaction id
93      */
94     public String getTransactionId() {
95         return transactionId;
96     }
97
98     /**
99      * Gets the info.
100      *
101      * @return the info
102      */
103     public UriInfo getInfo() {
104         return info;
105     }
106
107     /**
108      * Gets the parser.
109      *
110      * @return the parser
111      */
112     public QueryParser getParser() {
113         return parser;
114     }
115
116     /**
117      * Gets the introspector.
118      *
119      * @return the introspector
120      */
121     public Introspector getIntrospector() {
122         return introspector;
123     }
124
125     /**
126      * Gets the method.
127      *
128      * @return the method
129      */
130     public HttpMethod getMethod() {
131         return method;
132     }
133
134     /**
135      * Gets the uri.
136      *
137      * @return the uri
138      */
139     public URI getUri() {
140         return uri;
141     }
142
143     /**
144      * Gets the raw content.
145      *
146      * @return the raw content
147      */
148     public Optional<String> getRawRequestContent() {
149         return rawRequestContent;
150     }
151
152     public Optional<MarshallerProperties> getMarshallerProperties() {
153         return marshallerProperties;
154     }
155
156     public static class Builder {
157
158         private QueryParser parser = null;
159
160         private Introspector introspector = null;
161
162         private HttpHeaders headers = null;
163
164         private String transactionId = null;
165
166         private UriInfo info = null;
167
168         private HttpMethod method = null;
169
170         private URI uri = null;
171
172         private Optional<MarshallerProperties> marshallerProperties = Optional.empty();
173
174         private Optional<String> rawRequestContent = Optional.empty();
175
176         /**
177          * Instantiates a new DB request.
178          *
179          * @param method the method
180          * @param uri the uri
181          * @param parser the parser
182          * @param obj the obj
183          * @param headers the headers
184          * @param info the info
185          * @param transactionId the transaction id
186          */
187         public Builder(HttpMethod method, URI uri, QueryParser parser, Introspector obj, HttpHeaders headers,
188                 UriInfo info, String transactionId) {
189             this.method = method;
190             this.parser = parser;
191             this.introspector = obj;
192             this.headers = headers;
193             this.transactionId = transactionId;
194             this.info = info;
195             this.uri = uri;
196
197         }
198
199         public QueryParser getParser() {
200             return parser;
201         }
202
203         public Introspector getIntrospector() {
204             return introspector;
205         }
206
207         public HttpHeaders getHeaders() {
208             return headers;
209         }
210
211         public String getTransactionId() {
212             return transactionId;
213         }
214
215         public UriInfo getInfo() {
216             return info;
217         }
218
219         public HttpMethod getMethod() {
220             return method;
221         }
222
223         public URI getUri() {
224             return uri;
225         }
226
227         public Builder customMarshaller(MarshallerProperties properties) {
228             this.marshallerProperties = Optional.of(properties);
229             return this;
230         }
231
232         public Builder rawRequestContent(String content) {
233             this.rawRequestContent = Optional.of(content);
234             return this;
235         }
236
237         protected Optional<MarshallerProperties> getMarshallerProperties() {
238             return marshallerProperties;
239         }
240
241         protected Optional<String> getRawRequestContent() {
242             return rawRequestContent;
243         }
244
245         public DBRequest build() {
246
247             return new DBRequest(this);
248         }
249
250     }
251 }