2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.util;
23 import java.io.UnsupportedEncodingException;
25 import java.net.URISyntaxException;
26 import java.net.URLEncoder;
27 import java.nio.charset.StandardCharsets;
29 import javax.ws.rs.core.UriBuilder;
31 import org.onap.aai.exceptions.AAIException;
33 public class Request<T> {
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;
44 * Instantiates a new request.
46 * @param builder the builder
48 public Request(RequestBuilder<T> builder) {
50 fromAppId = builder.fromAppId;
51 transactionId = builder.transactionId;
52 restObj = builder.restObj;
53 oldServer = builder.oldServer;
54 apiVersion = builder.apiVersion;
57 path = apiVersion + "/" + builder.path;
64 public static class RequestBuilder<T> {
65 private String fromAppId;
66 private String transactionId;
68 private RestObject<T> restObj;
69 private boolean oldServer;
70 private String apiVersion = Request.V14;
73 * Sets the from app id.
75 * @param fromAppId the from app id
76 * @return the request builder
78 public RequestBuilder<T> setFromAppId(String fromAppId) {
79 this.fromAppId = fromAppId;
84 * Sets the transaction id.
86 * @param transactionId the transaction id
87 * @return the request builder
89 public RequestBuilder<T> setTransactionId(String transactionId) {
90 this.transactionId = transactionId;
98 * @param path the path
99 * @return the request builder
101 public RequestBuilder<T> setPath(String path) {
109 * Sets the restcore obj.
111 * @param restObj the restcore obj
112 * @return the request builder
114 public RequestBuilder<T> setRestObj(RestObject<T> restObj) {
115 this.restObj = restObj;
121 * Sets the old server.
123 * @param oldServer the old server
124 * @return the request builder
126 public RequestBuilder<T> setOldServer(boolean oldServer) {
127 this.oldServer = oldServer;
133 * Sets the api version.
135 * @param apiVersion the api version
136 * @return the request builder
138 public RequestBuilder<T> setApiVersion(String apiVersion) {
139 this.apiVersion = apiVersion;
146 * @return the request
148 public Request<T> build() {
149 return new Request<T>(this);