Adding back-end support for UI filters
[aai/sparky-be.git] / src / main / java / org / onap / aai / 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.onap.aai.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.onap.aai.sparky.util.ConfigHelper;
32 import org.onap.aai.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 =
40       "elasticsearch.autosuggestIndexname:SearchServiceWrapper,elasticsearch.indexName:VnfSearchService";
41
42   private Map<String, String> searchIndexToSearchService;
43
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;
55
56
57   private SuggestionConfig() {}
58
59   /**
60    * Returns initialized instance as per singleton pattern.
61    * 
62    * @return initialized SuggestionConfig instance
63    */
64   public static SuggestionConfig getConfig() {
65     if (config == null) {
66       config = new SuggestionConfig();
67       config.initializeConfigProperties();
68     }
69     return config;
70   }
71
72   public void initializeConfigProperties() {
73
74     Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
75     Properties suggestionProps = ConfigHelper.getConfigWithPrefix("suggestion", props);
76
77     String indexSearchMapper = suggestionProps.getProperty("routing", INDEX_SEARCH_MAPPER_DEFAULT);
78     String[] indexesToSearchClassesArray = indexSearchMapper.split(",");
79     searchIndexToSearchService = new HashMap<String, String>();
80     for (String pair : indexesToSearchClassesArray) {
81       String[] subPair = pair.split(":");
82       searchIndexToSearchService.put(subPair[0], subPair[1]);
83     }
84
85     defaultPairingValue =
86         suggestionProps.getProperty("pairing.default.value", DEFAULT_PAIRING_DEFAULT_VALUE);
87     String calledValue =
88         suggestionProps.getProperty("pairing.called.value", CALLED_PAIRING_VALUE_DEFAULT);
89     String[] calledPairingArray =
90         suggestionProps.getProperty("pairing.called.key", CALLED_PAIRING_KEY_DEFAULT).split(",");
91     pairingList = new HashMap<String, String>();
92     for (String calledField : calledPairingArray) {
93       pairingList.put(calledField, calledValue);
94     }
95
96     this.conjunctionForAt =
97         suggestionProps.getProperty("pairing.at.value", AT_PAIRING_VALUE_DEFAULT);
98     String[] atPairingArray =
99         suggestionProps.getProperty("pairing.at.key", AT_PAIRING_KEY_DEFAULT).split(",");
100     for (String atField : atPairingArray) {
101       pairingList.put(atField, conjunctionForAt);
102     }
103
104     stopWords = Arrays.asList(suggestionProps.getProperty("stopwords", "").split(","));
105
106   }
107
108   public void setSearchIndexToSearchService(Map<String, String> searchIndexToSearchService) {
109     this.searchIndexToSearchService = searchIndexToSearchService;
110   }
111
112   public Map<String, String> getSearchIndexToSearchService() {
113     return searchIndexToSearchService;
114   }
115
116   public Collection<String> getStopWords() {
117     return stopWords;
118   }
119
120   public void setStopWords(Collection<String> stopWords) {
121     this.stopWords = stopWords;
122   }
123
124   public Map<String, String> getPairingList() {
125     return pairingList;
126   }
127
128   public void setPairingList(Map<String, String> pairingList) {
129     this.pairingList = pairingList;
130   }
131
132   public String getDefaultPairingValue() {
133     return defaultPairingValue;
134   }
135
136   public void setDefaultPairingValue(String defaultPairingValue) {
137     this.defaultPairingValue = defaultPairingValue;
138   }
139
140   public String getConjunctionForAt() {
141     return conjunctionForAt;
142   }
143
144   public void setConjunctionForAt(String conjunctionForAt) {
145     this.conjunctionForAt = conjunctionForAt;
146   }
147
148
149 }