use of org.xwiki.rest.model.jaxb.Pages in project xwiki-platform by xwiki.
the class WikisResourceTest method testPages.
@Test
public void testPages() throws Exception {
// Create a clean test page.
this.testUtils.rest().delete(this.reference);
this.testUtils.rest().savePage(this.reference);
// Get all pages
GetMethod getMethod = executeGet(String.format("%s", buildURI(WikiPagesResource.class, getWiki())));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Pages pages = (Pages) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertTrue(pages.getPageSummaries().size() > 0);
for (PageSummary pageSummary : pages.getPageSummaries()) {
checkLinks(pageSummary);
}
// Get all pages having a document name that contains "WebHome" (for all spaces)
getMethod = executeGet(String.format("%s?name=" + this.pageName, buildURI(WikiPagesResource.class, getWiki())));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
pages = (Pages) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
List<PageSummary> pageSummaries = pages.getPageSummaries();
Assert.assertTrue(pageSummaries.size() == 1);
PageSummary pageSummary = pageSummaries.get(0);
assertEquals(this.fullName, pageSummary.getFullName());
checkLinks(pageSummary);
// Get all pages having a document name that contains "WebHome" and a space with an "s" in its name.
getMethod = executeGet(String.format("%s?name=" + this.pageName + "&space=" + this.fullName.charAt(2), buildURI(WikiPagesResource.class, getWiki())));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
pages = (Pages) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
pageSummaries = pages.getPageSummaries();
Assert.assertTrue(pageSummaries.size() == 1);
pageSummary = pageSummaries.get(0);
assertEquals(this.fullName, pageSummary.getFullName());
checkLinks(pageSummary);
}
use of org.xwiki.rest.model.jaxb.Pages in project xwiki-platform by xwiki.
the class PageChildrenResourceImpl method getPageChildren.
@Override
public Pages getPageChildren(String wikiName, String spaceName, String pageName, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
Pages pages = objectFactory.createPages();
/* Use an explicit query to improve performance */
String queryString = "select distinct doc.fullName from XWikiDocument as doc where doc.parent = :parent order by doc.fullName asc";
List<String> childPageFullNames = queryManager.createQuery(queryString, Query.XWQL).bindValue("parent", doc.getFullName()).setOffset(start).setLimit(number).execute();
for (String childPageFullName : childPageFullNames) {
String pageId = Utils.getPageId(wikiName, childPageFullName);
if (!Utils.getXWikiApi(componentManager).exists(pageId)) {
getLogger().warn("Page [{}] appears to be in space [{}] but no information is available.", pageName, spaceName);
} else {
Document childDoc = Utils.getXWikiApi(componentManager).getDocument(pageId);
/* We only add pages we have the right to access */
if (childDoc != null) {
pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, uriInfo.getBaseUri(), childDoc, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
}
return pages;
} catch (Exception e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.model.jaxb.Pages in project xwiki-platform by xwiki.
the class PagesForTagsResourceImpl method getTags.
@Override
public Pages getTags(String wikiName, String tagNames, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
Pages pages = objectFactory.createPages();
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
String[] tagNamesArray = tagNames.split(",");
List<String> documentNames = new ArrayList<String>();
for (String tagName : tagNamesArray) {
List<String> documentNamesForTag = getDocumentsWithTag(tagName);
/* Avoid duplicates */
for (String documentName : documentNamesForTag) {
if (!documentNames.contains(documentName)) {
documentNames.add(documentName);
}
}
}
RangeIterable<String> ri = new RangeIterable<String>(documentNames, start, number);
for (String documentName : ri) {
Document doc = Utils.getXWikiApi(componentManager).getDocument(documentName);
if (doc != null) {
pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, uriInfo.getBaseUri(), doc, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
return pages;
} catch (Exception e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
use of org.xwiki.rest.model.jaxb.Pages in project xwiki-platform by xwiki.
the class PagesResourceImpl method getPages.
@Override
public Pages getPages(String wikiName, String spaceName, Integer start, Integer number, String parentFilterExpression, String order, Boolean withPrettyNames) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
List<String> spaces = parseSpaceSegments(spaceName);
String spaceId = Utils.getLocalSpaceId(spaces);
Pages pages = objectFactory.createPages();
try {
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
Query query = ("date".equals(order)) ? queryManager.createQuery("select doc.name from Document doc where doc.space=:space and language='' order by doc.date desc", "xwql") : queryManager.getNamedQuery("getSpaceDocsName");
/* Use an explicit query to improve performance */
List<String> pageNames = query.addFilter(componentManager.<QueryFilter>getInstance(QueryFilter.class, "hidden")).bindValue("space", spaceId).setOffset(start).setLimit(number).execute();
Pattern parentFilter = null;
if (parentFilterExpression != null) {
if (parentFilterExpression.equals("null")) {
parentFilter = Pattern.compile("");
} else {
parentFilter = Pattern.compile(parentFilterExpression);
}
}
for (String pageName : pageNames) {
String pageFullName = Utils.getPageId(wikiName, spaces, pageName);
if (!Utils.getXWikiApi(componentManager).exists(pageFullName)) {
getLogger().warn("Page [{}] appears to be in space [{}] but no information is available.", pageName, spaceId);
} else {
Document doc = Utils.getXWikiApi(componentManager).getDocument(pageFullName);
/* We only add pages we have the right to access */
if (doc != null) {
boolean add = true;
Document parent = Utils.getParentDocument(doc, Utils.getXWikiApi(componentManager));
if (parentFilter != null) {
String parentId = "";
if (parent != null && !parent.isNew()) {
parentId = parent.getPrefixedFullName();
}
add = parentFilter.matcher(parentId).matches();
}
if (add) {
pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, uriInfo.getBaseUri(), doc, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
}
}
} catch (Exception e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
return pages;
}
Aggregations