2 * ============LICENSE_START=======================================================
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package org.onap.so.adapters.sdnc.sdncrest;
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;
37 public class MapTypedRequestTunablesData {
39 private static Logger logger = LoggerFactory.getLogger(MapTypedRequestTunablesData.class);
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";
46 private Environment env;
49 public TypedRequestTunables setTunables(TypedRequestTunables reqTunableOriginal) throws SDNCAdapterException {
50 TypedRequestTunables reqTunable = new TypedRequestTunables(reqTunableOriginal);
53 String value = env.getProperty(reqTunable.getKey().toLowerCase(), "");
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);
60 throw new SDNCAdapterException(error);
63 String[] parts = value.split("\\|");
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);
72 reqTunable.setReqMethod(parts[0]);
73 logger.trace("Request Method is set to: {}", reqTunable.getReqMethod());
75 reqTunable.setTimeout(parts[1]);
76 logger.trace("Timeout is set to: {}", reqTunable.getTimeout());
78 String urlPropKey = Constants.REQUEST_TUNABLES + "." + parts[2];
79 reqTunable.setSdncUrl(env.getProperty(urlPropKey, ""));
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);
86 throw new SDNCAdapterException(error);
89 logger.trace("SDNC Url is set to: {}", reqTunable.getSdncUrl());
91 reqTunable.setHeaderName(parts[3]);
92 logger.trace("Header Name is set to: {}", reqTunable.getHeaderName());
94 reqTunable.setNamespace(parts[4]);
95 logger.trace("Namespace is set to: {}", reqTunable.getNamespace());
97 reqTunable.setMyUrl(env.getProperty(Constants.MY_URL_PROP, ""));
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);
104 throw new SDNCAdapterException(error);
107 while (reqTunable.getMyUrl().endsWith("/")) {
108 reqTunable.setMyUrl(reqTunable.getMyUrl().substring(0, reqTunable.getMyUrl().length() - 1));
111 reqTunable.setMyUrl(reqTunable.getMyUrl().concat(reqTunable.getMyUrlSuffix()));
113 logger.debug(reqTunable.toString());