2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2019 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.sa.rest;
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
27 import java.util.concurrent.atomic.AtomicBoolean;
28 import org.onap.aai.sa.searchdbabstraction.util.SearchDbConstants;
31 public class SettingConfiguration {
34 * Indicates whether or not we have imported the filter and analyzer configurations.
36 private AtomicBoolean configured = new AtomicBoolean(false);
39 * A json format string which is readable by Elastic Search and defines all of the custom filters and analyzers that
40 * we need Elastic Search to know about.
42 private String settings;
44 public void init(String settingConfigFile) {
46 if (configured.compareAndSet(false, true)) {
48 Path path = Paths.get(settingConfigFile);
49 settings = new String(Files.readAllBytes(path));
51 // Remove the enclosing brackets from the json blob.
52 settings = settings.replaceFirst("\\{", "");
53 settings = settings.substring(0, settings.lastIndexOf("}"));
54 } catch (IOException e) {
55 // It is valid not to have a settings file.
63 * Returns the set of pre-configured settings.
67 public String getSettings() {
68 init(SearchDbConstants.SDB_SETTINGS_CONFIG_FILE);
72 public String getSettingsWithAnalysis(AnalysisConfiguration analysisConfig) {
73 String ac = analysisConfig.getEsIndexSettings();
74 StringBuilder sb = new StringBuilder();
75 sb.append(ac.substring(0, ac.lastIndexOf("}")));
77 if (!getSettings().trim().isEmpty()) {
78 sb.append(", " + getSettings());