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=========================================================
20 package org.onap.aai.util;
22 import java.io.UnsupportedEncodingException;
24 import java.net.URISyntaxException;
25 import java.net.URLEncoder;
26 import java.nio.charset.StandardCharsets;
28 import javax.ws.rs.core.UriBuilder;
30 import org.onap.aai.exceptions.AAIException;
32 public class Request<T> {
34 public static final String V14 = "v14";
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;
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;
65 public static class RequestBuilder<T> {
66 private String fromAppId;
67 private String transactionId;
69 private RestObject<T> restObj;
70 private boolean oldServer;
71 private String apiVersion = Request.V14;
75 * Sets the from app id.
77 * @param fromAppId the from app id
78 * @return the request builder
80 public RequestBuilder<T> setFromAppId(String fromAppId) {
81 this.fromAppId = fromAppId;
86 * Sets the transaction id.
88 * @param transactionId the transaction id
89 * @return the request builder
91 public RequestBuilder<T> setTransactionId(String transactionId) {
92 this.transactionId = transactionId;
100 * @param path the path
101 * @return the request builder
103 public RequestBuilder<T> setPath(String path) {
111 * Sets the restcore obj.
113 * @param restObj the restcore obj
114 * @return the request builder
116 public RequestBuilder<T> setRestObj(RestObject<T> restObj) {
117 this.restObj = restObj;
123 * Sets the old server.
125 * @param oldServer the old server
126 * @return the request builder
128 public RequestBuilder<T> setOldServer(boolean oldServer) {
129 this.oldServer = oldServer;
135 * Sets the api version.
137 * @param apiVersion the api version
138 * @return the request builder
140 public RequestBuilder<T> setApiVersion(String apiVersion) {
141 this.apiVersion = apiVersion;
148 * @return the request
150 public Request<T> build() {
151 return new Request<T>(this);