2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.util;
24 import java.io.UnsupportedEncodingException;
26 import java.net.URISyntaxException;
27 import java.net.URLEncoder;
28 import java.nio.charset.StandardCharsets;
30 import javax.ws.rs.core.UriBuilder;
32 import org.onap.aai.exceptions.AAIException;
34 public class Request<T> {
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;
49 * Instantiates a new request.
51 * @param builder the builder
53 public Request(RequestBuilder<T> builder) {
55 fromAppId = builder.fromAppId;
56 transactionId = builder.transactionId;
57 restObj = builder.restObj;
58 oldServer = builder.oldServer;
59 apiVersion = builder.apiVersion;
62 path = apiVersion + "/" + builder.path;
70 public static class RequestBuilder<T> {
71 private String fromAppId;
72 private String transactionId;
74 private RestObject<T> restObj;
75 private boolean oldServer;
76 private String apiVersion = Request.V4;
80 * Sets the from app id.
82 * @param fromAppId the from app id
83 * @return the request builder
85 public RequestBuilder<T> setFromAppId(String fromAppId) {
86 this.fromAppId = fromAppId;
91 * Sets the transaction id.
93 * @param transactionId the transaction id
94 * @return the request builder
96 public RequestBuilder<T> setTransactionId(String transactionId) {
97 this.transactionId = transactionId;
105 * @param path the path
106 * @return the request builder
108 public RequestBuilder<T> setPath(String path) {
116 * Sets the restcore obj.
118 * @param restObj the restcore obj
119 * @return the request builder
121 public RequestBuilder<T> setRestObj(RestObject<T> restObj) {
122 this.restObj = restObj;
128 * Sets the old server.
130 * @param oldServer the old server
131 * @return the request builder
133 public RequestBuilder<T> setOldServer(boolean oldServer) {
134 this.oldServer = oldServer;
140 * Sets the api version.
142 * @param apiVersion the api version
143 * @return the request builder
145 public RequestBuilder<T> setApiVersion(String apiVersion) {
146 this.apiVersion = apiVersion;
153 * @return the request
155 public Request<T> build() {
156 return new Request<T>(this);