6f85ef3d35fccd66a0d09e301695767cd461e598
[dcaegen2/services/mapper.git] /
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : DCAE
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
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=========================================================
19 */
20 package org.onap.universalvesadapter.configs;
21
22 import java.util.Map;
23 import java.util.concurrent.ConcurrentHashMap;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.factory.annotation.Value;
27 import org.springframework.stereotype.Component;
28
29 /**
30  * Configuration for universal adapter service 
31  * 
32  * @author kmalbari
33  *
34  */
35 @Component
36 public class UniversalEventConfiguration{
37
38         private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
39
40         @Value("${universal.configFiles}")
41         private String configFiles;
42
43         private Map<String, String> eventToConfigFileMap = new ConcurrentHashMap<>();
44         
45         
46         /**
47          * Returns config file for a particular event from the mapping. 
48          * If mapping is empty, populates its
49          * 
50          * @param eventType 
51          * 
52          * @return config file name
53          */
54         public String getConfigForEvent(String eventType){
55                 LOGGER.debug("Getting config file name for event:" + eventType);
56                 if(null != configFiles && eventToConfigFileMap.isEmpty()){
57                         for(String entry : configFiles.split(",")){
58                                 eventToConfigFileMap.put(entry.split(":")[0], entry.split(":")[1]);
59                         }
60                         LOGGER.debug("Populated mappings for event type to config files");
61                 }
62                 
63                 return (null == eventToConfigFileMap.get(eventType)) ? "default" : eventToConfigFileMap.get(eventType) ;
64                 
65         }
66         
67         
68 }