forked from searchisko/elasticsearch-river-remote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentWithCommentsIndexStructureBuilder.java
584 lines (514 loc) · 23.8 KB
/
DocumentWithCommentsIndexStructureBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
/*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
*/
package org.jboss.elasticsearch.river.remote;
import static org.elasticsearch.client.Requests.deleteRequest;
import static org.elasticsearch.client.Requests.indexRequest;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.query.FilterBuilder;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.jboss.elasticsearch.tools.content.StructuredContentPreprocessor;
/**
* Universal configurable implementation of component responsible to transform document data obtained from remote system
* call to the document stored in ElasticSearch index. Supports comment tied to document too.
*
* @author Vlastimil Elias (velias at redhat dot com)
*/
public class DocumentWithCommentsIndexStructureBuilder implements IDocumentIndexStructureBuilder {
private static final ESLogger logger = Loggers.getLogger(DocumentWithCommentsIndexStructureBuilder.class);
/**
* Name of River to be stored in document to mark indexing source
*/
protected String riverName;
/**
* Name of ElasticSearch index used to store issues
*/
protected String indexName;
/**
* Name of ElasticSearch type used to store issues into index
*/
protected String issueTypeName;
protected static final String CONFIG_FIELDS = "fields";
protected static final String CONFIG_FIELDS_REMOTEFIELD = "remote_field";
protected static final String CONFIG_FIELDS_VALUEFILTER = "value_filter";
protected static final String CONFIG_FILTERS = "value_filters";
protected static final String CONFIG_REMOTEFIELD_DOCUMENTID = "remote_field_document_id";
protected static final String CONFIG_REMOTEFIELD_UPDATED = "remote_field_updated";
protected static final String CONFIG_REMOTEFIELD_COMMENTS = "remote_field_comments";
protected static final String CONFIG_REMOTEFIELD_COMMENTID = "remote_field_comment_id";
protected static final String CONFIG_FIELDRIVERNAME = "field_river_name";
protected static final String CONFIG_FIELDSPACEKEY = "field_space_key";
protected static final String CONFIG_FIELDDOCUMENTID = "field_document_id";
protected static final String CONFIG_COMMENTMODE = "comment_mode";
protected static final String CONFIG_FIELDCOMMENTS = "field_comments";
protected static final String CONFIG_COMMENTTYPE = "comment_type";
protected static final String CONFIG_COMMENTFILEDS = "comment_fields";
/**
* Field in remote document data to get indexed document id from.
*/
protected String remoteDataFieldForDocumentId = null;
/**
* Field in remote document data to get indexed document last update timestamp from.
*/
protected String remoteDataFieldForUpdated = null;
/**
* Field in remote document data to get array of comments from.
*/
protected String remoteDataFieldForComments = null;
/**
* Field in remote document's comment structure to get comment id from. Is necessary if comment is indexed as
* standalone document.
*/
protected String remoteDataFieldForCommentId = null;
/**
* Fields configuration structure. Key is name of field in search index. Value is map of configurations for given
* index field containing <code>CONFIG_FIELDS_xx</code> constants as keys.
*/
protected Map<String, Map<String, String>> fieldsConfig;
/**
* Value filters configuration structure. Key is name of filter. Value is map of filter configurations to be used in
* {@link Utils#remapDataInMap(Map, Map)}.
*/
protected Map<String, Map<String, String>> filtersConfig;
/**
* Name of field in search index where river name is stored.
*/
protected String indexFieldForRiverName = null;
/**
* Name of field in search index where Space key is stored.
*/
protected String indexFieldForSpaceKey = null;
/**
* Name of field in search index where remote document unique identifier is stored.
*/
protected String indexFieldForRemoteDocumentId = null;
/**
* Issue comment indexing mode.
*/
protected CommentIndexingMode commentIndexingMode;
/**
* Name of field in search index issue document where array of comments is stored in case of
* {@link CommentIndexingMode#EMBEDDED}.
*/
protected String indexFieldForComments = null;
/**
* Name of ElasticSearch type used to store issues comments into index in case of
* {@link CommentIndexingMode#STANDALONE} or {@link CommentIndexingMode#CHILD}.
*/
protected String commentTypeName;
/**
* Fields configuration structure for comment document. Key is name of field in search index. Value is map of
* configurations for given index field containing <code>CONFIG_FIELDS_xx</code> constants as keys.
*/
protected Map<String, Map<String, String>> commentFieldsConfig;
/**
* List of data preprocessors used inside {@link #indexDocument(BulkRequestBuilder, String, Map)}.
*/
protected List<StructuredContentPreprocessor> issueDataPreprocessors = null;
/**
* Constructor for unit tests. Nothing is filled inside.
*/
protected DocumentWithCommentsIndexStructureBuilder() {
super();
}
/**
* Constructor.
*
* @param riverName name of ElasticSearch River instance this indexer is running inside to be stored in search index
* to identify indexed documents source.
* @param indexName name of ElasticSearch index used to store issues
* @param issueTypeName name of ElasticSearch type used to store issues into index
* @param settings map to load other structure builder settings from
* @throws SettingsException
*/
@SuppressWarnings("unchecked")
public DocumentWithCommentsIndexStructureBuilder(String riverName, String indexName, String issueTypeName,
Map<String, Object> settings) throws SettingsException {
super();
this.riverName = riverName;
this.indexName = indexName;
this.issueTypeName = issueTypeName;
if (settings != null) {
remoteDataFieldForDocumentId = Utils.trimToNull(XContentMapValues.nodeStringValue(
settings.get(CONFIG_REMOTEFIELD_DOCUMENTID), null));
remoteDataFieldForUpdated = Utils.trimToNull(XContentMapValues.nodeStringValue(
settings.get(CONFIG_REMOTEFIELD_UPDATED), null));
remoteDataFieldForComments = Utils.trimToNull(XContentMapValues.nodeStringValue(
settings.get(CONFIG_REMOTEFIELD_COMMENTS), null));
remoteDataFieldForCommentId = Utils.trimToNull(XContentMapValues.nodeStringValue(
settings.get(CONFIG_REMOTEFIELD_COMMENTID), null));
indexFieldForRiverName = XContentMapValues.nodeStringValue(settings.get(CONFIG_FIELDRIVERNAME), null);
indexFieldForSpaceKey = XContentMapValues.nodeStringValue(settings.get(CONFIG_FIELDSPACEKEY), null);
indexFieldForRemoteDocumentId = XContentMapValues.nodeStringValue(settings.get(CONFIG_FIELDDOCUMENTID), null);
filtersConfig = (Map<String, Map<String, String>>) settings.get(CONFIG_FILTERS);
fieldsConfig = (Map<String, Map<String, String>>) settings.get(CONFIG_FIELDS);
commentIndexingMode = CommentIndexingMode.parseConfiguration(XContentMapValues.nodeStringValue(
settings.get(CONFIG_COMMENTMODE), null));
indexFieldForComments = XContentMapValues.nodeStringValue(settings.get(CONFIG_FIELDCOMMENTS), null);
commentTypeName = XContentMapValues.nodeStringValue(settings.get(CONFIG_COMMENTTYPE), null);
commentFieldsConfig = (Map<String, Map<String, String>>) settings.get(CONFIG_COMMENTFILEDS);
}
loadDefaultsIfNecessary();
validateConfiguration();
}
private void loadDefaultsIfNecessary() {
Map<String, Object> settingsDefault = loadDefaultSettingsMapFromFile();
indexFieldForRiverName = loadDefaultStringIfNecessary(indexFieldForRiverName, CONFIG_FIELDRIVERNAME,
settingsDefault);
indexFieldForSpaceKey = loadDefaultStringIfNecessary(indexFieldForSpaceKey, CONFIG_FIELDSPACEKEY, settingsDefault);
indexFieldForRemoteDocumentId = loadDefaultStringIfNecessary(indexFieldForRemoteDocumentId, CONFIG_FIELDDOCUMENTID,
settingsDefault);
if (filtersConfig == null)
filtersConfig = new HashMap<String, Map<String, String>>();
if (commentIndexingMode == null) {
commentIndexingMode = CommentIndexingMode.parseConfiguration(XContentMapValues.nodeStringValue(
settingsDefault.get(CONFIG_COMMENTMODE), null));
}
}
private void validateConfiguration() {
validateConfigurationString(remoteDataFieldForDocumentId, "index/" + CONFIG_REMOTEFIELD_DOCUMENTID);
validateConfigurationString(remoteDataFieldForUpdated, "index/" + CONFIG_REMOTEFIELD_UPDATED);
validateConfigurationObject(filtersConfig, "index/value_filters");
validateConfigurationObject(fieldsConfig, "index/fields");
validateConfigurationString(indexFieldForRiverName, "index/field_river_name");
validateConfigurationString(indexFieldForSpaceKey, "index/field_space_key");
validateConfigurationString(indexFieldForRemoteDocumentId, "index/field_document_id");
validateConfigurationObject(commentIndexingMode, "index/comment_mode");
if (commentIndexingMode != CommentIndexingMode.NONE) {
validateConfigurationString(remoteDataFieldForComments, "index/" + CONFIG_REMOTEFIELD_COMMENTS);
validateConfigurationString(indexFieldForComments, "index/field_comments");
validateConfigurationObject(commentFieldsConfig, "index/comment_fields");
validateConfigurationFieldsStructure(commentFieldsConfig, "index/comment_fields");
if (commentIndexingMode.isExtraDocumentIndexed()) {
validateConfigurationString(commentTypeName, "index/comment_type");
validateConfigurationString(remoteDataFieldForCommentId, "index/" + CONFIG_REMOTEFIELD_COMMENTID);
}
}
validateConfigurationFieldsStructure(fieldsConfig, "index/fields");
}
@Override
public void addDataPreprocessor(StructuredContentPreprocessor preprocessor) {
if (preprocessor == null)
return;
if (issueDataPreprocessors == null)
issueDataPreprocessors = new ArrayList<StructuredContentPreprocessor>();
issueDataPreprocessors.add(preprocessor);
}
@Override
public String getDocumentSearchIndexName(String spaceKey) {
return indexName;
}
@Override
public void indexDocument(BulkRequestBuilder esBulk, String spaceKey, Map<String, Object> document) throws Exception {
document.put("spaceKey", spaceKey);
document = preprocessDocumentData(spaceKey, document);
esBulk.add(indexRequest(indexName).type(issueTypeName).id(extractDocumentId(document))
.source(prepareIndexedDocument(spaceKey, document)));
if (commentIndexingMode.isExtraDocumentIndexed()) {
List<Map<String, Object>> comments = extractComments(document);
if (comments != null && !comments.isEmpty()) {
String issueKey = extractDocumentId(document);
for (Map<String, Object> comment : comments) {
String commentId = extractCommentId(comment);
IndexRequest irq = indexRequest(indexName).type(commentTypeName).id(commentId)
.source(prepareCommentIndexedDocument(spaceKey, issueKey, comment));
if (commentIndexingMode == CommentIndexingMode.CHILD) {
irq.parent(issueKey);
}
esBulk.add(irq);
}
}
}
}
@Override
public String extractDocumentId(Map<String, Object> document) {
return extractIdValueFromDocumentField(document, remoteDataFieldForDocumentId, CONFIG_REMOTEFIELD_DOCUMENTID);
}
private String extractIdValueFromDocumentField(Map<String, Object> document, String idFieldName,
String idFieldConfigPropertyName) {
Object id = XContentMapValues.extractValue(idFieldName, document);
if (id == null)
return null;
if (!isSimpleValue(id))
throw new SettingsException("Remote data field '" + idFieldName + "' defined in 'index/"
+ idFieldConfigPropertyName + "' config param must provide simple value, but value is " + id);
return id.toString();
}
private boolean isSimpleValue(Object value) {
return (value instanceof String || value instanceof Integer || value instanceof Long || value instanceof Date);
}
@Override
public Date extractDocumentUpdated(Map<String, Object> document) {
Object val = XContentMapValues.extractValue(remoteDataFieldForUpdated, document);
if (val == null)
return null;
if (!isSimpleValue(val))
throw new SettingsException("Remote data field '" + remoteDataFieldForUpdated
+ "' must provide simple value, but value is " + val);
if (val instanceof Date)
return (Date) val;
try {
// try simple timestamp
return new Date(Long.parseLong(val.toString()));
} catch (NumberFormatException e) {
// try ISO format
try {
return DateTimeUtils.parseISODateTime(val.toString());
} catch (IllegalArgumentException e1) {
throw new SettingsException("Remote data field '" + remoteDataFieldForUpdated
+ "' is not reecognized as timestamp value (ISO format or number with millis from 1.1.1970): " + val);
}
}
}
protected String extractCommentId(Map<String, Object> comment) {
String commentId = extractIdValueFromDocumentField(comment, remoteDataFieldForCommentId,
CONFIG_REMOTEFIELD_COMMENTID);
if (commentId == null) {
throw new IllegalArgumentException("Comment ID not found in remote system response within data: " + comment);
}
return commentId;
}
/**
* Preprocess document data over all configured preprocessors.
*
* @param spaceKey document is for
* @param document data to preprocess
* @return preprocessed data
*/
protected Map<String, Object> preprocessDocumentData(String spaceKey, Map<String, Object> document) {
if (issueDataPreprocessors != null) {
for (StructuredContentPreprocessor prepr : issueDataPreprocessors) {
document = prepr.preprocessData(document);
}
}
return document;
}
@Override
public void buildSearchForIndexedDocumentsNotUpdatedAfter(SearchRequestBuilder srb, String spaceKey, Date date) {
FilterBuilder filterTime = FilterBuilders.rangeFilter("_timestamp").lt(date);
FilterBuilder filterProject = FilterBuilders.termFilter(indexFieldForSpaceKey, spaceKey);
FilterBuilder filterSource = FilterBuilders.termFilter(indexFieldForRiverName, riverName);
FilterBuilder filter = FilterBuilders.boolFilter().must(filterTime).must(filterProject).must(filterSource);
srb.setQuery(QueryBuilders.matchAllQuery()).addField("_id").setFilter(filter);
if (commentIndexingMode.isExtraDocumentIndexed())
srb.setTypes(issueTypeName, commentTypeName);
else
srb.setTypes(issueTypeName);
}
@Override
public boolean deleteESDocument(BulkRequestBuilder esBulk, SearchHit documentToDelete) throws Exception {
esBulk.add(deleteRequest(indexName).type(documentToDelete.getType()).id(documentToDelete.getId()));
return issueTypeName.equals(documentToDelete.getType());
}
/**
* Convert remote system returned document data into JSON document to be stored in search index.
*
* @param spaceKey key of space document is for.
* @param documentRemote data from remote system REST call
* @return JSON builder with document for index
* @throws Exception
*/
protected XContentBuilder prepareIndexedDocument(String spaceKey, Map<String, Object> documentRemote)
throws Exception {
String documentId = extractDocumentId(documentRemote);
XContentBuilder out = jsonBuilder().startObject();
addValueToTheIndexField(out, indexFieldForRiverName, riverName);
addValueToTheIndexField(out, indexFieldForSpaceKey, spaceKey);
addValueToTheIndexField(out, indexFieldForRemoteDocumentId, documentId);
for (String indexFieldName : fieldsConfig.keySet()) {
Map<String, String> fieldConfig = fieldsConfig.get(indexFieldName);
addValueToTheIndex(out, indexFieldName, fieldConfig.get(CONFIG_FIELDS_REMOTEFIELD), documentRemote,
fieldConfig.get(CONFIG_FIELDS_VALUEFILTER));
}
if (commentIndexingMode == CommentIndexingMode.EMBEDDED) {
List<Map<String, Object>> comments = extractComments(documentRemote);
if (comments != null && !comments.isEmpty()) {
out.startArray(indexFieldForComments);
for (Map<String, Object> comment : comments) {
out.startObject();
addCommonFieldsToCommentIndexedDocument(out, documentId, comment);
out.endObject();
}
out.endArray();
}
}
return out.endObject();
}
/**
* Convert remote system's returned data into JSON document to be stored in search index for comments in child and
* standalone mode.
*
* @param spaceKey key of space document is for.
* @param documentId this comment is for
* @param comment data from remote system document
* @return JSON builder with comment document for index
* @throws Exception
*/
protected XContentBuilder prepareCommentIndexedDocument(String spaceKey, String documentId,
Map<String, Object> comment) throws Exception {
XContentBuilder out = jsonBuilder().startObject();
addValueToTheIndexField(out, indexFieldForRiverName, riverName);
addValueToTheIndexField(out, indexFieldForSpaceKey, spaceKey);
addValueToTheIndexField(out, indexFieldForRemoteDocumentId, documentId);
addCommonFieldsToCommentIndexedDocument(out, documentId, comment);
return out.endObject();
}
private void addCommonFieldsToCommentIndexedDocument(XContentBuilder out, String documentId,
Map<String, Object> comment) throws Exception {
for (String indexFieldName : commentFieldsConfig.keySet()) {
Map<String, String> commentFieldConfig = commentFieldsConfig.get(indexFieldName);
addValueToTheIndex(out, indexFieldName, commentFieldConfig.get(CONFIG_FIELDS_REMOTEFIELD), comment,
commentFieldConfig.get(CONFIG_FIELDS_VALUEFILTER));
}
}
/**
* Get all comments for document from remote system JSON data.
*
* @param document Map of Maps document data structure loaded from remote system.
* @return list of comments if available in data
*/
@SuppressWarnings("unchecked")
protected List<Map<String, Object>> extractComments(Map<String, Object> document) {
List<Map<String, Object>> comments = (List<Map<String, Object>>) XContentMapValues.extractValue(
remoteDataFieldForComments, document);
return comments;
}
/**
* Get defined value from values structure and add it into index document. Calls
* {@link #addValueToTheIndex(XContentBuilder, String, String, Map, Map)} and receive filter from
* {@link #filtersConfig} based on passed <code>valueFieldFilterName</code>)
*
* @param out content builder to add indexed value field into
* @param indexField name of field for index
* @param valuePath path to get value from <code>values</code> structure. Dot notation for nested values can be used
* here (see {@link XContentMapValues#extractValue(String, Map)}).
* @param values structure to get value from. Can be <code>null</code> - nothing added in this case, but not
* exception.
* @param valueFieldFilterName name of filter definition to get it from {@link #filtersConfig}
* @throws Exception
*/
protected void addValueToTheIndex(XContentBuilder out, String indexField, String valuePath,
Map<String, Object> values, String valueFieldFilterName) throws Exception {
Map<String, String> filter = null;
if (!Utils.isEmpty(valueFieldFilterName)) {
filter = filtersConfig.get(valueFieldFilterName);
}
addValueToTheIndex(out, indexField, valuePath, values, filter);
}
/**
* Get defined value from values structure and add it into index document.
*
* @param out content builder to add indexed value field into
* @param indexField name of field for index
* @param valuePath path to get value from <code>values</code> structure. Dot notation for nested values can be used
* here (see {@link XContentMapValues#extractValue(String, Map)}).
* @param values structure to get value from. Can be <code>null</code> - nothing added in this case, but not
* exception.
* @param valueFieldFilter if value is JSON Object (java Map here) or List of JSON Objects, then fields in this
* objects are filtered to leave only fields named here and remap them - see
* {@link Utils#remapDataInMap(Map, Map)}. No filtering performed if this is <code>null</code>.
* @throws Exception
*/
@SuppressWarnings("unchecked")
protected void addValueToTheIndex(XContentBuilder out, String indexField, String valuePath,
Map<String, Object> values, Map<String, String> valueFieldFilter) throws Exception {
if (values == null) {
return;
}
Object v = null;
if (valuePath.contains(".")) {
v = XContentMapValues.extractValue(valuePath, values);
} else {
v = values.get(valuePath);
}
if (v != null && valueFieldFilter != null && !valueFieldFilter.isEmpty()) {
if (v instanceof Map) {
Utils.remapDataInMap((Map<String, Object>) v, valueFieldFilter);
} else if (v instanceof List) {
for (Object o : (List<?>) v) {
if (o instanceof Map) {
Utils.remapDataInMap((Map<String, Object>) o, valueFieldFilter);
} else {
logger.warn(
"Filter defined for field which is not filterable - remote document array field '{}' with value: {}",
valuePath, v);
}
}
} else {
logger.warn("Filter defined for field which is not filterable - remote document field '{}' with value: {}",
valuePath, v);
}
}
addValueToTheIndexField(out, indexField, v);
}
/**
* Add value into field in index document. Do not add it if value is <code>null</code>!
*
* @param out builder to add field into.
* @param indexField real name of field used in index.
* @param value to be added to the index field. Can be <code>null</code>, nothing added in this case
* @throws Exception
*
* @see {@link XContentBuilder#field(String, Object)}.
*/
protected void addValueToTheIndexField(XContentBuilder out, String indexField, Object value) throws Exception {
if (value != null)
out.field(indexField, value);
}
@SuppressWarnings("unchecked")
private Map<String, Object> loadDefaultSettingsMapFromFile() throws SettingsException {
Map<String, Object> json = Utils.loadJSONFromJarPackagedFile("/templates/river_configuration_default.json");
return (Map<String, Object>) json.get("index");
}
private String loadDefaultStringIfNecessary(String valueToCheck, String valueConfigKey,
Map<String, Object> settingsDefault) {
if (Utils.isEmpty(valueToCheck)) {
return XContentMapValues.nodeStringValue(settingsDefault.get(valueConfigKey), null);
} else {
return valueToCheck.trim();
}
}
private void validateConfigurationFieldsStructure(Map<String, Map<String, String>> value, String configFieldName) {
for (String idxFieldName : value.keySet()) {
if (Utils.isEmpty(idxFieldName)) {
throw new SettingsException("Empty key found in '" + configFieldName + "' map.");
}
Map<String, String> fc = value.get(idxFieldName);
if (Utils.isEmpty(fc.get(CONFIG_FIELDS_REMOTEFIELD))) {
throw new SettingsException("'remote_field' is not defined in '" + configFieldName + "/" + idxFieldName + "'");
}
String fil = fc.get(CONFIG_FIELDS_VALUEFILTER);
if (fil != null && !filtersConfig.containsKey(fil)) {
throw new SettingsException("Filter definition not found for filter name '" + fil + "' defined in '"
+ configFieldName + "/" + idxFieldName + "/value_filter'");
}
}
}
private void validateConfigurationString(String value, String configFieldName) throws SettingsException {
if (Utils.isEmpty(value)) {
throw new SettingsException("String value must be provided for '" + configFieldName + "' configuration!");
}
}
private void validateConfigurationObject(Object value, String configFieldName) throws SettingsException {
if (value == null) {
throw new SettingsException("Value must be provided for '" + configFieldName + "' configuration!");
}
}
}