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.synchronizer.config.NetworkStatisticsConfig;
31 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
33 import com.fasterxml.jackson.databind.ObjectMapper;
35 public class FiltersConfig {
37 private static final Logger LOG = LoggerFactory.getInstance().getLogger(FiltersConfig.class);
39 private static FiltersConfig instance;
41 private String filtersFileName;
43 private String filterMappingsFileName;
45 private FiltersForViewsConfig viewsConfig;
47 private FiltersDetailsConfig filtersConfig;
49 private NetworkStatisticsConfig processorConfig;
51 public NetworkStatisticsConfig getProcessorConfig() {
52 return processorConfig;
55 public void setProcessorConfig(NetworkStatisticsConfig processorConfig) {
56 this.processorConfig = processorConfig;
59 public static FiltersConfig getInstance() {
60 if (instance == null) {
61 instance = new FiltersConfig();
62 instance.initializeFilters();
68 public static void setConfig(FiltersConfig config) {
69 FiltersConfig.instance = config;
73 * Instantiates a new UiViewFilterConfig.
75 private FiltersConfig() {}
80 private void initializeFilters() {
81 filtersFileName = TierSupportUiConstants.FILTER_LIST_FILE_DEFAULT;
82 filterMappingsFileName = TierSupportUiConstants.FILTER_MAPPING_FILE_DEFAULT;
84 viewsConfig = this.readUiViewsConfig();
85 filtersConfig = this.readUiFiltersConfig();
88 public String getFilterMappingsFileName() {
89 return filterMappingsFileName;
92 public void setFilterMappingsFileName(String filterMappingsFileName) {
93 this.filterMappingsFileName = filterMappingsFileName;
96 public String getFiltersFileName() {
97 return filtersFileName;
100 public void setFiltersFileName(String filtersFileName) {
101 this.filtersFileName = filtersFileName;
104 public FiltersForViewsConfig getViewsConfig() {
108 public void setViewsConfig(FiltersForViewsConfig filtersMapEntity) {
109 this.viewsConfig = filtersMapEntity;
112 public FiltersDetailsConfig getFiltersConfig() {
113 return filtersConfig;
116 public UiFilterConfig getFilterById(String filterId) {
117 for ( UiFilterConfig filter : filtersConfig.getFilters()) {
118 if ( filter.getFilterId().equals(filterId)) {
126 public void setFiltersConfig(FiltersDetailsConfig filtersConfig) {
127 this.filtersConfig = filtersConfig;
130 public FiltersDetailsConfig readUiFiltersConfig(){
131 ObjectMapper mapper = new ObjectMapper();
132 FiltersDetailsConfig filtersConfig = null;
134 filtersConfig = mapper.readValue(new File(this.getFiltersFileName()), FiltersDetailsConfig.class);
135 System.out.println(String.valueOf(filtersConfig));
136 } catch (Exception e){
137 LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, TierSupportUiConstants.getConfigPath(this.getFiltersFileName()));
140 return filtersConfig;
143 public FiltersForViewsConfig readUiViewsConfig(){
144 ObjectMapper mapper = new ObjectMapper();
145 FiltersForViewsConfig viewsConfig = null;
148 viewsConfig = mapper.readValue(new File(this.getFilterMappingsFileName()), FiltersForViewsConfig.class);
149 System.out.println(String.valueOf(viewsConfig));
150 } catch (Exception e){
151 LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, TierSupportUiConstants.getConfigPath(this.getFilterMappingsFileName()));