Initial commit for AAI-UI(sparky-backend)
[aai/sparky-be.git] / src / main / java / org / openecomp / sparky / search / config / SuggestionConfig.java
1 /**
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25 package org.openecomp.sparky.search.config;
26
27 import java.util.Arrays;
28 import java.util.Collection;
29 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.Properties;
32
33 import org.openecomp.sparky.util.ConfigHelper;
34 import org.openecomp.sparky.viewandinspect.config.TierSupportUiConstants;
35
36 public class SuggestionConfig {
37   public static final String CONFIG_FILE =
38       TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "suggestive-search.properties";
39   
40   private static SuggestionConfig config;
41   private static final String INDEX_SEARCH_MAPPER_DEFAULT = "elasticsearch.autosuggestIndexname:SearchServiceWrapper,elasticsearch.indexName:VnfSearchService";
42   
43   private Map<String, String> searchIndexToSearchService;
44   
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;
54   
55   
56   private SuggestionConfig() {}
57
58   /**
59    * Returns initialized instance as per singleton pattern.
60    * 
61    * @return initialized SuggestionConfig instance
62    */
63   public static SuggestionConfig getConfig() {
64     if (config == null) {
65       config = new SuggestionConfig();
66       config.initializeConfigProperties();
67     }
68     return config;
69   }
70   
71   public void initializeConfigProperties() {
72     
73     Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
74     Properties suggestionProps = ConfigHelper.getConfigWithPrefix("suggestion", props);
75     
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]);
82     }
83     
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);
90     }
91     
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);
96     }
97     
98     stopWords = Arrays.asList(suggestionProps.getProperty("stopwords", "").split(","));
99     
100   }
101   
102   public void setSearchIndexToSearchService(Map<String, String> searchIndexToSearchService) {
103     this.searchIndexToSearchService = searchIndexToSearchService;
104   }
105
106   public Map<String, String> getSearchIndexToSearchService() {
107     return searchIndexToSearchService;
108   }
109   
110   public Collection<String> getStopWords() {
111     return stopWords;
112   }
113
114   public void setStopWords(Collection<String> stopWords) {
115     this.stopWords = stopWords;
116   }
117
118   public Map<String, String> getPairingList() {
119     return pairingList;
120   }
121
122   public void setPairingList(Map<String, String> pairingList) {
123     this.pairingList = pairingList;
124   }
125
126   public String getDefaultPairingValue() {
127     return defaultPairingValue;
128   }
129
130   public void setDefaultPairingValue(String defaultPairingValue) {
131     this.defaultPairingValue = defaultPairingValue;
132   }
133
134   public String getConjunctionForAt() {
135     return conjunctionForAt;
136   }
137
138   public void setConjunctionForAt(String conjunctionForAt) {
139     this.conjunctionForAt = conjunctionForAt;
140   }
141
142
143 }