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

File SpacesResourceImpl.java

 

Coverage histogram

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

Code metrics

4
14
1
1
76
45
4
0.29
14
1
4

Classes

Class Line # Actions
SpacesResourceImpl 43 14 0% 4 4
0.789473778.9%
 

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.spaces;
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.QueryFilter;
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.Spaces;
33    import org.xwiki.rest.resources.spaces.SpacesResource;
34   
35    import com.xpn.xwiki.api.Document;
36    import com.xpn.xwiki.api.XWiki;
37   
38    /**
39    * @version $Id: f2beea669df68aef6eed30e492cc98185626f1f9 $
40    */
41    @Component
42    @Named("org.xwiki.rest.internal.resources.spaces.SpacesResourceImpl")
 
43    public class SpacesResourceImpl extends XWikiResource implements SpacesResource
44    {
 
45  10 toggle @Override
46    public Spaces getSpaces(String wikiName, Integer start, Integer number)
47    throws XWikiRestException
48    {
49  10 Spaces spaces = objectFactory.createSpaces();
50   
51  10 try {
52  10 List<String> spaceNames = queryManager.getNamedQuery("getSpaces").addFilter(
53    componentManager.<QueryFilter>getInstance(QueryFilter.class, "hidden")).setOffset(start)
54    .setLimit(number).setWiki(wikiName).execute();
55   
56  10 for (String spaceName : spaceNames) {
57  77 List<String> spaceList = Utils.getSpacesFromSpaceId(spaceName);
58  77 String homeId = Utils.getPageId(wikiName, spaceList, "WebHome");
59  77 Document home = null;
60   
61  77 XWiki xwikiApi = Utils.getXWikiApi(componentManager);
62  77 if (xwikiApi.hasAccessLevel("view", homeId)) {
63  77 if (xwikiApi.exists(homeId)) {
64  0 home = Utils.getXWikiApi(componentManager).getDocument(homeId);
65    }
66  77 spaces.getSpaces().add(DomainObjectFactory
67    .createSpace(objectFactory, uriInfo.getBaseUri(), wikiName, spaceList, home));
68    }
69    }
70    } catch (Exception e) {
71  0 throw new XWikiRestException(e);
72    }
73   
74  10 return spaces;
75    }
76    }