/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
+ * ============LICENSE_START===================================================
+ * SPARKY (AAI UI service)
+ * ============================================================================
+ * Copyright © 2017 AT&T Intellectual Property.
+ * Copyright © 2017 Amdocs
+ * All rights reserved.
+ * ============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
+ * ============LICENSE_END=====================================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
*/
package org.onap.aai.sparky.search.filters.config;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.sparky.config.SparkyResourceLoader;
import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
import com.fasterxml.jackson.databind.ObjectMapper;
private String filtersFileName;
- private String filterMappingsFileName;
+ private String viewsFileName;
private FiltersForViewsConfig viewsConfig;
private FiltersDetailsConfig filtersConfig;
-
- /**
- * Instantiates a new UiViewFilterConfig.
- */
+
+ private SparkyResourceLoader resourceLoader;
+
public FiltersConfig() {
- initializeFilters();
+ //exposed for testing
}
- public FiltersConfig(String filtersFileName, String filterMappingsFileName) {
+ public FiltersConfig(String filtersFileName, String viewsFileName, SparkyResourceLoader resourceLoader) {
this.filtersFileName = filtersFileName;
- this.filterMappingsFileName = filterMappingsFileName;
-
- viewsConfig = this.readUiViewsConfig();
- filtersConfig = this.readUiFiltersConfig();
- }
+ this.viewsFileName = viewsFileName;
+ this.resourceLoader = resourceLoader;
+ initializeFilters();
+ }
+
/**
* Initialize config.
*/
private void initializeFilters() {
- filtersFileName = SparkyConstants.FILTER_LIST_FILE_DEFAULT;
- filterMappingsFileName = SparkyConstants.FILTER_MAPPING_FILE_DEFAULT;
-
viewsConfig = this.readUiViewsConfig();
filtersConfig = this.readUiFiltersConfig();
}
- public String getFilterMappingsFileName() {
- return filterMappingsFileName;
+ public String getViewsFileName() {
+ return viewsFileName;
}
- public void setFilterMappingsFileName(String filterMappingsFileName) {
- this.filterMappingsFileName = filterMappingsFileName;
+ public void setViewsFileName(String viewsFileName) {
+ this.viewsFileName = viewsFileName;
}
public String getFiltersFileName() {
public FiltersDetailsConfig readUiFiltersConfig() {
ObjectMapper mapper = new ObjectMapper();
FiltersDetailsConfig filtersConfig = null;
- try{
- filtersConfig = mapper.readValue(new File(this.getFiltersFileName()), FiltersDetailsConfig.class);
+ try{
+ filtersConfig = mapper.readValue(resourceLoader.getResourceAsFile(this.getFiltersFileName(),true), FiltersDetailsConfig.class);
} catch (Exception e){
- LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, SparkyConstants.getConfigPath(this.getFiltersFileName()));
+ LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, this.getFiltersFileName());
}
return filtersConfig;
FiltersForViewsConfig viewsConfig = null;
try {
- viewsConfig = mapper.readValue(new File(this.getFilterMappingsFileName()), FiltersForViewsConfig.class);
+ viewsConfig = mapper.readValue(resourceLoader.getResourceAsFile(this.getViewsFileName(),true), FiltersForViewsConfig.class);
} catch (Exception e){
- LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, SparkyConstants.getConfigPath(this.getFilterMappingsFileName()));
+ LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, this.getViewsFileName());
}
return viewsConfig;
}
+
+ public void initializeFiltersDetailsConfig(File filtersFile) {
+ ObjectMapper mapper = new ObjectMapper();
+ try{
+ this.filtersConfig = mapper.readValue(filtersFile, FiltersDetailsConfig.class);
+ } catch (Exception e){
+ LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, filtersFile.getAbsolutePath());
+ }
+ }
+
+ public void initializeFiltersForViewsConfig(File viewsFile) {
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ this.viewsConfig = mapper.readValue(viewsFile, FiltersForViewsConfig.class);
+ } catch (Exception e){
+ LOG.error(AaiUiMsgs.ERROR_READING_JSON_SCHEMA, viewsFile.getAbsolutePath());
+ }
+
+ }
+
}