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

File SpaceTreeNode.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

2
16
2
1
107
63
3
0.19
8
2
1.5

Classes

Class Line # Actions
SpaceTreeNode 51 16 0% 3 20
0.00%
 

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.nestedspaces.parentchild;
21   
22    import java.util.ArrayList;
23    import java.util.HashMap;
24    import java.util.List;
25    import java.util.Map;
26   
27    import javax.inject.Inject;
28    import javax.inject.Named;
29   
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.component.annotation.InstantiationStrategy;
32    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
33    import org.xwiki.model.reference.DocumentReference;
34    import org.xwiki.model.reference.DocumentReferenceResolver;
35    import org.xwiki.model.reference.EntityReference;
36    import org.xwiki.model.reference.SpaceReference;
37    import org.xwiki.query.Query;
38    import org.xwiki.query.QueryException;
39    import org.xwiki.query.QueryFilter;
40   
41    /**
42    * The space node in the parent-child over nested spaces hierarchy.
43    *
44    * @version $Id: f9a651cb91f628f8bbc50717aa01b1ce7edf19ed $
45    * @since 8.3M2
46    * @since 7.4.5
47    */
48    @Component
49    @Named("space/parentChildOnNestedSpaces")
50    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
51    public class SpaceTreeNode extends org.xwiki.index.tree.internal.nestedspaces.SpaceTreeNode
52    {
53    private static final String PARAMETER_ABSOLUTE_REFERENCE = "absoluteRef";
54   
55    private static final String PARAMETER_LOCAL_REFERENCE = "localRef";
56   
57    @Inject
58    @Named("explicit")
59    private DocumentReferenceResolver<String> explicitDocumentReferenceResolver;
60   
61    @Inject
62    @Named("topLevelPage/parentChildOnNestedSpaces")
63    private QueryFilter topLevelPageFilter;
64   
 
65  0 toggle @Override
66    protected List<? extends EntityReference> getChildren(SpaceReference spaceReference, int offset, int limit)
67    throws QueryException
68    {
69  0 Query query = getChildrenQuery(spaceReference, offset, limit);
70   
71  0 if (areTerminalDocumentsShown()) {
72    // Include only the documents that either don't have a parent document or that have a parent document in a
73    // different space.
74  0 query.addFilter(this.topLevelPageFilter);
75  0 DocumentReference absoluteReference =
76    this.explicitDocumentReferenceResolver.resolve(String.valueOf('%'), spaceReference);
77  0 query.bindValue(PARAMETER_ABSOLUTE_REFERENCE,
78    this.defaultEntityReferenceSerializer.serialize(absoluteReference));
79  0 query.bindValue(PARAMETER_LOCAL_REFERENCE,
80    this.localEntityReferenceSerializer.serialize(absoluteReference));
81    }
82   
83  0 return query.execute();
84    }
85   
 
86  0 toggle @Override
87    protected int getChildDocumentsCount(SpaceReference spaceReference) throws QueryException
88    {
89  0 List<String> constraints = new ArrayList<String>();
90  0 Map<String, Object> parameters = new HashMap<String, Object>();
91   
92    // Include only the documents that either don't have a parent document or that have a parent document in a
93    // different space. Note that in Oracle the empty string is stored as null.
94  0 String hasNoParent = "doc.parent = '' or doc.parent is null";
95  0 String hasParentOutsideSpace =
96    "doc.parent like '%.%' and doc.parent not like :absoluteRef and doc.parent not like :localRef";
97  0 constraints.add(String.format("((%s) or (%s))", hasNoParent, hasParentOutsideSpace));
98   
99  0 DocumentReference absoluteReference =
100    this.explicitDocumentReferenceResolver.resolve(String.valueOf('%'), spaceReference);
101  0 parameters.put(PARAMETER_ABSOLUTE_REFERENCE,
102    this.defaultEntityReferenceSerializer.serialize(absoluteReference));
103  0 parameters.put(PARAMETER_LOCAL_REFERENCE, this.localEntityReferenceSerializer.serialize(absoluteReference));
104   
105  0 return getChildDocumentsCount(spaceReference, constraints, parameters);
106    }
107    }