2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.sdnc.sdncrest;
23 import org.onap.so.adapters.sdnc.exception.SDNCAdapterException;
24 import org.onap.so.adapters.sdnc.impl.Constants;
25 import org.onap.so.logger.MessageEnum;
26 import org.onap.so.logger.MsoAlarmLogger;
27 import org.onap.so.logger.MsoLogger;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.core.env.Environment;
30 import org.springframework.stereotype.Component;
33 public class MapTypedRequestTunablesData {
35 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA,MapTypedRequestTunablesData.class);
37 private static final MsoAlarmLogger alarmLogger = new MsoAlarmLogger();
40 private Environment env;
43 public TypedRequestTunables setTunables(TypedRequestTunables reqTunableOriginal) throws SDNCAdapterException {
44 TypedRequestTunables reqTunable = new TypedRequestTunables(reqTunableOriginal);
47 String value = env.getProperty(reqTunable.getKey().toLowerCase(), "");
49 if ("".equals(value)) {
50 error= "Missing configuration for: " + reqTunable.getKey();
51 msoLogger.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, reqTunable.getKey(), "SDNC", "", MsoLogger.ErrorCode.DataError, "Missing config param");
52 alarmLogger.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, reqTunable.getError());
53 throw new SDNCAdapterException(error);
56 String[] parts = value.split("\\|");
58 if (parts.length != 5) {
59 error="Invalid configuration for: " + reqTunable.getKey();
60 msoLogger.error(MessageEnum.RA_SDNC_INVALID_CONFIG, reqTunable.getKey(), value, "SDNC", "", MsoLogger.ErrorCode.DataError, "Invalid config");
61 alarmLogger.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, reqTunable.getError());
62 throw new SDNCAdapterException(error);
65 reqTunable.setReqMethod(parts[0]);
66 msoLogger.trace("Request Method is set to: " + reqTunable.getReqMethod());
68 reqTunable.setTimeout(parts[1]);
69 msoLogger.trace("Timeout is set to: " + reqTunable.getTimeout());
71 String urlPropKey = Constants.REQUEST_TUNABLES + "." + parts[2];
72 reqTunable.setSdncUrl(env.getProperty(urlPropKey, ""));
74 if ("".equals(reqTunable.getSdncUrl())) {
75 error="Missing configuration for: " + urlPropKey;
76 msoLogger.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, urlPropKey, "SDNC", "", MsoLogger.ErrorCode.DataError, "Missing config param");
77 alarmLogger.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, reqTunable.getError());
78 throw new SDNCAdapterException(error);
81 msoLogger.trace("SDNC Url is set to: " + reqTunable.getSdncUrl());
83 reqTunable.setHeaderName(parts[3]);
84 msoLogger.trace("Header Name is set to: " + reqTunable.getHeaderName());
86 reqTunable.setNamespace(parts[4]);
87 msoLogger.trace("Namespace is set to: " + reqTunable.getNamespace());
89 reqTunable.setMyUrl(env.getProperty(Constants.MY_URL_PROP, ""));
91 if ("".equals(reqTunable.getMyUrl())) {
92 error="Missing configuration for: " + Constants.MY_URL_PROP;
93 msoLogger.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, Constants.MY_URL_PROP, "SDNC", "",
94 MsoLogger.ErrorCode.DataError, "Missing config param");
95 alarmLogger.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, reqTunable.getError());
96 throw new SDNCAdapterException(error);
99 while (reqTunable.getMyUrl().endsWith("/")) {
100 reqTunable.setMyUrl(reqTunable.getMyUrl().substring(0, reqTunable.getMyUrl().length()-1));
103 reqTunable.setMyUrl(reqTunable.getMyUrl().concat(reqTunable.getMyUrlSuffix()));
105 msoLogger.debug(reqTunable.toString());