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

File AbstractSolrReferenceResolver.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
6
3
1
97
39
3
0.5
2
3
1

Classes

Class Line # Actions
AbstractSolrReferenceResolver 42 6 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 13 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 javax.inject.Inject;
23    import javax.inject.Provider;
24   
25    import org.apache.solr.client.solrj.util.ClientUtils;
26    import org.slf4j.Logger;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.model.reference.EntityReference;
29    import org.xwiki.model.reference.EntityReferenceSerializer;
30    import org.xwiki.search.solr.internal.api.FieldUtils;
31    import org.xwiki.search.solr.internal.api.SolrIndexerException;
32   
33    import com.xpn.xwiki.XWikiContext;
34    import com.xpn.xwiki.doc.XWikiDocument;
35   
36    /**
37    * Base implementation.
38    *
39    * @version $Id: 0fec3476e31f1cf7942f1cf44c2d4f691f33c22c $
40    * @since 5.1M2
41    */
 
42    public abstract class AbstractSolrReferenceResolver implements SolrReferenceResolver
43    {
44    /**
45    * SEparator between several element of the SOLR query.
46    */
47    protected static final String QUERY_AND = " AND ";
48   
49    /**
50    * Used to access current {@link XWikiContext}.
51    */
52    @Inject
53    protected Provider<XWikiContext> xcontextProvider;
54   
55    /**
56    * Reference to String serializer.
57    */
58    @Inject
59    protected EntityReferenceSerializer<String> serializer;
60   
61    /**
62    * The logger.
63    */
64    @Inject
65    protected Logger logger;
66   
67    /**
68    * Utility method.
69    *
70    * @param documentReference reference to a document.
71    * @return the {@link XWikiDocument} instance referenced.
72    * @throws Exception if problems occur.
73    */
 
74  957 toggle protected XWikiDocument getDocument(DocumentReference documentReference) throws Exception
75    {
76  957 XWikiContext context = this.xcontextProvider.get();
77  957 XWikiDocument document = context.getWiki().getDocument(documentReference, context);
78   
79  957 return document;
80    }
81   
 
82  5149 toggle @Override
83    public String getId(EntityReference reference) throws SolrIndexerException, IllegalArgumentException
84    {
85  5149 String result = this.serializer.serialize(reference);
86   
87    // TODO: Include locale all the other entities once object/attachment translation is implemented.
88   
89  5149 return result;
90    }
91   
 
92  2 toggle @Override
93    public String getQuery(EntityReference reference) throws IllegalArgumentException, SolrIndexerException
94    {
95  2 return FieldUtils.ID + ':' + ClientUtils.escapeQueryChars(getId(reference));
96    }
97    }