Search in sources :

Example 1 with Wikis

use of org.xwiki.rest.model.jaxb.Wikis in project xwiki-platform by xwiki.

the class WikiManagerRestTest method testCreateWiki.

@Test
public void testCreateWiki() throws Exception {
    String WIKI_ID = "foo";
    Wiki wiki = objectFactory.createWiki();
    wiki.setId(WIKI_ID);
    PostMethod postMethod = executePost(getFullUri(WikiManagerREST.class), "superadmin", "pass", wiki);
    Assert.assertEquals(HttpStatus.SC_CREATED, postMethod.getStatusCode());
    wiki = (Wiki) unmarshaller.unmarshal(postMethod.getResponseBodyAsStream());
    Assert.assertEquals(WIKI_ID, wiki.getId());
    GetMethod getMethod = executeGet(getFullUri(WikisResource.class));
    Assert.assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
    Wikis wikis = (Wikis) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    boolean found = false;
    for (Wiki w : wikis.getWikis()) {
        if (WIKI_ID.equals(w.getId())) {
            found = true;
            break;
        }
    }
    Assert.assertTrue(found);
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Wikis(org.xwiki.rest.model.jaxb.Wikis) Wiki(org.xwiki.rest.model.jaxb.Wiki) WikiManagerREST(org.xwiki.wiki.rest.WikiManagerREST) WikisResource(org.xwiki.rest.resources.wikis.WikisResource) Test(org.junit.Test)

Example 2 with Wikis

use of org.xwiki.rest.model.jaxb.Wikis in project xwiki-platform by xwiki.

the class WikisResourceImpl method getWikis.

@Override
public Wikis getWikis() throws XWikiRestException {
    try {
        Wikis wikis = objectFactory.createWikis();
        for (String wikiId : this.wikiDescriptorManager.getAllIds()) {
            // Allow listing a wiki if:
            // - the user has view access to it
            // - or the wiki accepts global users and is not an invitation-based wiki
            // - or the current user has a pending invitation to the wiki
            // Note 1: To check if a user has view access to a wiki we check if the user can access the home page
            // of the "XWiki" space. We do this because this needs to be allowed in view for the wiki to
            // work properly.
            // Note 2: it would be nicer to have an API for this.
            // Note 3: this strategy is copied from WikisLiveTableResults.xml
            EntityReference absoluteCommentReference = new EntityReference(this.defaultDocumentReferenceProvider.get().getName(), EntityType.DOCUMENT, new EntityReference("XWiki", EntityType.SPACE, new EntityReference(wikiId, EntityType.WIKI)));
            DocumentReference currentUserReference = getXWikiContext().getUserReference();
            if (this.authorizationManager.hasAccess(Right.VIEW, absoluteCommentReference) || (this.wikiUserManager.getUserScope(wikiId) != UserScope.LOCAL_ONLY && this.wikiUserManager.getMembershipType(wikiId) != MembershipType.INVITE) || this.wikiUserManager.hasPendingInvitation(currentUserReference, wikiId)) {
                wikis.getWikis().add(DomainObjectFactory.createWiki(objectFactory, uriInfo.getBaseUri(), wikiId));
            }
        }
        String queryUri = Utils.createURI(uriInfo.getBaseUri(), WikisSearchQueryResource.class).toString();
        Link queryLink = objectFactory.createLink();
        queryLink.setHref(queryUri);
        queryLink.setRel(Relations.QUERY);
        wikis.getLinks().add(queryLink);
        return wikis;
    } catch (Exception e) {
        throw new XWikiRestException("Failed to get the list of wikis", e);
    }
}
Also used : WikisSearchQueryResource(org.xwiki.rest.resources.wikis.WikisSearchQueryResource) XWikiRestException(org.xwiki.rest.XWikiRestException) Wikis(org.xwiki.rest.model.jaxb.Wikis) EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Link(org.xwiki.rest.model.jaxb.Link) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 3 with Wikis

use of org.xwiki.rest.model.jaxb.Wikis in project xwiki-platform by xwiki.

the class PageResourceTest method getFirstPage.

private Page getFirstPage() throws Exception {
    GetMethod getMethod = executeGet(getFullUri(WikisResource.class));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Wikis wikis = (Wikis) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(wikis.getWikis().size() > 0);
    Wiki wiki = wikis.getWikis().get(0);
    // Get a link to an index of spaces (http://localhost:8080/xwiki/rest/wikis/xwiki/spaces)
    Link spacesLink = getFirstLinkByRelation(wiki, Relations.SPACES);
    Assert.assertNotNull(spacesLink);
    getMethod = executeGet(spacesLink.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Spaces spaces = (Spaces) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(spaces.getSpaces().size() > 0);
    Space space = null;
    for (final Space s : spaces.getSpaces()) {
        if (this.space.equals(s.getName())) {
            space = s;
            break;
        }
    }
    // get the pages list for the space
    // eg: http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages
    Link pagesInSpace = getFirstLinkByRelation(space, Relations.PAGES);
    Assert.assertNotNull(pagesInSpace);
    getMethod = executeGet(pagesInSpace.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Pages pages = (Pages) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(pages.getPageSummaries().size() > 0);
    Link pageLink = null;
    for (final PageSummary ps : pages.getPageSummaries()) {
        if (this.pageName.equals(ps.getName())) {
            pageLink = getFirstLinkByRelation(ps, Relations.PAGE);
            Assert.assertNotNull(pageLink);
            break;
        }
    }
    Assert.assertNotNull(pageLink);
    getMethod = executeGet(pageLink.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Page page = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    return page;
}
Also used : Space(org.xwiki.rest.model.jaxb.Space) Pages(org.xwiki.rest.model.jaxb.Pages) Spaces(org.xwiki.rest.model.jaxb.Spaces) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Wikis(org.xwiki.rest.model.jaxb.Wikis) Wiki(org.xwiki.rest.model.jaxb.Wiki) Page(org.xwiki.rest.model.jaxb.Page) PageSummary(org.xwiki.rest.model.jaxb.PageSummary) Link(org.xwiki.rest.model.jaxb.Link) WikisResource(org.xwiki.rest.resources.wikis.WikisResource)

Example 4 with Wikis

use of org.xwiki.rest.model.jaxb.Wikis in project xwiki-platform by xwiki.

the class PagesResourceTest method testRepresentation.

@Override
@Test
public void testRepresentation() throws Exception {
    GetMethod getMethod = executeGet(getFullUri(WikisResource.class));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Wikis wikis = (Wikis) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(wikis.getWikis().size() > 0);
    Wiki wiki = wikis.getWikis().get(0);
    Link link = getFirstLinkByRelation(wiki, Relations.SPACES);
    Assert.assertNotNull(link);
    getMethod = executeGet(link.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Spaces spaces = (Spaces) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(spaces.getSpaces().size() > 0);
    Space space = spaces.getSpaces().get(0);
    link = getFirstLinkByRelation(space, Relations.PAGES);
    Assert.assertNotNull(link);
    getMethod = executeGet(link.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Pages pages = (Pages) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(pages.getPageSummaries().size() > 0);
    checkLinks(pages);
}
Also used : Space(org.xwiki.rest.model.jaxb.Space) Pages(org.xwiki.rest.model.jaxb.Pages) Spaces(org.xwiki.rest.model.jaxb.Spaces) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Wikis(org.xwiki.rest.model.jaxb.Wikis) Wiki(org.xwiki.rest.model.jaxb.Wiki) Link(org.xwiki.rest.model.jaxb.Link) WikisResource(org.xwiki.rest.resources.wikis.WikisResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 5 with Wikis

use of org.xwiki.rest.model.jaxb.Wikis in project xwiki-platform by xwiki.

the class SpacesResourceTest method testRepresentation.

@Override
@Test
public void testRepresentation() throws Exception {
    // Create a subspace
    createPageIfDoesntExist(Arrays.asList("SpaceA", "SpaceB", "SpaceC"), "MyPage", "some content");
    GetMethod getMethod = executeGet(getFullUri(WikisResource.class));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Wikis wikis = (Wikis) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(wikis.getWikis().size() > 0);
    Wiki wiki = wikis.getWikis().get(0);
    Link link = getFirstLinkByRelation(wiki, Relations.SPACES);
    Assert.assertNotNull(link);
    getMethod = executeGet(link.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Spaces spaces = (Spaces) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(spaces.getSpaces().size() > 0);
    boolean nestedSpaceFound = false;
    for (Space space : spaces.getSpaces()) {
        link = getFirstLinkByRelation(space, Relations.SEARCH);
        Assert.assertNotNull(link);
        checkLinks(space);
        if ("xwiki:SpaceA.SpaceB.SpaceC".equals(space.getId())) {
            Assert.assertEquals("SpaceC", space.getName());
            nestedSpaceFound = true;
        }
        /*
             * Check that in the returned spaces there are not spaces not visible to user Guest, for example the
             * "Scheduler" space
             */
        Assert.assertFalse(space.getName().equals("Scheduler"));
    }
    Assert.assertTrue(nestedSpaceFound);
}
Also used : Space(org.xwiki.rest.model.jaxb.Space) Spaces(org.xwiki.rest.model.jaxb.Spaces) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Wikis(org.xwiki.rest.model.jaxb.Wikis) Wiki(org.xwiki.rest.model.jaxb.Wiki) Link(org.xwiki.rest.model.jaxb.Link) WikisResource(org.xwiki.rest.resources.wikis.WikisResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Aggregations

Wikis (org.xwiki.rest.model.jaxb.Wikis)7 GetMethod (org.apache.commons.httpclient.methods.GetMethod)6 WikisResource (org.xwiki.rest.resources.wikis.WikisResource)6 Link (org.xwiki.rest.model.jaxb.Link)5 Wiki (org.xwiki.rest.model.jaxb.Wiki)5 Test (org.junit.Test)4 Space (org.xwiki.rest.model.jaxb.Space)3 Spaces (org.xwiki.rest.model.jaxb.Spaces)3 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)3 Pages (org.xwiki.rest.model.jaxb.Pages)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 EntityReference (org.xwiki.model.reference.EntityReference)1 XWikiRestException (org.xwiki.rest.XWikiRestException)1 Page (org.xwiki.rest.model.jaxb.Page)1 PageSummary (org.xwiki.rest.model.jaxb.PageSummary)1 WikisSearchQueryResource (org.xwiki.rest.resources.wikis.WikisSearchQueryResource)1 WikiManagerREST (org.xwiki.wiki.rest.WikiManagerREST)1