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.reference; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Iterator; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import javax.inject.Inject; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.slf4j.Logger; |
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
import org.xwiki.component.manager.ComponentLookupException; |
32 |
|
import org.xwiki.component.manager.ComponentManager; |
33 |
|
import org.xwiki.model.EntityType; |
34 |
|
import org.xwiki.model.reference.EntityReference; |
35 |
|
import org.xwiki.model.reference.WikiReference; |
36 |
|
import org.xwiki.search.solr.internal.api.SolrIndexerException; |
37 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
38 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
46 |
|
@Component |
47 |
|
@Singleton |
|
|
| 87.1% |
Uncovered Elements: 4 (31) |
Complexity: 10 |
Complexity Density: 0.5 |
|
48 |
|
public class DefaultSolrReferenceResolver implements SolrReferenceResolver |
49 |
|
{ |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
@version |
54 |
|
|
|
|
| 85.7% |
Uncovered Elements: 4 (28) |
Complexity: 11 |
Complexity Density: 0.73 |
|
55 |
|
class FarmIterator implements Iterator<EntityReference> |
56 |
|
{ |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
private Iterator<EntityReference> currentIterator; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
private final Iterator<String> currentWiki; |
66 |
|
|
67 |
|
|
68 |
|
@param |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
2 |
FarmIterator(List<String> wikis)... |
71 |
|
{ |
72 |
2 |
this.currentWiki = wikis.iterator(); |
73 |
|
} |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0 |
@Override... |
76 |
|
public void remove() |
77 |
|
{ |
78 |
0 |
throw new UnsupportedOperationException(); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
81 |
26 |
@Override... |
82 |
|
public boolean hasNext() |
83 |
|
{ |
84 |
26 |
update(); |
85 |
|
|
86 |
26 |
return currentIterator != null; |
87 |
|
} |
88 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
89 |
24 |
@Override... |
90 |
|
public EntityReference next() |
91 |
|
{ |
92 |
24 |
update(); |
93 |
|
|
94 |
24 |
return currentIterator != null ? currentIterator.next() : null; |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 6 |
Complexity Density: 0.67 |
|
100 |
52 |
private void update()... |
101 |
|
{ |
102 |
52 |
if (currentIterator == null || !currentIterator.hasNext()) { |
103 |
6 |
if (currentWiki.hasNext()) { |
104 |
4 |
String wiki = currentWiki.next(); |
105 |
4 |
try { |
106 |
4 |
currentIterator = getReferences(new WikiReference(wiki)).iterator(); |
107 |
|
} catch (SolrIndexerException e) { |
108 |
0 |
logger.error("Failed to get references for wiki [" + wiki + "]", e); |
109 |
|
} |
110 |
|
|
111 |
4 |
if (!currentIterator.hasNext()) { |
112 |
2 |
update(); |
113 |
|
} |
114 |
|
} else { |
115 |
2 |
currentIterator = null; |
116 |
|
} |
117 |
|
} |
118 |
|
} |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
@link |
123 |
|
|
124 |
|
@Inject |
125 |
|
private ComponentManager componentManager; |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
@Inject |
131 |
|
private Logger logger; |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
@Inject |
137 |
|
private WikiDescriptorManager wikiDescriptorManager; |
138 |
|
|
139 |
|
|
140 |
|
@param |
141 |
|
@return |
142 |
|
@throws |
143 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
144 |
938 |
private SolrReferenceResolver getResover(EntityReference reference) throws SolrIndexerException... |
145 |
|
{ |
146 |
938 |
EntityType type = reference.getType(); |
147 |
|
|
148 |
938 |
SolrReferenceResolver resolver; |
149 |
938 |
try { |
150 |
938 |
resolver = this.componentManager.getInstance(SolrReferenceResolver.class, type.getLowerCase()); |
151 |
|
} catch (ComponentLookupException e) { |
152 |
0 |
throw new SolrIndexerException("Failed to get SolrDocumentReferenceResolver corresponding to entity type [" |
153 |
|
+ type + "]", e); |
154 |
|
} |
155 |
|
|
156 |
938 |
return resolver; |
157 |
|
} |
158 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
159 |
498 |
@Override... |
160 |
|
public Iterable<EntityReference> getReferences(EntityReference reference) throws SolrIndexerException |
161 |
|
{ |
162 |
498 |
if (reference != null) { |
163 |
497 |
return getResover(reference).getReferences(reference); |
164 |
|
} else { |
165 |
1 |
final List<String> wikis; |
166 |
1 |
try { |
167 |
1 |
wikis = new ArrayList<String>(this.wikiDescriptorManager.getAllIds()); |
168 |
|
} catch (WikiManagerException e) { |
169 |
0 |
throw new SolrIndexerException("Failed to get the list of available wikis.", e); |
170 |
|
} |
171 |
|
|
172 |
1 |
return new Iterable<EntityReference>() |
173 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
2 |
@Override... |
175 |
|
public Iterator<EntityReference> iterator() |
176 |
|
{ |
177 |
2 |
return new FarmIterator(wikis); |
178 |
|
} |
179 |
|
}; |
180 |
|
} |
181 |
|
} |
182 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
183 |
435 |
@Override... |
184 |
|
public String getId(EntityReference reference) throws SolrIndexerException, IllegalArgumentException |
185 |
|
{ |
186 |
435 |
if (reference != null) { |
187 |
435 |
return getResover(reference).getId(reference); |
188 |
|
} else { |
189 |
0 |
return null; |
190 |
|
} |
191 |
|
} |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
193 |
9 |
@Override... |
194 |
|
public String getQuery(EntityReference reference) throws SolrIndexerException |
195 |
|
{ |
196 |
9 |
if (reference != null) { |
197 |
6 |
return getResover(reference).getQuery(reference); |
198 |
|
} else { |
199 |
3 |
return "*:*"; |
200 |
|
} |
201 |
|
} |
202 |
|
} |