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;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.core.env.Environment;
35 import org.springframework.stereotype.Component;
38 public class MapTypedRequestTunablesData {
40 private static Logger logger = LoggerFactory.getLogger(MapTypedRequestTunablesData.class);
42 private static final String MISSING_CONFIGURATION_ERROR_MSG= "Missing configuration for: ";
43 private static final String MISSING_CONFIG_PARAM_ERROR_MSG="Missing config param";
44 private static final String MSO_INTERNAL_ERROR="MsoInternalError";
47 private Environment env;
50 public TypedRequestTunables setTunables(TypedRequestTunables reqTunableOriginal) throws SDNCAdapterException {
51 TypedRequestTunables reqTunable = new TypedRequestTunables(reqTunableOriginal);
54 String value = env.getProperty(reqTunable.getKey().toLowerCase(), "");
56 if ("".equals(value)) {
57 error= MISSING_CONFIGURATION_ERROR_MSG + reqTunable.getKey();
58 logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), reqTunable.getKey(), "SDNC",
59 ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG);
61 throw new SDNCAdapterException(error);
64 String[] parts = value.split("\\|");
66 if (parts.length != 5) {
67 error="Invalid configuration for: " + reqTunable.getKey();
68 logger.error("{} {} {} {} {} {}", MessageEnum.RA_SDNC_INVALID_CONFIG.toString(), reqTunable.getKey(), value, "SDNC",
69 ErrorCode.DataError.getValue(), "Invalid config");
70 throw new SDNCAdapterException(error);
73 reqTunable.setReqMethod(parts[0]);
74 logger.trace("Request Method is set to: {}", reqTunable.getReqMethod());
76 reqTunable.setTimeout(parts[1]);
77 logger.trace("Timeout is set to: {}", reqTunable.getTimeout());
79 String urlPropKey = Constants.REQUEST_TUNABLES + "." + parts[2];
80 reqTunable.setSdncUrl(env.getProperty(urlPropKey, ""));
82 if ("".equals(reqTunable.getSdncUrl())) {
83 error=MISSING_CONFIGURATION_ERROR_MSG + urlPropKey;
84 logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), urlPropKey, "SDNC",
85 ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG);
87 throw new SDNCAdapterException(error);
90 logger.trace("SDNC Url is set to: {}", reqTunable.getSdncUrl());
92 reqTunable.setHeaderName(parts[3]);
93 logger.trace("Header Name is set to: {}", reqTunable.getHeaderName());
95 reqTunable.setNamespace(parts[4]);
96 logger.trace("Namespace is set to: {}", reqTunable.getNamespace());
98 reqTunable.setMyUrl(env.getProperty(Constants.MY_URL_PROP, ""));
100 if ("".equals(reqTunable.getMyUrl())) {
101 error=MISSING_CONFIGURATION_ERROR_MSG + Constants.MY_URL_PROP;
102 logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), Constants.MY_URL_PROP, "SDNC",
103 ErrorCode.DataError.getValue(), MISSING_CONFIG_PARAM_ERROR_MSG);
105 throw new SDNCAdapterException(error);
108 while (reqTunable.getMyUrl().endsWith("/")) {
109 reqTunable.setMyUrl(reqTunable.getMyUrl().substring(0, reqTunable.getMyUrl().length()-1));
112 reqTunable.setMyUrl(reqTunable.getMyUrl().concat(reqTunable.getMyUrlSuffix()));
114 logger.debug(reqTunable.toString());