use of org.xwiki.rest.model.jaxb.History 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());
}
}
}
use of org.xwiki.rest.model.jaxb.History 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());
}
}
use of org.xwiki.rest.model.jaxb.History 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());
}
use of org.xwiki.rest.model.jaxb.History 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;
}
use of org.xwiki.rest.model.jaxb.History 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;
}
Aggregations