Search in sources :

Example 1 with HistorySummary

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

the class CommentsResourceTest method testGETCommentsAtPreviousVersions.

@Test
public void testGETCommentsAtPreviousVersions() throws Exception {
    String pageHistoryUri = buildURI(PageHistoryResource.class, getWiki(), this.spaces, this.pageName).toString();
    GetMethod getMethod = executeGet(pageHistoryUri);
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    History history = (History) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    for (HistorySummary historySummary : history.getHistorySummaries()) {
        getMethod = executeGet(getFirstLinkByRelation(historySummary, Relations.PAGE).getHref());
        Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
        Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
        if (getFirstLinkByRelation(page, Relations.COMMENTS) != null) {
            getMethod = executeGet(getFirstLinkByRelation(page, Relations.COMMENTS).getHref());
            Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
        }
    }
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) HistorySummary(org.xwiki.rest.model.jaxb.HistorySummary) Page(org.xwiki.rest.model.jaxb.Page) PageHistoryResource(org.xwiki.rest.resources.pages.PageHistoryResource) History(org.xwiki.rest.model.jaxb.History) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 2 with HistorySummary

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

the class PageResourceTest method testPageTranslationHistory.

@Test
public void testPageTranslationHistory() throws Exception {
    String pageHistoryUri = buildURI(PageHistoryResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TRANSLATIONS_PAGE_NAME).toString();
    GetMethod getMethod = executeGet(pageHistoryUri);
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    History history = (History) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    for (HistorySummary historySummary : history.getHistorySummaries()) {
        getMethod = executeGet(getFirstLinkByRelation(historySummary, Relations.PAGE).getHref());
        Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
        Page page = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
        checkLinks(page);
        checkLinks(page.getTranslations());
    }
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) HistorySummary(org.xwiki.rest.model.jaxb.HistorySummary) Page(org.xwiki.rest.model.jaxb.Page) PageHistoryResource(org.xwiki.rest.resources.pages.PageHistoryResource) History(org.xwiki.rest.model.jaxb.History) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 3 with HistorySummary

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

the class PageResourceTest method testPageHistory.

