2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.sparky.search.filters.config;
29 import org.onap.aai.cl.api.Logger;
30 import org.onap.aai.cl.eelf.LoggerFactory;
31 import org.onap.aai.sparky.config.SparkyResourceLoader;
32 import org.onap.aai.sparky.logging.AaiUiMsgs;
34 import com.fasterxml.jackson.databind.ObjectMapper;
36 public class FiltersConfig {
38 private static final Logger LOG = LoggerFactory.getInstance().getLogger(FiltersConfig.class);
40 private String filtersFileName;
42 private String viewsFileName;
44 private FiltersForViewsConfig viewsConfig;
46 private FiltersDetailsConfig filtersConfig;
48 private SparkyResourceLoader resourceLoader;
50 public FiltersConfig() {
54 public FiltersConfig(String filtersFileName, String viewsFileName, SparkyResourceLoader resourceLoader) {
55 this.filtersFileName = filtersFileName;
56 this.viewsFileName = viewsFileName;
57 this.resourceLoader = resourceLoader;
65 private void initializeFilters() {
66 viewsConfig = this.readUiViewsConfig();
67 filtersConfig = this.readUiFiltersConfig();
70 public String getViewsFileName() {
74 public void setViewsFileName(String viewsFileName) {
75 this.viewsFileName = viewsFileName;
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(resourceLoader.getResourceAsFile(this.getFiltersFileName(),true), FiltersDetailsConfig.class);
117 } catch (Exception e){
118 LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, this.getFiltersFileName());
121 return filtersConfig;
124 public FiltersForViewsConfig readUiViewsConfig() {
125 ObjectMapper mapper = new ObjectMapper();
126 FiltersForViewsConfig viewsConfig = null;
129 viewsConfig = mapper.readValue(resourceLoader.getResourceAsFile(this.getViewsFileName(),true), FiltersForViewsConfig.class);
130 } catch (Exception e){
131 LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, this.getViewsFileName());
137 public void initializeFiltersDetailsConfig(File filtersFile) {
138 ObjectMapper mapper = new ObjectMapper();
140 this.filtersConfig = mapper.readValue(filtersFile, FiltersDetailsConfig.class);
141 } catch (Exception e){
142 LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, filtersFile.getAbsolutePath());
146 public void initializeFiltersForViewsConfig(File viewsFile) {
147 ObjectMapper mapper = new ObjectMapper();
150 this.viewsConfig = mapper.readValue(viewsFile, FiltersForViewsConfig.class);
151 } catch (Exception e){
152 LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, viewsFile.getAbsolutePath());