2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.sparky.search.filters.config;
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;
30 import com.fasterxml.jackson.databind.ObjectMapper;
32 public class FiltersConfig {
34 private static final Logger LOG = LoggerFactory.getInstance().getLogger(FiltersConfig.class);
36 private String filtersFileName;
38 private String filterMappingsFileName;
40 private FiltersForViewsConfig viewsConfig;
42 private FiltersDetailsConfig filtersConfig;
45 * Instantiates a new UiViewFilterConfig.
47 public FiltersConfig() {
51 public FiltersConfig(String filtersFileName, String filterMappingsFileName) {
52 this.filtersFileName = filtersFileName;
53 this.filterMappingsFileName = filterMappingsFileName;
55 viewsConfig = this.readUiViewsConfig();
56 filtersConfig = this.readUiFiltersConfig();
62 private void initializeFilters() {
63 filtersFileName = SparkyConstants.FILTER_LIST_FILE_DEFAULT;
64 filterMappingsFileName = SparkyConstants.FILTER_MAPPING_FILE_DEFAULT;
66 viewsConfig = this.readUiViewsConfig();
67 filtersConfig = this.readUiFiltersConfig();
70 public String getFilterMappingsFileName() {
71 return filterMappingsFileName;
74 public void setFilterMappingsFileName(String filterMappingsFileName) {
75 this.filterMappingsFileName = filterMappingsFileName;
78 public String getFiltersFileName() {
79 return filtersFileName;
82 public void setFiltersFileName(String filtersFileName) {
83 this.filtersFileName = filtersFileName;
86 public FiltersForViewsConfig getViewsConfig() {
90 public void setViewsConfig(FiltersForViewsConfig filtersMapEntity) {
91 this.viewsConfig = filtersMapEntity;
94 public FiltersDetailsConfig getFiltersConfig() {
98 public UiFilterConfig getFilterById(String filterId) {
99 for ( UiFilterConfig filter : filtersConfig.getFilters()) {
100 if ( filter.getFilterId().equals(filterId)) {
108 public void setFiltersConfig(FiltersDetailsConfig filtersConfig) {
109 this.filtersConfig = filtersConfig;
112 public FiltersDetailsConfig readUiFiltersConfig() {
113 ObjectMapper mapper = new ObjectMapper();
114 FiltersDetailsConfig filtersConfig = null;
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()));
121 return filtersConfig;
124 public FiltersForViewsConfig readUiViewsConfig() {
125 ObjectMapper mapper = new ObjectMapper();
126 FiltersForViewsConfig viewsConfig = null;
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()));