75b92e72470722a5556c984271a317feeedcbd55
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / search / filters / config / FiltersConfig.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.sparky.search.filters.config;
24
25 import java.io.File;
26
27 import org.onap.aai.cl.api.Logger;
28 import org.onap.aai.cl.eelf.LoggerFactory;
29 import org.onap.aai.sparky.logging.AaiUiMsgs;
30 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
31
32 import com.fasterxml.jackson.databind.ObjectMapper;
33
34 public class FiltersConfig {
35
36   private static final Logger LOG = LoggerFactory.getInstance().getLogger(FiltersConfig.class);
37   
38   private String filtersFileName;
39   
40   private String filterMappingsFileName;
41   
42   private FiltersForViewsConfig viewsConfig;
43   
44   private FiltersDetailsConfig filtersConfig;
45
46   /**
47    * Instantiates a new UiViewFilterConfig.
48    */
49   public FiltersConfig() {
50     initializeFilters();
51   }
52
53   /**
54    * Initialize config.
55    */
56   private void initializeFilters() {
57     filtersFileName = SparkyConstants.FILTER_LIST_FILE_DEFAULT;
58     filterMappingsFileName = SparkyConstants.FILTER_MAPPING_FILE_DEFAULT;
59
60     viewsConfig = this.readUiViewsConfig();
61     filtersConfig = this.readUiFiltersConfig();
62   }
63
64   public String getFilterMappingsFileName() {
65     return filterMappingsFileName;
66   }
67
68   public void setFilterMappingsFileName(String filterMappingsFileName) {
69     this.filterMappingsFileName = filterMappingsFileName;
70   }
71
72   public String getFiltersFileName() {
73     return filtersFileName;
74   }
75
76   public void setFiltersFileName(String filtersFileName) {
77     this.filtersFileName = filtersFileName;
78   }
79
80   public FiltersForViewsConfig getViewsConfig() {
81     return viewsConfig;
82   }
83
84   public void setViewsConfig(FiltersForViewsConfig filtersMapEntity) {
85     this.viewsConfig = filtersMapEntity;
86   }
87
88   public FiltersDetailsConfig getFiltersConfig() {
89     return filtersConfig;
90   }
91   
92   public UiFilterConfig getFilterById(String filterId) {
93     for ( UiFilterConfig filter : filtersConfig.getFilters()) {
94       if ( filter.getFilterId().equals(filterId)) {
95         return filter;
96       }
97     }
98     
99     return null;
100   }
101   
102   public void setFiltersConfig(FiltersDetailsConfig filtersConfig) {
103     this.filtersConfig = filtersConfig;
104   }
105
106   public FiltersDetailsConfig readUiFiltersConfig(){
107     ObjectMapper mapper = new ObjectMapper();
108     FiltersDetailsConfig filtersConfig = null;
109     try{
110       filtersConfig = mapper.readValue(new File(this.getFiltersFileName()), FiltersDetailsConfig.class);
111     } catch (Exception e){
112       LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, SparkyConstants.getConfigPath(this.getFiltersFileName()));
113     }
114
115     return filtersConfig;
116   }
117
118   public FiltersForViewsConfig readUiViewsConfig(){
119     ObjectMapper mapper = new ObjectMapper();
120     FiltersForViewsConfig viewsConfig = null;
121     
122     try {
123       viewsConfig = mapper.readValue(new File(this.getFilterMappingsFileName()), FiltersForViewsConfig.class);
124     } catch (Exception e){
125       LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, SparkyConstants.getConfigPath(this.getFilterMappingsFileName()));
126     }
127
128     return viewsConfig;
129   }
130 }
131