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 V12 = "v12";
37 public final String fromAppId;
38 public final String transactionId;
39 public final String path;
40 public final RestObject<T> restObj;
41 public final boolean oldServer;
42 public final String apiVersion;
46 * Instantiates a new request.
48 * @param builder the builder
50 public Request(RequestBuilder<T> builder) {
52 fromAppId = builder.fromAppId;
53 transactionId = builder.transactionId;
54 restObj = builder.restObj;
55 oldServer = builder.oldServer;
56 apiVersion = builder.apiVersion;
59 path = apiVersion + "/" + builder.path;
67 public static class RequestBuilder<T> {
68 private String fromAppId;
69 private String transactionId;
71 private RestObject<T> restObj;
72 private boolean oldServer;
73 private String apiVersion = Request.V12;
77 * Sets the from app id.
79 * @param fromAppId the from app id
80 * @return the request builder
82 public RequestBuilder<T> setFromAppId(String fromAppId) {
83 this.fromAppId = fromAppId;
88 * Sets the transaction id.
90 * @param transactionId the transaction id
91 * @return the request builder
93 public RequestBuilder<T> setTransactionId(String transactionId) {
94 this.transactionId = transactionId;
102 * @param path the path
103 * @return the request builder
105 public RequestBuilder<T> setPath(String path) {
113 * Sets the restcore obj.
115 * @param restObj the restcore obj
116 * @return the request builder
118 public RequestBuilder<T> setRestObj(RestObject<T> restObj) {
119 this.restObj = restObj;
125 * Sets the old server.
127 * @param oldServer the old server
128 * @return the request builder
130 public RequestBuilder<T> setOldServer(boolean oldServer) {
131 this.oldServer = oldServer;
137 * Sets the api version.
139 * @param apiVersion the api version
140 * @return the request builder
142 public RequestBuilder<T> setApiVersion(String apiVersion) {
143 this.apiVersion = apiVersion;
150 * @return the request
152 public Request<T> build() {
153 return new Request<T>(this);