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