Update the license for 2017-2018 license
[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 package org.onap.aai.util;
21
22 import java.io.UnsupportedEncodingException;
23 import java.net.URI;
24 import java.net.URISyntaxException;
25 import java.net.URLEncoder;
26 import java.nio.charset.StandardCharsets;
27
28 import javax.ws.rs.core.UriBuilder;
29
30 import org.onap.aai.exceptions.AAIException;
31
32 public class Request<T> {
33
34         public static final String V12 = "v12";
35         public final String fromAppId;
36         public final String transactionId;
37         public final String path;
38         public final RestObject<T> restObj;
39         public final boolean oldServer;
40         public final String apiVersion;
41         
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         
65         public static class RequestBuilder<T> {
66                 private String fromAppId;
67                 private String transactionId;
68                 private String path;
69                 private RestObject<T> restObj;
70                 private boolean oldServer;
71                 private String apiVersion = Request.V12;
72                 
73
74                 /**
75                  * Sets the from app id.
76                  *
77                  * @param fromAppId the from app id
78                  * @return the request builder
79                  */
80                 public RequestBuilder<T> setFromAppId(String fromAppId) {
81                         this.fromAppId = fromAppId;
82                         return this;
83                 }
84                 
85                 /**
86                  * Sets the transaction id.
87                  *
88                  * @param transactionId the transaction id
89                  * @return the request builder
90                  */
91                 public RequestBuilder<T> setTransactionId(String transactionId) {
92                         this.transactionId = transactionId;
93                         return this;
94
95                 }
96                 
97                 /**
98                  * Sets the path.
99                  *
100                  * @param path the path
101                  * @return the request builder
102                  */
103                 public RequestBuilder<T> setPath(String path) {
104                         
105                         this.path = path;
106                         return this;
107
108                 }
109                 
110                 /**
111                  * Sets the restcore obj.
112                  *
113                  * @param restObj the restcore obj
114                  * @return the request builder
115                  */
116                 public RequestBuilder<T> setRestObj(RestObject<T> restObj) {
117                         this.restObj = restObj;
118                         return this;
119
120                 }
121                 
122                 /**
123                  * Sets the old server.
124                  *
125                  * @param oldServer the old server
126                  * @return the request builder
127                  */
128                 public RequestBuilder<T> setOldServer(boolean oldServer) {
129                         this.oldServer = oldServer;
130                         return this;
131
132                 }
133                 
134                 /**
135                  * Sets the api version.
136                  *
137                  * @param apiVersion the api version
138                  * @return the request builder
139                  */
140                 public RequestBuilder<T> setApiVersion(String apiVersion) {
141                         this.apiVersion = apiVersion;
142                         return this;
143                 }
144                 
145                 /**
146                  * Builds the.
147                  *
148                  * @return the request
149                  */
150                 public Request<T> build() {
151                         return new Request<T>(this);
152                 }
153                 
154         }
155         
156 }