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.openecomp.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.openecomp.sparky.util.ConfigHelper;
32 import org.openecomp.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 = "elasticsearch.autosuggestIndexname:SearchServiceWrapper,elasticsearch.indexName:VnfSearchService";
41 private Map<String, String> searchIndexToSearchService;
43 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";
44 private static final String CALLED_PAIRING_VALUE_DEFAULT = "called";
45 private static final String AT_PAIRING_KEY_DEFAULT = "street1,street2,postal-code,ipv4-oam-address,network-policy-fqdn";
46 private static final String AT_PAIRING_VALUE_DEFAULT = "at";
47 private static final String DEFAULT_PAIRING_DEFAULT_VALUE = "with";
48 private String conjunctionForAt;
49 Map<String, String> pairingList;
50 private Collection<String> stopWords;
51 private String defaultPairingValue;
54 private SuggestionConfig() {}
57 * Returns initialized instance as per singleton pattern.
59 * @return initialized SuggestionConfig instance
61 public static SuggestionConfig getConfig() {
63 config = new SuggestionConfig();
64 config.initializeConfigProperties();
69 public void initializeConfigProperties() {
71 Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
72 Properties suggestionProps = ConfigHelper.getConfigWithPrefix("suggestion", props);
74 String indexSearchMapper = suggestionProps.getProperty("routing", INDEX_SEARCH_MAPPER_DEFAULT);
75 String[] indexesToSearchClassesArray = indexSearchMapper.split(",");
76 searchIndexToSearchService = new HashMap<String, String>();
77 for (String pair : indexesToSearchClassesArray) {
78 String[] subPair = pair.split(":");
79 searchIndexToSearchService.put(subPair[0], subPair[1]);
82 defaultPairingValue=suggestionProps.getProperty("pairing.default.value", DEFAULT_PAIRING_DEFAULT_VALUE);
83 String calledValue = suggestionProps.getProperty("pairing.called.value", CALLED_PAIRING_VALUE_DEFAULT);
84 String[] calledPairingArray = suggestionProps.getProperty("pairing.called.key", CALLED_PAIRING_KEY_DEFAULT).split(",");
85 pairingList = new HashMap<String, String>();
86 for(String calledField: calledPairingArray){
87 pairingList.put(calledField, calledValue);
90 this.conjunctionForAt = suggestionProps.getProperty("pairing.at.value", AT_PAIRING_VALUE_DEFAULT);
91 String[] atPairingArray = suggestionProps.getProperty("pairing.at.key", AT_PAIRING_KEY_DEFAULT).split(",");
92 for(String atField: atPairingArray){
93 pairingList.put(atField, conjunctionForAt);
96 stopWords = Arrays.asList(suggestionProps.getProperty("stopwords", "").split(","));
100 public void setSearchIndexToSearchService(Map<String, String> searchIndexToSearchService) {
101 this.searchIndexToSearchService = searchIndexToSearchService;
104 public Map<String, String> getSearchIndexToSearchService() {
105 return searchIndexToSearchService;
108 public Collection<String> getStopWords() {
112 public void setStopWords(Collection<String> stopWords) {
113 this.stopWords = stopWords;
116 public Map<String, String> getPairingList() {
120 public void setPairingList(Map<String, String> pairingList) {
121 this.pairingList = pairingList;
124 public String getDefaultPairingValue() {
125 return defaultPairingValue;
128 public void setDefaultPairingValue(String defaultPairingValue) {
129 this.defaultPairingValue = defaultPairingValue;
132 public String getConjunctionForAt() {
133 return conjunctionForAt;
136 public void setConjunctionForAt(String conjunctionForAt) {
137 this.conjunctionForAt = conjunctionForAt;