Replaced all tabs with spaces in java and pom.xml
[so.git] / adapters / mso-sdnc-adapter / src / main / java / org / onap / so / adapters / sdnc / sdncrest / MapTypedRequestTunablesData.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) 2018 IBM.
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  * 
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.so.adapters.sdnc.sdncrest;
25
26 import org.onap.so.adapters.sdnc.exception.SDNCAdapterException;
27 import org.onap.so.adapters.sdnc.impl.Constants;
28 import org.onap.so.logger.ErrorCode;
29 import org.onap.so.logger.MessageEnum;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.core.env.Environment;
34 import org.springframework.stereotype.Component;
35
36 @Component
37 public class MapTypedRequestTunablesData {
38
39     private static Logger logger = LoggerFactory.getLogger(MapTypedRequestTunablesData.class);
40
41     private static final String MISSING_CONFIGURATION_ERROR_MSG = "Missing configuration for: ";
42     private static final String MISSING_CONFIG_PARAM_ERROR_MSG = "Missing config param";
43     private static final String MSO_INTERNAL_ERROR = "MsoInternalError";
44
45     @Autowired
46     private Environment env;
47
48
49     public TypedRequestTunables setTunables(TypedRequestTunables reqTunableOriginal) throws SDNCAdapterException {
50         TypedRequestTunables reqTunable = new TypedRequestTunables(reqTunableOriginal);
51
52         String error;
53         String value = env.getProperty(reqTunable.getKey().toLowerCase(), "");
54
55         if ("".equals(value)) {
56             error = MISSING_CONFIGURATION_ERROR_MSG + reqTunable.getKey();
57             logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), reqTunable.getKey(),
58                     "SDNC", ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG);
59
60             throw new SDNCAdapterException(error);
61         }
62
63         String[] parts = value.split("\\|");
64
65         if (parts.length != 5) {
66             error = "Invalid configuration for: " + reqTunable.getKey();
67             logger.error("{} {} {} {} {} {}", MessageEnum.RA_SDNC_INVALID_CONFIG.toString(), reqTunable.getKey(), value,
68                     "SDNC", ErrorCode.DataError.getValue(), "Invalid config");
69             throw new SDNCAdapterException(error);
70         }
71
72         reqTunable.setReqMethod(parts[0]);
73         logger.trace("Request Method is set to: {}", reqTunable.getReqMethod());
74
75         reqTunable.setTimeout(parts[1]);
76         logger.trace("Timeout is set to: {}", reqTunable.getTimeout());
77
78         String urlPropKey = Constants.REQUEST_TUNABLES + "." + parts[2];
79         reqTunable.setSdncUrl(env.getProperty(urlPropKey, ""));
80
81         if ("".equals(reqTunable.getSdncUrl())) {
82             error = MISSING_CONFIGURATION_ERROR_MSG + urlPropKey;
83             logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), urlPropKey, "SDNC",
84                     ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG);
85
86             throw new SDNCAdapterException(error);
87         }
88
89         logger.trace("SDNC Url is set to: {}", reqTunable.getSdncUrl());
90
91         reqTunable.setHeaderName(parts[3]);
92         logger.trace("Header Name is set to: {}", reqTunable.getHeaderName());
93
94         reqTunable.setNamespace(parts[4]);
95         logger.trace("Namespace is set to: {}", reqTunable.getNamespace());
96
97         reqTunable.setMyUrl(env.getProperty(Constants.MY_URL_PROP, ""));
98
99         if ("".equals(reqTunable.getMyUrl())) {
100             error = MISSING_CONFIGURATION_ERROR_MSG + Constants.MY_URL_PROP;
101             logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), Constants.MY_URL_PROP,
102                     "SDNC", ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG);
103
104             throw new SDNCAdapterException(error);
105         }
106
107         while (reqTunable.getMyUrl().endsWith("/")) {
108             reqTunable.setMyUrl(reqTunable.getMyUrl().substring(0, reqTunable.getMyUrl().length() - 1));
109         }
110
111         reqTunable.setMyUrl(reqTunable.getMyUrl().concat(reqTunable.getMyUrlSuffix()));
112
113         logger.debug(reqTunable.toString());
114         return reqTunable;
115     }
116
117 }