2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.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.openecomp.aai.exceptions.AAIException;
33 public class Request<T> {
35 public static final String V2 = "v2";
36 public static final String V3 = "v3";
37 public static final String V4 = "v4";
38 public static final String V5 = "v5";
39 public final String fromAppId;
40 public final String transactionId;
41 public final String path;
42 public final RestObject<T> restObj;
43 public final boolean oldServer;
44 public final String apiVersion;
48 * Instantiates a new request.
50 * @param builder the builder
52 public Request(RequestBuilder<T> builder) {
54 fromAppId = builder.fromAppId;
55 transactionId = builder.transactionId;
56 restObj = builder.restObj;
57 oldServer = builder.oldServer;
58 apiVersion = builder.apiVersion;
61 path = apiVersion + "/" + builder.path;
69 public static class RequestBuilder<T> {
70 private String fromAppId;
71 private String transactionId;
73 private RestObject<T> restObj;
74 private boolean oldServer;
75 private String apiVersion = Request.V4;
79 * Sets the from app id.
81 * @param fromAppId the from app id
82 * @return the request builder
84 public RequestBuilder<T> setFromAppId(String fromAppId) {
85 this.fromAppId = fromAppId;
90 * Sets the transaction id.
92 * @param transactionId the transaction id
93 * @return the request builder
95 public RequestBuilder<T> setTransactionId(String transactionId) {
96 this.transactionId = transactionId;
104 * @param path the path
105 * @return the request builder
107 public RequestBuilder<T> setPath(String path) {
115 * Sets the restcore obj.
117 * @param restObj the restcore obj
118 * @return the request builder
120 public RequestBuilder<T> setRestObj(RestObject<T> restObj) {
121 this.restObj = restObj;
127 * Sets the old server.
129 * @param oldServer the old server
130 * @return the request builder
132 public RequestBuilder<T> setOldServer(boolean oldServer) {
133 this.oldServer = oldServer;
139 * Sets the api version.
141 * @param apiVersion the api version
142 * @return the request builder
144 public RequestBuilder<T> setApiVersion(String apiVersion) {
145 this.apiVersion = apiVersion;
152 * @return the request
154 public Request<T> build() {
155 return new Request<T>(this);