Merge "Fix Blocker/Critical sonar issues"
[aai/sparky-be.git] / src / main / java / org / openecomp / sparky / search / config / SuggestionConfig.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.openecomp.sparky.search.config;
24
25 import java.util.Arrays;
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.Properties;
30
31 import org.openecomp.sparky.util.ConfigHelper;
32 import org.openecomp.sparky.viewandinspect.config.TierSupportUiConstants;
33
34 public class SuggestionConfig {
35   public static final String CONFIG_FILE =
36       TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "suggestive-search.properties";
37   
38   private static SuggestionConfig config;
39   private static final String INDEX_SEARCH_MAPPER_DEFAULT = "elasticsearch.autosuggestIndexname:SearchServiceWrapper,elasticsearch.indexName:VnfSearchService";
40   
41   private Map<String, String> searchIndexToSearchService;
42   
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;
52   
53   
54   private SuggestionConfig() {}
55
56   /**
57    * Returns initialized instance as per singleton pattern.
58    * 
59    * @return initialized SuggestionConfig instance
60    */
61   public static SuggestionConfig getConfig() {
62     if (config == null) {
63       config = new SuggestionConfig();
64       config.initializeConfigProperties();
65     }
66     return config;
67   }
68   
69   public void initializeConfigProperties() {
70     
71     Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
72     Properties suggestionProps = ConfigHelper.getConfigWithPrefix("suggestion", props);
73     
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]);
80     }
81     
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);
88     }
89     
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);
94     }
95     
96     stopWords = Arrays.asList(suggestionProps.getProperty("stopwords", "").split(","));
97     
98   }
99   
100   public void setSearchIndexToSearchService(Map<String, String> searchIndexToSearchService) {
101     this.searchIndexToSearchService = searchIndexToSearchService;
102   }
103
104   public Map<String, String> getSearchIndexToSearchService() {
105     return searchIndexToSearchService;
106   }
107   
108   public Collection<String> getStopWords() {
109     return stopWords;
110   }
111
112   public void setStopWords(Collection<String> stopWords) {
113     this.stopWords = stopWords;
114   }
115
116   public Map<String, String> getPairingList() {
117     return pairingList;
118   }
119
120   public void setPairingList(Map<String, String> pairingList) {
121     this.pairingList = pairingList;
122   }
123
124   public String getDefaultPairingValue() {
125     return defaultPairingValue;
126   }
127
128   public void setDefaultPairingValue(String defaultPairingValue) {
129     this.defaultPairingValue = defaultPairingValue;
130   }
131
132   public String getConjunctionForAt() {
133     return conjunctionForAt;
134   }
135
136   public void setConjunctionForAt(String conjunctionForAt) {
137     this.conjunctionForAt = conjunctionForAt;
138   }
139
140
141 }