1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.search.solr.internal; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Provider; |
28 |
|
import javax.inject.Singleton; |
29 |
|
|
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.xwiki.bridge.event.ApplicationReadyEvent; |
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.observation.EventListener; |
34 |
|
import org.xwiki.observation.event.Event; |
35 |
|
import org.xwiki.search.solr.internal.api.SolrConfiguration; |
36 |
|
import org.xwiki.search.solr.internal.api.SolrIndexer; |
37 |
|
import org.xwiki.search.solr.internal.api.SolrIndexerException; |
38 |
|
import org.xwiki.search.solr.internal.job.IndexerRequest; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
46 |
|
@Component |
47 |
|
@Named("solr.initializer") |
48 |
|
@Singleton |
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 5 |
Complexity Density: 0.62 |
|
49 |
|
public class SolrIndexInitializeListener implements EventListener |
50 |
|
{ |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
private static final List<Event> EVENTS = Arrays.<Event> asList(new ApplicationReadyEvent()); |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
@Inject |
60 |
|
protected Logger logger; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@link |
66 |
|
|
67 |
|
@Inject |
68 |
|
private Provider<SolrIndexer> solrIndexer; |
69 |
|
|
70 |
|
@Inject |
71 |
|
private SolrConfiguration configuration; |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
3 |
@Override... |
74 |
|
public List<Event> getEvents() |
75 |
|
{ |
76 |
3 |
return EVENTS; |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
12 |
@Override... |
80 |
|
public String getName() |
81 |
|
{ |
82 |
12 |
return this.getClass().getName(); |
83 |
|
} |
84 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
85 |
3 |
@Override... |
86 |
|
public void onEvent(Event event, Object source, Object data) |
87 |
|
{ |
88 |
3 |
if (this.configuration.synchronizeAtStartup()) { |
89 |
|
|
90 |
3 |
IndexerRequest request = new IndexerRequest(); |
91 |
3 |
request.setId(Arrays.asList("solr", "indexer")); |
92 |
|
|
93 |
3 |
try { |
94 |
3 |
this.solrIndexer.get().startIndex(request); |
95 |
|
} catch (SolrIndexerException e) { |
96 |
0 |
this.logger.error("Failed to start initial Solr index synchronization", e); |
97 |
|
} |
98 |
|
} |
99 |
|
} |
100 |
|
} |