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.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.apache.solr.client.solrj.util.ClientUtils; |
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
import org.xwiki.model.EntityType; |
33 |
|
import org.xwiki.model.reference.EntityReference; |
34 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
35 |
|
import org.xwiki.query.QueryException; |
36 |
|
import org.xwiki.query.QueryManager; |
37 |
|
import org.xwiki.search.solr.internal.api.FieldUtils; |
38 |
|
import org.xwiki.search.solr.internal.api.SolrIndexerException; |
39 |
|
|
40 |
|
import com.google.common.collect.Iterables; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
48 |
|
@Component |
49 |
|
@Named("wiki") |
50 |
|
@Singleton |
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 4 |
Complexity Density: 0.33 |
|
51 |
|
public class WikiSolrReferenceResolver extends AbstractSolrReferenceResolver |
52 |
|
{ |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@Inject |
57 |
|
@Named("space") |
58 |
|
private Provider<SolrReferenceResolver> spaceResolverProvider; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@Inject |
64 |
|
private QueryManager queryManager; |
65 |
|
|
66 |
|
@Inject |
67 |
|
@Named("explicit") |
68 |
|
private EntityReferenceResolver<String> explicitEntityReferenceResolver; |
69 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.27 |
|
70 |
6 |
@Override... |
71 |
|
public List<EntityReference> getReferences(EntityReference wikiReference) throws SolrIndexerException |
72 |
|
{ |
73 |
6 |
List<EntityReference> result = new ArrayList<EntityReference>(); |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
6 |
List<String> localSpaceRefs = null; |
78 |
|
|
79 |
|
|
80 |
6 |
try { |
81 |
6 |
localSpaceRefs = this.queryManager.getNamedQuery("getSpaces").setWiki(wikiReference.getName()).execute(); |
82 |
|
} catch (QueryException e) { |
83 |
0 |
throw new SolrIndexerException("Failed to query wiki [" + wikiReference.getName() + "] spaces", e); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
6 |
for (String localSpaceRef : localSpaceRefs) { |
88 |
9 |
EntityReference spaceReference = |
89 |
|
this.explicitEntityReferenceResolver.resolve(localSpaceRef, EntityType.SPACE, wikiReference); |
90 |
|
|
91 |
9 |
try { |
92 |
9 |
Iterables.addAll(result, this.spaceResolverProvider.get().getReferences(spaceReference)); |
93 |
|
} catch (Exception e) { |
94 |
0 |
this.logger.error("Failed to resolve references for space [" + spaceReference + "]", e); |
95 |
|
} |
96 |
|
} |
97 |
|
|
98 |
6 |
return result; |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
4 |
@Override... |
102 |
|
public String getQuery(EntityReference reference) |
103 |
|
{ |
104 |
4 |
return FieldUtils.WIKI + ':' + ClientUtils.escapeQueryChars(reference.getName()); |
105 |
|
} |
106 |
|
} |