Replaced all tabs with spaces in java and pom.xml
[so.git] / adapters / mso-sdnc-adapter / src / main / java / org / onap / so / adapters / sdnc / impl / MapRequestTunables.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.impl;
25
26 import org.onap.so.logger.ErrorCode;
27 import org.onap.so.logger.MessageEnum;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.core.env.Environment;
32 import org.springframework.stereotype.Component;
33
34 @Component
35 public class MapRequestTunables {
36
37     private static Logger logger = LoggerFactory.getLogger(MapRequestTunables.class);
38     public static final String GENERATED_KEY = "Generated key: ";
39
40     @Autowired
41     private Environment env;
42
43     public RequestTunables setTunables(RequestTunables reqTunableOriginal) {
44         RequestTunables reqTunable = new RequestTunables(reqTunableOriginal);
45         String error = null;
46         String key;
47         if ("query".equals(reqTunable.getAction())) { // due to variable format for reqTunable.getOperation() eg
48                                                       // services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9
49             key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + ".." + reqTunable.getAction();
50             logger.debug(GENERATED_KEY + key);
51         } else if ("put".equals(reqTunable.getAction()) || "restdelete".equals(reqTunable.getAction())) { // due to
52                                                                                                           // variable
53                                                                                                           // format for
54                                                                                                           // reqTunable.getOperation()
55                                                                                                           // eg
56                                                                                                           // services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9
57             key = Constants.REQUEST_TUNABLES + "..." + reqTunable.getAction();
58             logger.debug(GENERATED_KEY + key);
59         } else {
60             key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + "." + reqTunable.getOperation() + "."
61                     + reqTunable.getAction();
62             logger.debug(GENERATED_KEY + key);
63         }
64
65         String value;
66         value = env.getProperty(key, "");
67
68         if (value != null && value.length() > 0) {
69
70             String[] parts = value.split("\\|"); // escape pipe
71             if (parts.length < 3) {
72                 logger.warn("{} {} {} {} {} {}", MessageEnum.RA_SDNC_INVALID_CONFIG.toString(), key, value, "SDNC",
73                         ErrorCode.DataError.getValue(), "Invalid config");
74             }
75
76             for (int i = 0; i < parts.length; i++) {
77                 if (i == 0) {
78                     reqTunable.setReqMethod(parts[i]);
79                     logger.debug("Request Method is set to: {}", reqTunable.getReqMethod());
80                 } else if (i == 1) {
81                     reqTunable.setTimeout(parts[i]);
82                     logger.debug("Timeout is set to: {}", reqTunable.getTimeout());
83                 } else if (i == 2) {
84                     reqTunable.setSdncUrl(env.getProperty(Constants.REQUEST_TUNABLES + "." + parts[i], ""));
85                     if (reqTunable.getOperation() != null && reqTunable.getSdncUrl() != null) {
86                         reqTunable.setSdncUrl(reqTunable.getSdncUrl() + reqTunable.getOperation());
87                     }
88                     logger.debug("SDNC Url is set to: {}", reqTunable.getSdncUrl());
89                 } else if (i == 3) {
90                     reqTunable.setHeaderName(parts[i]);
91                     logger.debug("HeaderName is set to: {}", reqTunable.getHeaderName());
92                 } else if (i == 4) {
93                     reqTunable.setNamespace(parts[i]);
94                     logger.debug("NameSpace is set to: {}", reqTunable.getNamespace());
95                 } else if (i == 5) {
96                     reqTunable.setAsyncInd(parts[i]);
97                     logger.debug("AsyncInd is set to: {}", reqTunable.getAsyncInd());
98                 }
99             }
100
101             if (reqTunable.getSdncUrl() == null || ("").equals(reqTunable.getSdncUrl())) {
102                 error = "Invalid configuration, sdncUrl required for:" + key + " value:" + value;
103             }
104         } else {
105             error = "Missing configuration for:" + key;
106         }
107         if (error != null) {
108             logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), key, "SDNC",
109                     ErrorCode.DataError.getValue(), "Missing config param");
110         }
111         logger.debug("RequestTunables Key:{} Value:{} Tunables:{}", key, value, this.toString());
112         return reqTunable;
113     }
114 }