| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
| 40 |
|
|
| 41 |
|
@Component |
| 42 |
|
@Named("org.xwiki.rest.internal.resources.spaces.SpacesResourceImpl") |
| |
|
| 78.9% |
Uncovered Elements: 4 (19) |
Complexity: 4 |
Complexity Density: 0.29 |
|
| 43 |
|
public class SpacesResourceImpl extends XWikiResource implements SpacesResource |
| 44 |
|
{ |
| |
|
| 77.8% |
Uncovered Elements: 4 (18) |
Complexity: 4 |
Complexity Density: 0.29 |
|
| 45 |
10 |
@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 |
|
} |