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