2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2018 IBM.
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.adapters.sdnc.sdncrest;
25 import org.onap.so.adapters.sdnc.exception.SDNCAdapterException;
26 import org.onap.so.adapters.sdnc.impl.Constants;
27 import org.onap.so.logger.MessageEnum;
28 import org.onap.so.logger.MsoAlarmLogger;
29 import org.onap.so.logger.MsoLogger;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.core.env.Environment;
32 import org.springframework.stereotype.Component;
35 public class MapTypedRequestTunablesData {
37 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA,MapTypedRequestTunablesData.class);
39 private static final MsoAlarmLogger alarmLogger = new MsoAlarmLogger();
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 msoLogger.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, reqTunable.getKey(), "SDNC", "", MsoLogger.ErrorCode.DataError, MISSING_CONFIG_PARAM_ERROR_MSG);
58 alarmLogger.sendAlarm(MSO_INTERNAL_ERROR, MsoAlarmLogger.CRITICAL, reqTunable.getError());
59 throw new SDNCAdapterException(error);
62 String[] parts = value.split("\\|");
64 if (parts.length != 5) {
65 error="Invalid configuration for: " + reqTunable.getKey();
66 msoLogger.error(MessageEnum.RA_SDNC_INVALID_CONFIG, reqTunable.getKey(), value, "SDNC", "", MsoLogger.ErrorCode.DataError, "Invalid config");
67 alarmLogger.sendAlarm(MSO_INTERNAL_ERROR, MsoAlarmLogger.CRITICAL, reqTunable.getError());
68 throw new SDNCAdapterException(error);
71 reqTunable.setReqMethod(parts[0]);
72 msoLogger.trace("Request Method is set to: " + reqTunable.getReqMethod());
74 reqTunable.setTimeout(parts[1]);
75 msoLogger.trace("Timeout is set to: " + reqTunable.getTimeout());
77 String urlPropKey = Constants.REQUEST_TUNABLES + "." + parts[2];
78 reqTunable.setSdncUrl(env.getProperty(urlPropKey, ""));
80 if ("".equals(reqTunable.getSdncUrl())) {
81 error=MISSING_CONFIGURATION_ERROR_MSG + urlPropKey;
82 msoLogger.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, urlPropKey, "SDNC", "", MsoLogger.ErrorCode.DataError, MISSING_CONFIG_PARAM_ERROR_MSG);
83 alarmLogger.sendAlarm(MSO_INTERNAL_ERROR, MsoAlarmLogger.CRITICAL, reqTunable.getError());
84 throw new SDNCAdapterException(error);
87 msoLogger.trace("SDNC Url is set to: " + reqTunable.getSdncUrl());
89 reqTunable.setHeaderName(parts[3]);
90 msoLogger.trace("Header Name is set to: " + reqTunable.getHeaderName());
92 reqTunable.setNamespace(parts[4]);
93 msoLogger.trace("Namespace is set to: " + reqTunable.getNamespace());
95 reqTunable.setMyUrl(env.getProperty(Constants.MY_URL_PROP, ""));
97 if ("".equals(reqTunable.getMyUrl())) {
98 error=MISSING_CONFIGURATION_ERROR_MSG + Constants.MY_URL_PROP;
99 msoLogger.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, Constants.MY_URL_PROP, "SDNC", "",
100 MsoLogger.ErrorCode.DataError, MISSING_CONFIG_PARAM_ERROR_MSG);
101 alarmLogger.sendAlarm(MSO_INTERNAL_ERROR, MsoAlarmLogger.CRITICAL, reqTunable.getError());
102 throw new SDNCAdapterException(error);
105 while (reqTunable.getMyUrl().endsWith("/")) {
106 reqTunable.setMyUrl(reqTunable.getMyUrl().substring(0, reqTunable.getMyUrl().length()-1));
109 reqTunable.setMyUrl(reqTunable.getMyUrl().concat(reqTunable.getMyUrlSuffix()));
111 msoLogger.debug(reqTunable.toString());