[AAI] Fix doc config files
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / util / Request.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.util;
22
23 import java.io.UnsupportedEncodingException;
24 import java.net.URI;
25 import java.net.URISyntaxException;
26 import java.net.URLEncoder;
27 import java.nio.charset.StandardCharsets;
28
29 import javax.ws.rs.core.UriBuilder;
30
31 import org.onap.aai.exceptions.AAIException;
32
33 public class Request<T> {
34
35     public static final String V14 = "v14";
36     public final String fromAppId;
37     public final String transactionId;
38     public final String path;
39     public final RestObject<T> restObj;
40     public final boolean oldServer;
41     public final String apiVersion;
42
43     /**
44      * Instantiates a new request.
45      *
46      * @param builder the builder
47      */
48     public Request(RequestBuilder<T> builder) {
49
50         fromAppId = builder.fromAppId;
51         transactionId = builder.transactionId;
52         restObj = builder.restObj;
53         oldServer = builder.oldServer;
54         apiVersion = builder.apiVersion;
55
56         if (!oldServer) {
57             path = apiVersion + "/" + builder.path;
58         } else {
59             path = builder.path;
60         }
61
62     }
63
64     public static class RequestBuilder<T> {
65         private String fromAppId;
66         private String transactionId;
67         private String path;
68         private RestObject<T> restObj;
69         private boolean oldServer;
70         private String apiVersion = Request.V14;
71
72         /**
73          * Sets the from app id.
74          *
75          * @param fromAppId the from app id
76          * @return the request builder
77          */
78         public RequestBuilder<T> setFromAppId(String fromAppId) {
79             this.fromAppId = fromAppId;
80             return this;
81         }
82
83         /**
84          * Sets the transaction id.
85          *
86          * @param transactionId the transaction id
87          * @return the request builder
88          */
89         public RequestBuilder<T> setTransactionId(String transactionId) {
90             this.transactionId = transactionId;
91             return this;
92
93         }
94
95         /**
96          * Sets the path.
97          *
98          * @param path the path
99          * @return the request builder
100          */
101         public RequestBuilder<T> setPath(String path) {
102
103             this.path = path;
104             return this;
105
106         }
107
108         /**
109          * Sets the restcore obj.
110          *
111          * @param restObj the restcore obj
112          * @return the request builder
113          */
114         public RequestBuilder<T> setRestObj(RestObject<T> restObj) {
115             this.restObj = restObj;
116             return this;
117
118         }
119
120         /**
121          * Sets the old server.
122          *
123          * @param oldServer the old server
124          * @return the request builder
125          */
126         public RequestBuilder<T> setOldServer(boolean oldServer) {
127             this.oldServer = oldServer;
128             return this;
129
130         }
131
132         /**
133          * Sets the api version.
134          *
135          * @param apiVersion the api version
136          * @return the request builder
137          */
138         public RequestBuilder<T> setApiVersion(String apiVersion) {
139             this.apiVersion = apiVersion;
140             return this;
141         }
142
143         /**
144          * Builds the.
145          *
146          * @return the request
147          */
148         public Request<T> build() {
149             return new Request<T>(this);
150         }
151
152     }
153
154 }