|
6 | 6 | import com.xatkit.core.recognition.processor.InputPreProcessor; |
7 | 7 | import com.xatkit.core.recognition.processor.IntentPostProcessor; |
8 | 8 | import com.xatkit.core.recognition.regex.RegExIntentRecognitionProvider; |
| 9 | +import com.xatkit.core.server.XatkitServer; |
9 | 10 | import com.xatkit.util.Loader; |
10 | 11 | import fr.inria.atlanmod.commons.log.Log; |
11 | 12 | import lombok.NonNull; |
@@ -38,19 +39,20 @@ private IntentRecognitionProviderFactory() { |
38 | 39 | } |
39 | 40 |
|
40 | 41 | /** |
41 | | - * The database model that will be used for this instance of Xatkit. |
| 42 | + * The database that will be used by this instance of Xatkit to store logs. |
42 | 43 | * <p> |
43 | | - * This property is optional, and it's default value is set to "MAPDB" if not specified |
| 44 | + * If this property is not set the bot won't use logging. |
| 45 | + * <p> |
| 46 | + * The value of this property is the fully-qualified name of the {@link RecognitionMonitor} subclass to |
| 47 | + * instantiate. Libraries providing such implementations typically provide a constant value for that. |
44 | 48 | */ |
45 | | - public static final String DATABASE_MODEL_KEY = "xatkit.database.model"; |
| 49 | + public static final String LOGS_DATABASE = "xatkit.logs.database"; |
46 | 50 |
|
47 | 51 | /** |
48 | 52 | * The default value for xatkit.database.model in case it's not specified in the properties file. |
49 | 53 | */ |
50 | 54 | public static final String DATABASE_MODEL_MAPDB = "mapdb"; |
51 | 55 |
|
52 | | - public static final String DATABASE_MODEL_INFLUXDB = "influxdb"; |
53 | | - |
54 | 56 | public static final String DATABASE_MODEL_POSTGRESQL = "postgresql"; |
55 | 57 |
|
56 | 58 | public static final String DEFAULT_DATABASE_MODEL = DATABASE_MODEL_MAPDB; |
@@ -120,16 +122,17 @@ public static IntentRecognitionProvider getIntentRecognitionProvider(@NonNull Xa |
120 | 122 |
|
121 | 123 | IntentRecognitionProvider provider; |
122 | 124 |
|
123 | | - if(baseConfiguration.containsKey(INTENT_PROVIDER_KEY)) { |
| 125 | + if (baseConfiguration.containsKey(INTENT_PROVIDER_KEY)) { |
124 | 126 | try { |
125 | 127 | String providerClassName = baseConfiguration.getString(INTENT_PROVIDER_KEY); |
126 | | - Class<? extends IntentRecognitionProvider> providerClass = (Class<? extends IntentRecognitionProvider>) Class.forName(providerClassName); |
| 128 | + Class<? extends IntentRecognitionProvider> providerClass = |
| 129 | + (Class<? extends IntentRecognitionProvider>) Class.forName(providerClassName); |
127 | 130 | Constructor<? extends IntentRecognitionProvider> providerConstructor = |
128 | 131 | providerClass.getConstructor(EventDefinitionRegistry.class, Configuration.class, |
129 | 132 | RecognitionMonitor.class); |
130 | 133 | provider = providerConstructor.newInstance(xatkitBot.getEventDefinitionRegistry(), baseConfiguration, |
131 | 134 | recognitionMonitor); |
132 | | - } catch(ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | |
| 135 | + } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | |
133 | 136 | IllegalAccessException e) { |
134 | 137 | throw new RuntimeException(e); |
135 | 138 | } |
@@ -176,27 +179,25 @@ private static RecognitionMonitor getRecognitionMonitor(XatkitBot xatkitBot, |
176 | 179 | */ |
177 | 180 | RecognitionMonitor monitor = null; |
178 | 181 | if (configuration.isEnableRecognitionAnalytics()) { |
179 | | - if (configuration.getBaseConfiguration().getString(DATABASE_MODEL_KEY, DEFAULT_DATABASE_MODEL) |
180 | | - .toLowerCase().equals(DATABASE_MODEL_INFLUXDB)) { |
181 | | - Log.info("Using InfluxDB to store monitoring data"); |
182 | | - monitor = new RecognitionMonitorInflux(xatkitBot.getXatkitServer(), |
183 | | - configuration.getBaseConfiguration()); |
184 | | - } else if (configuration.getBaseConfiguration().getString(DATABASE_MODEL_KEY) |
185 | | - .toLowerCase().equals(DATABASE_MODEL_POSTGRESQL)) { |
| 182 | + if (configuration.getBaseConfiguration().containsKey(LOGS_DATABASE)) { |
186 | 183 | try { |
187 | | - monitor = new RecognitionMonitorPostgreSQL(xatkitBot.getXatkitServer(), |
| 184 | + String databaseClassName = configuration.getBaseConfiguration().getString(LOGS_DATABASE); |
| 185 | + Class<? extends RecognitionMonitor> databaseClass = |
| 186 | + (Class<? extends RecognitionMonitor>) Class.forName(databaseClassName); |
| 187 | + Constructor<? extends RecognitionMonitor> databaseConstructor = |
| 188 | + databaseClass.getConstructor(XatkitServer.class, Configuration.class); |
| 189 | + monitor = databaseConstructor.newInstance(xatkitBot.getXatkitServer(), |
188 | 190 | configuration.getBaseConfiguration()); |
189 | | - } catch (Exception e) { |
190 | | - throw new RuntimeException("Error creating the PostgreSQL monitoring, see the exception for " |
191 | | - + "details ", e); |
| 191 | + } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | |
| 192 | + IllegalAccessException e) { |
| 193 | + throw new RuntimeException(e); |
192 | 194 | } |
193 | | - |
194 | | - |
195 | 195 | } else { |
196 | | - Log.info("Using MapDB to store monitoring data"); |
197 | | - monitor = new RecognitionMonitorMapDB(xatkitBot.getXatkitServer(), |
198 | | - configuration.getBaseConfiguration()); |
| 196 | + Log.error("Analytics are enabled but no database provided for storing logs. Please provide a value " |
| 197 | + + "for {0}", LOGS_DATABASE); |
199 | 198 | } |
| 199 | + } else { |
| 200 | + Log.debug("Analytics are disabled"); |
200 | 201 | } |
201 | 202 | return monitor; |
202 | 203 | } |
|
0 commit comments