Added UniversalVesAdapter in the Mapper
[dcaegen2/services/mapper.git] / UniversalVesAdapter / src / main / java / org / onap / universalvesadapter / configs / UniversalEventConfiguration.java
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 extends Configuration {
37
38         private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
39         
40         @Value("${snmpTrap.configFile}")
41         private String configFile;
42
43         @Value("${universal.configFiles}")
44         private String configFiles;
45
46         private Map<String, String> eventToConfigFileMap = new ConcurrentHashMap<>();
47         
48         
49         /**
50          * Returns config file for a particular event from the mapping. 
51          * If mapping is empty, populates its
52          * 
53          * @param eventType 
54          * 
55          * @return config file name
56          */
57         public String getConfigForEvent(String eventType){
58                 LOGGER.debug("Getting config file name for event:" + eventType);
59                 if(null != configFiles && eventToConfigFileMap.isEmpty()){
60                         for(String entry : configFiles.split(",")){
61                                 eventToConfigFileMap.put(entry.split(":")[0], entry.split(":")[1]);
62                         }
63                         LOGGER.debug("Populated mappings for event type to config files");
64                 }
65                 
66                 return (null == eventToConfigFileMap.get(eventType)) ? "default" : eventToConfigFileMap.get(eventType) ;
67                 
68         }
69         
70         
71         //think about adding mapping files on runtime as well
72         
73 }