@Test
public void testPageHistory() throws Exception {
    GetMethod getMethod = executeGet(buildURI(PageResource.class, getWiki(), this.spaces, this.pageName).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Page originalPage = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertEquals(this.spaces.get(0), originalPage.getSpace());
    String pageHistoryUri = buildURI(PageHistoryResource.class, getWiki(), this.spaces, originalPage.getName()).toString();
    getMethod = executeGet(pageHistoryUri);
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    History history = (History) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    HistorySummary firstVersion = null;
    for (HistorySummary historySummary : history.getHistorySummaries()) {
        if ("1.1".equals(historySummary.getVersion())) {
            firstVersion = historySummary;
        }
        getMethod = executeGet(getFirstLinkByRelation(historySummary, Relations.PAGE).getHref());
        Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
        Page page = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
        checkLinks(page);
        for (Translation translation : page.getTranslations().getTranslations()) {
            checkLinks(translation);
        }
    }
    Assert.assertNotNull(firstVersion);
    Assert.assertEquals("Test page", firstVersion.getComment());
}
Also used : Translation(org.xwiki.rest.model.jaxb.Translation) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HistorySummary(org.xwiki.rest.model.jaxb.HistorySummary) Page(org.xwiki.rest.model.jaxb.Page) PageHistoryResource(org.xwiki.rest.resources.pages.PageHistoryResource) History(org.xwiki.rest.model.jaxb.History) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 4 with HistorySummary

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

the class PageHistoryResourceImpl method getPageHistory.

@Override
public History getPageHistory(String wikiName, String spaceName, String pageName, Integer start, Integer number, String order, Boolean withPrettyNames) throws XWikiRestException {
    List<String> spaces = parseSpaceSegments(spaceName);
    String spaceId = Utils.getLocalSpaceId(spaces);
    History history = new History();
    try {
        // Note that the query is made to work with Oracle which treats empty strings as null.
        String query = String.format("select doc.space, doc.name, rcs.id, rcs.date, rcs.author, rcs.comment" + " from XWikiRCSNodeInfo as rcs, XWikiDocument as doc where rcs.id.docId = doc.id and" + " doc.space = :space and doc.name = :name and (doc.language = '' or doc.language is null)" + " order by rcs.date %s, rcs.id.version1 %s, rcs.id.version2 %s", order, order, order);
        List<Object> queryResult = null;
        queryResult = queryManager.createQuery(query, Query.XWQL).bindValue("space", spaceId).bindValue("name", pageName).setLimit(number).setOffset(start).setWiki(wikiName).execute();
        for (Object object : queryResult) {
            Object[] fields = (Object[]) object;
            XWikiRCSNodeId nodeId = (XWikiRCSNodeId) fields[2];
            Timestamp timestamp = (Timestamp) fields[3];
            Date modified = new Date(timestamp.getTime());
            String modifier = (String) fields[4];
            String comment = (String) fields[5];
            HistorySummary historySummary = DomainObjectFactory.createHistorySummary(objectFactory, uriInfo.getBaseUri(), wikiName, spaces, pageName, null, nodeId.getVersion(), modifier, modified, comment, Utils.getXWikiApi(componentManager), withPrettyNames);
            history.getHistorySummaries().add(historySummary);
        }
    } catch (QueryException e) {
        throw new XWikiRestException(e);
    }
    return history;
}
Also used : QueryException(org.xwiki.query.QueryException) XWikiRestException(org.xwiki.rest.XWikiRestException) HistorySummary(org.xwiki.rest.model.jaxb.HistorySummary) XWikiRCSNodeId(com.xpn.xwiki.doc.rcs.XWikiRCSNodeId) History(org.xwiki.rest.model.jaxb.History) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 5 with HistorySummary

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

the class PageTranslationHistoryResourceImpl method getPageTranslationHistory.

@Override
public History getPageTranslationHistory(String wikiName, String spaceName, String pageName, String language, Integer start, Integer number, String order, Boolean withPrettyNames) throws XWikiRestException {
    List<String> spaces = parseSpaceSegments(spaceName);
    String spaceId = Utils.getLocalSpaceId(spaces);
    History history = new History();
    try {
        String query = String.format("select doc.space, doc.name, rcs.id, rcs.date, rcs.author, rcs.comment" + " from XWikiRCSNodeInfo as rcs, XWikiDocument as doc where rcs.id.docId = doc.id and" + " doc.space = :space and doc.name = :name and doc.language = :language" + " order by rcs.date %s, rcs.id.version1 %s, rcs.id.version2 %s", order, order, order);
        List<Object> queryResult = null;
        queryResult = queryManager.createQuery(query, Query.XWQL).bindValue("space", spaceId).bindValue("name", pageName).setLimit(number).bindValue("language", language).setOffset(start).setWiki(wikiName).execute();
        for (Object object : queryResult) {
            Object[] fields = (Object[]) object;
            XWikiRCSNodeId nodeId = (XWikiRCSNodeId) fields[2];
            Timestamp timestamp = (Timestamp) fields[3];
            Date modified = new Date(timestamp.getTime());
            String modifier = (String) fields[4];
            String comment = (String) fields[5];
            HistorySummary historySummary = DomainObjectFactory.createHistorySummary(objectFactory, uriInfo.getBaseUri(), wikiName, spaces, pageName, language, nodeId.getVersion(), modifier, modified, comment, Utils.getXWikiApi(componentManager), withPrettyNames);
            history.getHistorySummaries().add(historySummary);
        }
    } catch (QueryException e) {
        throw new XWikiRestException(e);
    }
    return history;
}
Also used : QueryException(org.xwiki.query.QueryException) XWikiRestException(org.xwiki.rest.XWikiRestException) HistorySummary(org.xwiki.rest.model.jaxb.HistorySummary) XWikiRCSNodeId(com.xpn.xwiki.doc.rcs.XWikiRCSNodeId) History(org.xwiki.rest.model.jaxb.History) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Aggregations

HistorySummary (org.xwiki.rest.model.jaxb.HistorySummary)7 History (org.xwiki.rest.model.jaxb.History)6 XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)3 Timestamp (java.sql.Timestamp)3 Date (java.util.Date)3 GetMethod (org.apache.commons.httpclient.methods.GetMethod)3 Test (org.junit.Test)3 QueryException (org.xwiki.query.QueryException)3 XWikiRestException (org.xwiki.rest.XWikiRestException)3 Page (org.xwiki.rest.model.jaxb.Page)3 PageHistoryResource (org.xwiki.rest.resources.pages.PageHistoryResource)3 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)3 Calendar (java.util.Calendar)1 Link (org.xwiki.rest.model.jaxb.Link)1 Translation (org.xwiki.rest.model.jaxb.Translation)1