Merge "[AAI] Fix doc config files"
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / util / Request.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.util;
22
23 public class Request<T> {
24
25     public static final String V14 = "v14";
26     public final String fromAppId;
27     public final String transactionId;
28     public final String path;
29     public final RestObject<T> restObj;
30     public final boolean oldServer;
31     public final String apiVersion;
32
33     /**
34      * Instantiates a new request.
35      *
36      * @param builder the builder
37      */
38     public Request(RequestBuilder<T> builder) {
39
40         fromAppId = builder.fromAppId;
41         transactionId = builder.transactionId;
42         restObj = builder.restObj;
43         oldServer = builder.oldServer;
44         apiVersion = builder.apiVersion;
45
46         if (!oldServer) {
47             path = apiVersion + "/" + builder.path;
48         } else {
49             path = builder.path;
50         }
51
52     }
53
54     public static class RequestBuilder<T> {
55         private String fromAppId;
56         private String transactionId;
57         private String path;
58         private RestObject<T> restObj;
59         private boolean oldServer;
60         private String apiVersion = Request.V14;
61
62         /**
63          * Sets the from app id.
64          *
65          * @param fromAppId the from app id
66          * @return the request builder
67          */
68         public RequestBuilder<T> setFromAppId(String fromAppId) {
69             this.fromAppId = fromAppId;
70             return this;
71         }
72
73         /**
74          * Sets the transaction id.
75          *
76          * @param transactionId the transaction id
77          * @return the request builder
78          */
79         public RequestBuilder<T> setTransactionId(String transactionId) {
80             this.transactionId = transactionId;
81             return this;
82
83         }
84
85         /**
86          * Sets the path.
87          *
88          * @param path the path
89          * @return the request builder
90          */
91         public RequestBuilder<T> setPath(String path) {
92
93             this.path = path;
94             return this;
95
96         }
97
98         /**
99          * Sets the restcore obj.
100          *
101          * @param restObj the restcore obj
102          * @return the request builder
103          */
104         public RequestBuilder<T> setRestObj(RestObject<T> restObj) {
105             this.restObj = restObj;
106             return this;
107
108         }
109
110         /**
111          * Sets the old server.
112          *
113          * @param oldServer the old server
114          * @return the request builder
115          */
116         public RequestBuilder<T> setOldServer(boolean oldServer) {
117             this.oldServer = oldServer;
118             return this;
119
120         }
121
122         /**
123          * Sets the api version.
124          *
125          * @param apiVersion the api version
126          * @return the request builder
127          */
128         public RequestBuilder<T> setApiVersion(String apiVersion) {
129             this.apiVersion = apiVersion;
130             return this;
131         }
132
133         /**
134          * Builds the.
135          *
136          * @return the request
137          */
138         public Request<T> build() {
139             return new Request<T>(this);
140         }
141
142     }
143
144 }