2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.search.filters.config;
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;
32 import com.fasterxml.jackson.databind.ObjectMapper;
34 public class FiltersConfig {
36 private static final Logger LOG = LoggerFactory.getInstance().getLogger(FiltersConfig.class);
38 private String filtersFileName;
40 private String filterMappingsFileName;
42 private FiltersForViewsConfig viewsConfig;
44 private FiltersDetailsConfig filtersConfig;
47 * Instantiates a new UiViewFilterConfig.
49 public FiltersConfig() {
53 public FiltersConfig(String filtersFileName, String filterMappingsFileName) {
54 this.filtersFileName = filtersFileName;
55 this.filterMappingsFileName = filterMappingsFileName;
57 viewsConfig = this.readUiViewsConfig();
58 filtersConfig = this.readUiFiltersConfig();
64 private void initializeFilters() {
65 filtersFileName = SparkyConstants.FILTER_LIST_FILE_DEFAULT;
66 filterMappingsFileName = SparkyConstants.FILTER_MAPPING_FILE_DEFAULT;
68 viewsConfig = this.readUiViewsConfig();
69 filtersConfig = this.readUiFiltersConfig();
72 public String getFilterMappingsFileName() {
73 return filterMappingsFileName;
76 public void setFilterMappingsFileName(String filterMappingsFileName) {
77 this.filterMappingsFileName = filterMappingsFileName;
80 public String getFiltersFileName() {
81 return filtersFileName;
84 public void setFiltersFileName(String filtersFileName) {
85 this.filtersFileName = filtersFileName;
88 public FiltersForViewsConfig getViewsConfig() {
92 public void setViewsConfig(FiltersForViewsConfig filtersMapEntity) {
93 this.viewsConfig = filtersMapEntity;
96 public FiltersDetailsConfig getFiltersConfig() {
100 public UiFilterConfig getFilterById(String filterId) {
101 for ( UiFilterConfig filter : filtersConfig.getFilters()) {
102 if ( filter.getFilterId().equals(filterId)) {
110 public void setFiltersConfig(FiltersDetailsConfig filtersConfig) {
111 this.filtersConfig = filtersConfig;
114 public FiltersDetailsConfig readUiFiltersConfig() {
115 ObjectMapper mapper = new ObjectMapper();
116 FiltersDetailsConfig filtersConfig = null;
118 filtersConfig = mapper.readValue(new File(this.getFiltersFileName()), FiltersDetailsConfig.class);
119 } catch (Exception e){
120 LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, SparkyConstants.getConfigPath(this.getFiltersFileName()));
123 return filtersConfig;
126 public FiltersForViewsConfig readUiViewsConfig() {
127 ObjectMapper mapper = new ObjectMapper();
128 FiltersForViewsConfig viewsConfig = null;
131 viewsConfig = mapper.readValue(new File(this.getFilterMappingsFileName()), FiltersForViewsConfig.class);
132 } catch (Exception e){
133 LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, SparkyConstants.getConfigPath(this.getFilterMappingsFileName()));