1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.objects.classes

File DefaultPageQueryBuilder.java

 

Coverage histogram

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

Code metrics

2
9
1
1
94
48
2
0.22
9
1
2

Classes

Class Line # Actions
DefaultPageQueryBuilder 45 9 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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 com.xpn.xwiki.internal.objects.classes;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.query.Query;
29    import org.xwiki.query.QueryBuilder;
30    import org.xwiki.query.QueryException;
31    import org.xwiki.query.QueryFilter;
32    import org.xwiki.text.StringUtils;
33   
34    import com.xpn.xwiki.objects.classes.DBListClass;
35    import com.xpn.xwiki.objects.classes.PageClass;
36   
37    /**
38    * Builds a query that returns the values allowed for a Page property.
39    *
40    * @version $Id: 14aea824f9db23773bdb1fe182959886c490b6c9 $
41    * @since 10.6
42    */
43    @Component
44    @Singleton
 
45    public class DefaultPageQueryBuilder implements QueryBuilder<PageClass>
46    {
47    @Inject
48    @Named("explicitlyAllowedValues")
49    private QueryBuilder<DBListClass> explicitlyAllowedValuesQueryBuilder;
50   
51    @Inject
52    @Named("implicitlyAllowedValues")
53    private QueryBuilder<PageClass> implicitlyAllowedValuesQueryBuilder;
54   
55    @Inject
56    @Named("document")
57    private QueryFilter documentFilter;
58   
59    @Inject
60    @Named("viewable")
61    private QueryFilter viewableFilter;
62   
63    /**
64    * The filter used to show/hide hidden (technical) documents. We use a provider because we need a new instance for
65    * each query execution.
66    *
67    * @see <a href="https://jira.xwiki.org/browse/XWIKI-8160">XWIKI-8160: HiddenDocument query filter can put corrupted
68    * user documents in the cache (virtual mode)</a>
69    */
70    @Inject
71    @Named("hidden/document")
72    private Provider<QueryFilter> hiddenFilterProvider;
73   
 
74  38 toggle @Override
75    public Query build(PageClass pageClass) throws QueryException
76    {
77  38 Query query;
78  38 if (StringUtils.isEmpty(pageClass.getSql())) {
79  37 query = this.implicitlyAllowedValuesQueryBuilder.build(pageClass);
80    // We can filter hidden documents here because we control how the query is build ('doc' alias is present).
81  37 query.addFilter(hiddenFilterProvider.get());
82    // We don't need the viewable filter here as the query builder already adds its own viewable filter.
83  37 query.addFilter(this.documentFilter);
84    } else {
85  1 query = this.explicitlyAllowedValuesQueryBuilder.build(pageClass);
86    // NOTE: If the user provides an explicit query then he's responsible for filtering hidden documents if he
87    // needs it. We can't use the hidden document filter here because we don't control the query.
88  1 query.addFilter(this.documentFilter);
89  1 query.addFilter(this.viewableFilter);
90    }
91   
92  38 return query;
93    }
94    }