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.config;
25 import java.util.Arrays;
26 import java.util.Collection;
27 import java.util.HashMap;
29 import java.util.Properties;
31 import org.onap.aai.sparky.util.ConfigHelper;
32 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
34 public class SuggestionConfig {
35 public static final String CONFIG_FILE =
36 TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "suggestive-search.properties";
38 private static SuggestionConfig config;
39 private static final String INDEX_SEARCH_MAPPER_DEFAULT =
40 "elasticsearch.autosuggestIndexname:SearchServiceWrapper,elasticsearch.indexName:VnfSearchService";
42 private Map<String, String> searchIndexToSearchService;
44 private static final String CALLED_PAIRING_KEY_DEFAULT =
45 "volume-group-id,volume-group-name,physical-location-id,data-center-code,complex-name,tenant-id,tenant-name,vserver-id,vserver-name,vserver-name2,hostname,pserver-name2,pserver-id,global-customer-id,subscriber-name,service-instance-id,service-instance-name,link-name,vpn-id,vpn-name,vpe-id,vnf-id,vnf-name,vnf-name2,vnfc-name,network-id,network-name,network-policy-id,vf-module-id,vf-module-name,vnf-id2,pnf-name,circuit-id";
46 private static final String CALLED_PAIRING_VALUE_DEFAULT = "called";
47 private static final String AT_PAIRING_KEY_DEFAULT =
48 "street1,street2,postal-code,ipv4-oam-address,network-policy-fqdn";
49 private static final String AT_PAIRING_VALUE_DEFAULT = "at";
50 private static final String DEFAULT_PAIRING_DEFAULT_VALUE = "with";
51 private String conjunctionForAt;
52 Map<String, String> pairingList;
53 private Collection<String> stopWords;
54 private String defaultPairingValue;
57 public SuggestionConfig() {}
60 * Returns initialized instance as per singleton pattern.
62 * @return initialized SuggestionConfig instance
64 public static SuggestionConfig getConfig() {
66 config = new SuggestionConfig();
67 config.initializeConfigProperties();
72 public static void setConfig(SuggestionConfig config) {
73 SuggestionConfig.config = config;
76 public void initializeConfigProperties() {
78 Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
79 Properties suggestionProps = ConfigHelper.getConfigWithPrefix("suggestion", props);
81 String indexSearchMapper = suggestionProps.getProperty("routing", INDEX_SEARCH_MAPPER_DEFAULT);
82 String[] indexesToSearchClassesArray = indexSearchMapper.split(",");
83 searchIndexToSearchService = new HashMap<String, String>();
84 for (String pair : indexesToSearchClassesArray) {
85 String[] subPair = pair.split(":");
86 searchIndexToSearchService.put(subPair[0], subPair[1]);
90 suggestionProps.getProperty("pairing.default.value", DEFAULT_PAIRING_DEFAULT_VALUE);
92 suggestionProps.getProperty("pairing.called.value", CALLED_PAIRING_VALUE_DEFAULT);
93 String[] calledPairingArray =
94 suggestionProps.getProperty("pairing.called.key", CALLED_PAIRING_KEY_DEFAULT).split(",");
95 pairingList = new HashMap<String, String>();
96 for (String calledField : calledPairingArray) {
97 pairingList.put(calledField, calledValue);
100 this.conjunctionForAt =
101 suggestionProps.getProperty("pairing.at.value", AT_PAIRING_VALUE_DEFAULT);
102 String[] atPairingArray =
103 suggestionProps.getProperty("pairing.at.key", AT_PAIRING_KEY_DEFAULT).split(",");
104 for (String atField : atPairingArray) {
105 pairingList.put(atField, conjunctionForAt);
108 stopWords = Arrays.asList(suggestionProps.getProperty("stopwords", "").split(","));
112 public void setSearchIndexToSearchService(Map<String, String> searchIndexToSearchService) {
113 this.searchIndexToSearchService = searchIndexToSearchService;
116 public Map<String, String> getSearchIndexToSearchService() {
117 return searchIndexToSearchService;
120 public Collection<String> getStopWords() {
124 public void setStopWords(Collection<String> stopWords) {
125 this.stopWords = stopWords;
128 public Map<String, String> getPairingList() {
132 public void setPairingList(Map<String, String> pairingList) {
133 this.pairingList = pairingList;
136 public String getDefaultPairingValue() {
137 return defaultPairingValue;
140 public void setDefaultPairingValue(String defaultPairingValue) {
141 this.defaultPairingValue = defaultPairingValue;
144 public String getConjunctionForAt() {
145 return conjunctionForAt;
148 public void setConjunctionForAt(String conjunctionForAt) {
149 this.conjunctionForAt = conjunctionForAt;