1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rest.internal.resources.pages

File PageChildrenResourceImpl.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

4
15
1
1
85
49
4
0.27
15
1
4

Classes

Class Line # Actions
PageChildrenResourceImpl 42 15 0% 4 4
0.880%
 

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.rest.internal.resources.pages;
21   
22    import java.util.List;
23   
24    import javax.inject.Named;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.query.Query;
28    import org.xwiki.rest.XWikiResource;
29    import org.xwiki.rest.XWikiRestException;
30    import org.xwiki.rest.internal.DomainObjectFactory;
31    import org.xwiki.rest.internal.Utils;
32    import org.xwiki.rest.model.jaxb.Pages;
33    import org.xwiki.rest.resources.pages.PageChildrenResource;
34   
35    import com.xpn.xwiki.api.Document;
36   
37    /**
38    * @version $Id: 3582dbf402ee1e3f80dd78056035fdb9d42b6d77 $
39    */
40    @Component
41    @Named("org.xwiki.rest.internal.resources.pages.PageChildrenResourceImpl")
 
42    public class PageChildrenResourceImpl extends XWikiResource implements PageChildrenResource
43    {
 
44  3 toggle @Override
45    public Pages getPageChildren(String wikiName, String spaceName, String pageName, Integer start, Integer number,
46    Boolean withPrettyNames) throws XWikiRestException
47    {
48  3 try {
49  3 DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
50   
51  3 Document doc = documentInfo.getDocument();
52   
53  3 Pages pages = objectFactory.createPages();
54   
55    /* Use an explicit query to improve performance */
56  3 String queryString =
57    "select distinct doc.fullName from XWikiDocument as doc where doc.parent = :parent order by doc.fullName asc";
58  3 List<String> childPageFullNames =
59    queryManager.createQuery(queryString, Query.XWQL).bindValue("parent", doc.getFullName()).setOffset(
60    start).setLimit(number).execute();
61   
62  3 for (String childPageFullName : childPageFullNames) {
63  3 String pageId = Utils.getPageId(wikiName, childPageFullName);
64   
65  3 if (!Utils.getXWikiApi(componentManager).exists(pageId)) {
66  0 logger.warning(
67    String.format("[Page '%s' appears to be in space '%s' but no information is available.]",
68    pageName, spaceName));
69    } else {
70  3 Document childDoc = Utils.getXWikiApi(componentManager).getDocument(pageId);
71   
72    /* We only add pages we have the right to access */
73  3 if (childDoc != null) {
74  3 pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory,
75    uriInfo.getBaseUri(), childDoc, Utils.getXWikiApi(componentManager), withPrettyNames));
76    }
77    }
78    }
79   
80  3 return pages;
81    } catch (Exception e) {
82  0 throw new XWikiRestException(e);
83    }
84    }
85    }