1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.index.tree.internal.nestedpages

File WikiTreeNode.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

8
27
5
1
134
92
13
0.48
5.4
5
2.6

Classes

Class Line # Actions
WikiTreeNode 51 27 0% 13 19
0.52552.5%
 

Contributing tests

No tests hitting this source file were found.

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.index.tree.internal.nestedpages;
21   
22    import java.util.Collections;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27   
28    import org.apache.commons.lang3.exception.ExceptionUtils;
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.annotation.InstantiationStrategy;
31    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
32    import org.xwiki.index.tree.internal.AbstractEntityTreeNode;
33    import org.xwiki.localization.LocalizationContext;
34    import org.xwiki.model.EntityType;
35    import org.xwiki.model.reference.EntityReference;
36    import org.xwiki.model.reference.WikiReference;
37    import org.xwiki.query.Query;
38    import org.xwiki.query.QueryException;
39    import org.xwiki.query.QueryFilter;
40   
41    /**
42    * The wiki tree node.
43    *
44    * @version $Id: 95a0a21e1e80d9ce220a245ccb5a7d707d6a1b20 $
45    * @since 8.3M2
46    * @since 7.4.5
47    */
48    @Component
49    @Named("wiki")
50    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
51    public class WikiTreeNode extends AbstractEntityTreeNode
52    {
53    @Inject
54    private LocalizationContext localizationContext;
55   
56    @Inject
57    @Named("topLevelPage/nestedPages")
58    private QueryFilter topLevelPageFilter;
59   
60    @Inject
61    @Named("hiddenPage/nestedPages")
62    private QueryFilter hiddenPageFilter;
63   
64    @Inject
65    @Named("documentReferenceResolver/nestedPages")
66    private QueryFilter documentReferenceResolverFilter;
67   
 
68  3 toggle @Override
69    public List<String> getChildren(String nodeId, int offset, int limit)
70    {
71  3 EntityReference wikiReference = resolve(nodeId);
72  3 if (wikiReference != null && wikiReference.getType() == EntityType.WIKI) {
73  3 try {
74  3 return serialize(getChildren(new WikiReference(wikiReference), offset, limit));
75    } catch (QueryException e) {
76  0 this.logger.warn("Failed to retrieve the children of [{}]. Root cause [{}].", nodeId,
77    ExceptionUtils.getRootCauseMessage(e));
78    }
79    }
80  0 return Collections.emptyList();
81    }
82   
 
83  3 toggle protected List<? extends EntityReference> getChildren(WikiReference wikiReference, int offset, int limit)
84    throws QueryException
85    {
86  3 String orderBy = getOrderBy();
87  3 Query query;
88  3 if ("title".equals(orderBy)) {
89  3 query = this.queryManager.getNamedQuery("nonTerminalPagesOrderedByTitle");
90  3 query.bindValue("locale", this.localizationContext.getCurrentLocale().toString());
91    } else {
92    // Query only the spaces table.
93  0 query = this.queryManager.createQuery(
94    "select reference, 0 as terminal from XWikiSpace page order by lower(name), name", Query.HQL);
95    }
96  3 query.setWiki(wikiReference.getName());
97  3 query.setOffset(offset);
98  3 query.setLimit(limit);
99   
100  3 query.addFilter(this.topLevelPageFilter);
101   
102  3 if (!areHiddenEntitiesShown()) {
103  3 query.addFilter(this.hiddenPageFilter);
104    }
105   
106  3 return query.addFilter(this.documentReferenceResolverFilter).execute();
107    }
108   
 
109  0 toggle @Override
110    public int getChildCount(String nodeId)
111    {
112  0 EntityReference wikiReference = resolve(nodeId);
113  0 if (wikiReference != null && wikiReference.getType() == EntityType.WIKI) {
114  0 try {
115  0 return getChildCount(new WikiReference(wikiReference));
116    } catch (QueryException e) {
117  0 this.logger.warn("Failed to count the children of [{}]. Root cause [{}].", nodeId,
118    ExceptionUtils.getRootCauseMessage(e));
119    }
120    }
121  0 return 0;
122    }
123   
 
124  0 toggle protected int getChildCount(WikiReference wikiReference) throws QueryException
125    {
126  0 return getChildSpacesCount(wikiReference);
127    }
128   
 
129  0 toggle @Override
130    public String getParent(String nodeId)
131    {
132  0 return "farm:*";
133    }
134    }