Containerization feature of SO
[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  * 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.so.adapters.sdnc.sdncrest;
22
23 import org.apache.commons.lang3.builder.ToStringBuilder;
24 import org.onap.so.adapters.sdnc.impl.Constants;
25 import org.onap.so.logger.MsoLogger;
26
27 /**
28  * Typed Request Tunables.  Each entry is identified by a TYPE in the property name.
29  * Different types can have different keys.
30  * <p>
31  * General format:
32  * <pre>
33  * org.onap.so.adapters.sdnc.TYPE.KEY1[.KEY2...]=METHOD|TIMEOUT|URL|HEADER|NAMESPACE
34  * </pre>
35  * Currently supported type(s): service
36  * <pre>
37  * org.onap.so.adapters.sdnc.service.SERVICE.OPERATION=METHOD|TIMEOUT|URL|HEADER|NAMESPACE
38  * </pre>
39  */
40 public class TypedRequestTunables {     
41
42         private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, TypedRequestTunables.class);
43
44         private String reqId;
45         private String myUrlSuffix;
46         private String key = null;
47         private String error = "";
48
49         // tunables (all are required)
50         private String reqMethod = null;
51         private String timeout = null;
52         private String sdncUrl = null;
53         private String headerName = null;
54         private String namespace = null;
55         private String myUrl = null;
56         
57         public TypedRequestTunables(TypedRequestTunables reqTunableOriginal) {
58                 this.reqId = reqTunableOriginal.getReqId();
59                 this.myUrlSuffix = reqTunableOriginal.getMyUrlSuffix();
60                 this.key = reqTunableOriginal.getKey();
61                 this.error = reqTunableOriginal.getError();
62                 this.reqMethod = reqTunableOriginal.getReqMethod();
63                 this.timeout = reqTunableOriginal.getTimeout();
64                 this.sdncUrl = reqTunableOriginal.getSdncUrl();
65                 this.headerName = reqTunableOriginal.getHeaderName();
66                 this.namespace = reqTunableOriginal.getNamespace();
67                 this.myUrl = reqTunableOriginal.getMyUrl();             
68         }
69
70         public TypedRequestTunables(String reqId, String myUrlSuffix) {
71                 this.reqId = reqId;
72                 this.myUrlSuffix = myUrlSuffix;
73         }
74
75         /**
76          * Sets the key for a service request:
77          * <pre>
78          * org.onap.so.adapters.sdnc.service.SERVICE.OPERATION
79          * </pre>
80          * @param service the sdncService
81          * @param operation the sdncOperation
82          */
83         public void setServiceKey(String service, String operation) {
84                 key = Constants.REQUEST_TUNABLES + ".service." + service + "." + operation;
85                 LOGGER.debug("Generated " + getClass().getSimpleName() + " key: " + key);
86         }
87
88         /**
89          * Gets the SDNC request ID.
90          */
91         public String getReqId() {
92                 return reqId;
93         }
94
95         /**
96          * Gets the generated key.
97          */
98         public String getKey() {
99                 return key;
100         }
101
102         /**
103          * Gets the most recent error, or null if there was no error.
104          */
105         public String getError() {
106                 return error;
107         }
108
109         public String getReqMethod() {
110                 return reqMethod;
111         }
112
113         public String getTimeout() {
114                 return timeout;
115         }
116
117         public String getSdncUrl() {
118                 return sdncUrl;
119         }
120
121         public String getHeaderName() {
122                 return headerName;
123         }
124
125         public String getNamespace() {
126                 return namespace;
127         }
128
129         /**
130          * Gets the SDNC adapter notification URL, trimmed of trailing '/' characters.
131          */
132         public String getMyUrl() {
133                 return myUrl;
134         }       
135
136         public String getMyUrlSuffix() {
137                 return myUrlSuffix;
138         }
139
140         public void setKey(String key) {
141                 this.key = key;
142         }
143
144         public void setError(String error) {
145                 this.error = error;
146         }
147
148         public void setReqMethod(String reqMethod) {
149                 this.reqMethod = reqMethod;
150         }
151
152         public void setTimeout(String timeout) {
153                 this.timeout = timeout;
154         }
155
156         public void setSdncUrl(String sdncUrl) {
157                 this.sdncUrl = sdncUrl;
158         }
159
160         public void setHeaderName(String headerName) {
161                 this.headerName = headerName;
162         }
163
164         public void setNamespace(String namespace) {
165                 this.namespace = namespace;
166         }
167
168         public void setMyUrl(String myUrl) {
169                 this.myUrl = myUrl;
170         }       
171
172         @Override
173         public String toString() {
174                 return new ToStringBuilder(this).append("reqId", reqId).append("myUrlSuffix", myUrlSuffix).append("key", key)
175                                 .append("error", error).append("reqMethod", reqMethod).append("timeout", timeout)
176                                 .append("sdncUrl", sdncUrl).append("headerName", headerName).append("namespace", namespace)
177                                 .append("myUrl", myUrl).toString();
178         }
179         
180 }