1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.search.solr.internal.reference

File WikiSolrReferenceResolver.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

0
12
2
1
106
57
4
0.33
6
2
2

Classes

Class Line # Actions
WikiSolrReferenceResolver 51 12 0% 4 2
0.8571428785.7%
 

Contributing tests

This file is covered by 7 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Resolve wiki references.
44    *
45    * @version $Id: b0dd5b02a5fe03076d87a9e4baa9b338873d45eb $
46    * @since 5.1M2
47    */
48    @Component
49    @Named("wiki")
50    @Singleton
 
51    public class WikiSolrReferenceResolver extends AbstractSolrReferenceResolver
52    {
53    /**
54    * Used to resolve space references.
55    */
56    @Inject
57    @Named("space")
58    private Provider<SolrReferenceResolver> spaceResolverProvider;
59   
60    /**
61    * Query manager used to perform queries on the XWiki model.
62    */
63    @Inject
64    private QueryManager queryManager;
65   
66    @Inject
67    @Named("explicit")
68    private EntityReferenceResolver<String> explicitEntityReferenceResolver;
69   
 
70  6 toggle @Override
71    public List<EntityReference> getReferences(EntityReference wikiReference) throws SolrIndexerException
72    {
73  6 List<EntityReference> result = new ArrayList<EntityReference>();
74   
75    // Ignore the wiki reference because it is not indexable.
76   
77  6 List<String> localSpaceRefs = null;
78   
79    // Make sure the list of spaces is from the requested wiki.
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    // Visit each space
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   
 
101  4 toggle @Override
102    public String getQuery(EntityReference reference)
103    {
104  4 return FieldUtils.WIKI + ':' + ClientUtils.escapeQueryChars(reference.getName());
105    }
106    }