4ff6dbc9a623d9c0ef2357c6f0311efc1eac085c
[so.git] / adapters / mso-sdnc-adapter / src / main / java / org / onap / so / adapters / sdnc / sdncrest / TypedRequestTunables.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.adapters.sdnc.sdncrest;
24
25 import org.apache.commons.lang3.builder.ToStringBuilder;
26 import org.onap.so.adapters.sdnc.impl.Constants;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * Typed Request Tunables.  Each entry is identified by a TYPE in the property name.
32  * Different types can have different keys.
33  * <p>
34  * General format:
35  * <pre>
36  * org.onap.so.adapters.sdnc.TYPE.KEY1[.KEY2...]=METHOD|TIMEOUT|URL|HEADER|NAMESPACE
37  * </pre>
38  * Currently supported type(s): service
39  * <pre>
40  * org.onap.so.adapters.sdnc.service.SERVICE.OPERATION=METHOD|TIMEOUT|URL|HEADER|NAMESPACE
41  * </pre>
42  */
43 public class TypedRequestTunables {     
44
45         private static final Logger logger = LoggerFactory.getLogger(TypedRequestTunables.class);
46
47         private String reqId;
48         private String myUrlSuffix;
49         private String key = null;
50         private String error = "";
51
52         // tunables (all are required)
53         private String reqMethod = null;
54         private String timeout = null;
55         private String sdncUrl = null;
56         private String headerName = null;
57         private String namespace = null;
58         private String myUrl = null;
59         
60         public TypedRequestTunables(TypedRequestTunables reqTunableOriginal) {
61                 this.reqId = reqTunableOriginal.getReqId();
62                 this.myUrlSuffix = reqTunableOriginal.getMyUrlSuffix();
63                 this.key = reqTunableOriginal.getKey();
64                 this.error = reqTunableOriginal.getError();
65                 this.reqMethod = reqTunableOriginal.getReqMethod();
66                 this.timeout = reqTunableOriginal.getTimeout();
67                 this.sdncUrl = reqTunableOriginal.getSdncUrl();
68                 this.headerName = reqTunableOriginal.getHeaderName();
69                 this.namespace = reqTunableOriginal.getNamespace();
70                 this.myUrl = reqTunableOriginal.getMyUrl();             
71         }
72
73         public TypedRequestTunables(String reqId, String myUrlSuffix) {
74                 this.reqId = reqId;
75                 this.myUrlSuffix = myUrlSuffix;
76         }
77
78         /**
79          * Sets the key for a service request:
80          * <pre>
81          * org.onap.so.adapters.sdnc.service.SERVICE.OPERATION
82          * </pre>
83          * @param service the sdncService
84          * @param operation the sdncOperation
85          */
86         public void setServiceKey(String service, String operation) {
87                 key = Constants.REQUEST_TUNABLES + ".service." + service + "." + operation;
88                 logger.debug("Generated {} key: {}", getClass().getSimpleName(), key);
89         }
90
91         /**
92          * Gets the SDNC request ID.
93          */
94         public String getReqId() {
95                 return reqId;
96         }
97
98         /**
99          * Gets the generated key.
100          */
101         public String getKey() {
102                 return key;
103         }
104
105         /**
106          * Gets the most recent error, or null if there was no error.
107          */
108         public String getError() {
109                 return error;
110         }
111
112         public String getReqMethod() {
113                 return reqMethod;
114         }
115
116         public String getTimeout() {
117                 return timeout;
118         }
119
120         public String getSdncUrl() {
121                 return sdncUrl;
122         }
123
124         public String getHeaderName() {
125                 return headerName;
126         }
127
128         public String getNamespace() {
129                 return namespace;
130         }
131
132         /**
133          * Gets the SDNC adapter notification URL, trimmed of trailing '/' characters.
134          */
135         public String getMyUrl() {
136                 return myUrl;
137         }       
138
139         public String getMyUrlSuffix() {
140                 return myUrlSuffix;
141         }
142
143         public void setKey(String key) {
144                 this.key = key;
145         }
146
147         public void setError(String error) {
148                 this.error = error;
149         }
150
151         public void setReqMethod(String reqMethod) {
152                 this.reqMethod = reqMethod;
153         }
154
155         public void setTimeout(String timeout) {
156                 this.timeout = timeout;
157         }
158
159         public void setSdncUrl(String sdncUrl) {
160                 this.sdncUrl = sdncUrl;
161         }
162
163         public void setHeaderName(String headerName) {
164                 this.headerName = headerName;
165         }
166
167         public void setNamespace(String namespace) {
168                 this.namespace = namespace;
169         }
170
171         public void setMyUrl(String myUrl) {
172                 this.myUrl = myUrl;
173         }       
174
175         @Override
176         public String toString() {
177                 return new ToStringBuilder(this).append("reqId", reqId).append("myUrlSuffix", myUrlSuffix).append("key", key)
178                                 .append("error", error).append("reqMethod", reqMethod).append("timeout", timeout)
179                                 .append("sdncUrl", sdncUrl).append("headerName", headerName).append("namespace", namespace)
180                                 .append("myUrl", myUrl).toString();
181         }
182         
183 }