Adding interfaces in documentation
[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-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 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 package org.onap.aai.sparky.search.filters.config;
22
23 import java.io.File;
24
25 import org.onap.aai.cl.api.Logger;
26 import org.onap.aai.cl.eelf.LoggerFactory;
27 import org.onap.aai.sparky.logging.AaiUiMsgs;
28 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
29
30 import com.fasterxml.jackson.databind.ObjectMapper;
31
32 public class FiltersConfig {
33
34   private static final Logger LOG = LoggerFactory.getInstance().getLogger(FiltersConfig.class);
35   
36   private String filtersFileName;
37   
38   private String filterMappingsFileName;
39   
40   private FiltersForViewsConfig viewsConfig;
41   
42   private FiltersDetailsConfig filtersConfig;
43
44   /**
45    * Instantiates a new UiViewFilterConfig.
46    */
47   public FiltersConfig() {
48     initializeFilters();
49   }
50   
51   public FiltersConfig(String filtersFileName, String filterMappingsFileName) {
52     this.filtersFileName = filtersFileName;
53     this.filterMappingsFileName = filterMappingsFileName;
54     
55     viewsConfig = this.readUiViewsConfig();
56     filtersConfig = this.readUiFiltersConfig();
57   }
58
59   /**
60    * Initialize config.
61    */
62   private void initializeFilters() {
63     filtersFileName = SparkyConstants.FILTER_LIST_FILE_DEFAULT;
64     filterMappingsFileName = SparkyConstants.FILTER_MAPPING_FILE_DEFAULT;
65
66     viewsConfig = this.readUiViewsConfig();
67     filtersConfig = this.readUiFiltersConfig();
68   }
69
70   public String getFilterMappingsFileName() {
71     return filterMappingsFileName;
72   }
73
74   public void setFilterMappingsFileName(String filterMappingsFileName) {
75     this.filterMappingsFileName = filterMappingsFileName;
76   }
77
78   public String getFiltersFileName() {
79     return filtersFileName;
80   }
81
82   public void setFiltersFileName(String filtersFileName) {
83     this.filtersFileName = filtersFileName;
84   }
85
86   public FiltersForViewsConfig getViewsConfig() {
87     return viewsConfig;
88   }
89
90   public void setViewsConfig(FiltersForViewsConfig filtersMapEntity) {
91     this.viewsConfig = filtersMapEntity;
92   }
93
94   public FiltersDetailsConfig getFiltersConfig() {
95     return filtersConfig;
96   }
97   
98   public UiFilterConfig getFilterById(String filterId) {
99     for ( UiFilterConfig filter : filtersConfig.getFilters()) {
100       if ( filter.getFilterId().equals(filterId)) {
101         return filter;
102       }
103     }
104     
105     return null;
106   }
107   
108   public void setFiltersConfig(FiltersDetailsConfig filtersConfig) {
109     this.filtersConfig = filtersConfig;
110   }
111
112   public FiltersDetailsConfig readUiFiltersConfig() {
113     ObjectMapper mapper = new ObjectMapper();
114     FiltersDetailsConfig filtersConfig = null;
115     try{
116       filtersConfig = mapper.readValue(new File(this.getFiltersFileName()), FiltersDetailsConfig.class);
117     } catch (Exception e){
118       LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, SparkyConstants.getConfigPath(this.getFiltersFileName()));
119     }
120
121     return filtersConfig;
122   }
123
124   public FiltersForViewsConfig readUiViewsConfig() {
125     ObjectMapper mapper = new ObjectMapper();
126     FiltersForViewsConfig viewsConfig = null;
127     
128     try {
129       viewsConfig = mapper.readValue(new File(this.getFilterMappingsFileName()), FiltersForViewsConfig.class);
130     } catch (Exception e){
131       LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, SparkyConstants.getConfigPath(this.getFilterMappingsFileName()));
132     }
133
134     return viewsConfig;
135   }
136 }
137