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.openecomp.sparky.search.config;
27 import java.util.Arrays;
28 import java.util.Collection;
29 import java.util.HashMap;
31 import java.util.Properties;
33 import org.openecomp.sparky.util.ConfigHelper;
34 import org.openecomp.sparky.viewandinspect.config.TierSupportUiConstants;
36 public class SuggestionConfig {
37 public static final String CONFIG_FILE =
38 TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "suggestive-search.properties";
40 private static SuggestionConfig config;
41 private static final String INDEX_SEARCH_MAPPER_DEFAULT = "elasticsearch.autosuggestIndexname:SearchServiceWrapper,elasticsearch.indexName:VnfSearchService";
43 private Map<String, String> searchIndexToSearchService;
45 private static final String CALLED_PAIRING_KEY_DEFAULT = "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 = "street1,street2,postal-code,ipv4-oam-address,network-policy-fqdn";
48 private static final String AT_PAIRING_VALUE_DEFAULT = "at";
49 private static final String DEFAULT_PAIRING_DEFAULT_VALUE = "with";
50 private String conjunctionForAt;
51 Map<String, String> pairingList;
52 private Collection<String> stopWords;
53 private String defaultPairingValue;
56 private SuggestionConfig() {}
59 * Returns initialized instance as per singleton pattern.
61 * @return initialized SuggestionConfig instance
63 public static SuggestionConfig getConfig() {
65 config = new SuggestionConfig();
66 config.initializeConfigProperties();
71 public void initializeConfigProperties() {
73 Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
74 Properties suggestionProps = ConfigHelper.getConfigWithPrefix("suggestion", props);
76 String indexSearchMapper = suggestionProps.getProperty("routing", INDEX_SEARCH_MAPPER_DEFAULT);
77 String[] indexesToSearchClassesArray = indexSearchMapper.split(",");
78 searchIndexToSearchService = new HashMap<String, String>();
79 for (String pair : indexesToSearchClassesArray) {
80 String[] subPair = pair.split(":");
81 searchIndexToSearchService.put(subPair[0], subPair[1]);
84 defaultPairingValue=suggestionProps.getProperty("pairing.default.value", DEFAULT_PAIRING_DEFAULT_VALUE);
85 String calledValue = suggestionProps.getProperty("pairing.called.value", CALLED_PAIRING_VALUE_DEFAULT);
86 String[] calledPairingArray = suggestionProps.getProperty("pairing.called.key", CALLED_PAIRING_KEY_DEFAULT).split(",");
87 pairingList = new HashMap<String, String>();
88 for(String calledField: calledPairingArray){
89 pairingList.put(calledField, calledValue);
92 this.conjunctionForAt = suggestionProps.getProperty("pairing.at.value", AT_PAIRING_VALUE_DEFAULT);
93 String[] atPairingArray = suggestionProps.getProperty("pairing.at.key", AT_PAIRING_KEY_DEFAULT).split(",");
94 for(String atField: atPairingArray){
95 pairingList.put(atField, conjunctionForAt);
98 stopWords = Arrays.asList(suggestionProps.getProperty("stopwords", "").split(","));
102 public void setSearchIndexToSearchService(Map<String, String> searchIndexToSearchService) {
103 this.searchIndexToSearchService = searchIndexToSearchService;
106 public Map<String, String> getSearchIndexToSearchService() {
107 return searchIndexToSearchService;
110 public Collection<String> getStopWords() {
114 public void setStopWords(Collection<String> stopWords) {
115 this.stopWords = stopWords;
118 public Map<String, String> getPairingList() {
122 public void setPairingList(Map<String, String> pairingList) {
123 this.pairingList = pairingList;
126 public String getDefaultPairingValue() {
127 return defaultPairingValue;
130 public void setDefaultPairingValue(String defaultPairingValue) {
131 this.defaultPairingValue = defaultPairingValue;
134 public String getConjunctionForAt() {
135 return conjunctionForAt;
138 public void setConjunctionForAt(String conjunctionForAt) {
139 this.conjunctionForAt = conjunctionForAt;