use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class ObjectsAtPageVersionResourceImpl method getObjects.
@Override
public Objects getObjects(String wikiName, String spaceName, String pageName, String version, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
Document doc = documentInfo.getDocument();
Objects objects = objectFactory.createObjects();
List<com.xpn.xwiki.objects.BaseObject> objectList = getBaseObjects(doc);
RangeIterable<com.xpn.xwiki.objects.BaseObject> ri = new RangeIterable<com.xpn.xwiki.objects.BaseObject>(objectList, start, number);
for (com.xpn.xwiki.objects.BaseObject object : ri) {
/* By deleting objects, some of them might become null, so we must check for this */
if (object != null) {
objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, true, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
return objects;
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class ObjectsResourceImpl method getObjects.
@Override
public Objects getObjects(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();
Objects objects = objectFactory.createObjects();
List<BaseObject> objectList = getBaseObjects(doc);
RangeIterable<BaseObject> ri = new RangeIterable<BaseObject>(objectList, start, number);
for (BaseObject object : ri) {
/* By deleting objects, some of them might become null, so we must check for this */
if (object != null) {
objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, false, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
return objects;
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException 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.XWikiRestException 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.XWikiRestException in project xwiki-platform by xwiki.
the class PageResourceImpl method deletePage.
@Override
public void deletePage(String wikiName, String spaceName, String pageName) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, true);
deletePage(documentInfo);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
Aggregations