Search in sources :

Example 6 with Pages

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);
}
Also used : Pages(org.xwiki.rest.model.jaxb.Pages) GetMethod(org.apache.commons.httpclient.methods.GetMethod) WikiPagesResource(org.xwiki.rest.resources.wikis.WikiPagesResource) PageSummary(org.xwiki.rest.model.jaxb.PageSummary) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 7 with Pages

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);
    }
}
Also used : Pages(org.xwiki.rest.model.jaxb.Pages) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 8 with Pages

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);
    }
}
Also used : Pages(org.xwiki.rest.model.jaxb.Pages) RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) ArrayList(java.util.ArrayList) Document(com.xpn.xwiki.api.Document) QueryException(org.xwiki.query.QueryException) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 9 with Pages

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;
}
Also used : Pages(org.xwiki.rest.model.jaxb.Pages) Pattern(java.util.regex.Pattern) QueryFilter(org.xwiki.query.QueryFilter) Query(org.xwiki.query.Query) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiRestException(org.xwiki.rest.XWikiRestException)

Aggregations

Pages (org.xwiki.rest.model.jaxb.Pages)9 GetMethod (org.apache.commons.httpclient.methods.GetMethod)5 PageSummary (org.xwiki.rest.model.jaxb.PageSummary)5 Document (com.xpn.xwiki.api.Document)4 Test (org.junit.Test)4 XWikiRestException (org.xwiki.rest.XWikiRestException)4 Link (org.xwiki.rest.model.jaxb.Link)4 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)4 Query (org.xwiki.query.Query)2 QueryException (org.xwiki.query.QueryException)2 Page (org.xwiki.rest.model.jaxb.Page)2 Space (org.xwiki.rest.model.jaxb.Space)2 Spaces (org.xwiki.rest.model.jaxb.Spaces)2 Wiki (org.xwiki.rest.model.jaxb.Wiki)2 Wikis (org.xwiki.rest.model.jaxb.Wikis)2 PageResource (org.xwiki.rest.resources.pages.PageResource)2 WikisResource (org.xwiki.rest.resources.wikis.WikisResource)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1