use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class PageResourceImpl method getPage.
@Override
public Page getPage(String wikiName, String spaceName, String pageName, Boolean withPrettyNames, Boolean withObjects, Boolean withXClass, Boolean withAttachments) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
URI baseUri = uriInfo.getBaseUri();
Page page = this.factory.toRestPage(baseUri, uriInfo.getAbsolutePath(), doc, false, withPrettyNames, withObjects, withXClass, withAttachments);
return page;
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException 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;
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class AttachmentHistoryResourceImpl method getAttachmentHistory.
@Override
public Attachments getAttachmentHistory(String wikiName, String spaceName, String pageName, String attachmentName, Integer start, Integer number) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
final com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName);
if (xwikiAttachment == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
Attachments attachments = new Attachments();
Version[] versions = xwikiAttachment.getVersions();
List<Version> versionList = new ArrayList<Version>();
for (Version version : versions) {
versionList.add(version);
}
RangeIterable<Version> ri = new RangeIterable<Version>(versionList, start, number);
for (Version version : ri) {
com.xpn.xwiki.api.Attachment xwikiAttachmentAtVersion = xwikiAttachment.getAttachmentRevision(version.toString());
URL url = Utils.getXWikiContext(componentManager).getURLFactory().createAttachmentRevisionURL(attachmentName, spaceName, doc.getName(), version.toString(), null, wikiName, Utils.getXWikiContext(componentManager));
String attachmentXWikiAbsoluteUrl = url.toString();
String attachmentXWikiRelativeUrl = Utils.getXWikiContext(componentManager).getURLFactory().getURL(url, Utils.getXWikiContext(componentManager));
attachments.getAttachments().add(DomainObjectFactory.createAttachmentAtVersion(objectFactory, uriInfo.getBaseUri(), xwikiAttachmentAtVersion, attachmentXWikiRelativeUrl, attachmentXWikiAbsoluteUrl, Utils.getXWikiApi(componentManager), false));
}
return attachments;
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class AttachmentResourceImpl method putAttachment.
@Override
public Response putAttachment(String wikiName, String spaceName, String pageName, String attachmentName, byte[] content) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, true);
Document doc = documentInfo.getDocument();
if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
/* Attach the file */
AttachmentInfo attachmentInfo = storeAttachment(doc, attachmentName, content);
if (attachmentInfo.isAlreadyExisting()) {
return Response.status(Status.ACCEPTED).entity(attachmentInfo.getAttachment()).build();
} else {
return Response.created(uriInfo.getAbsolutePath()).entity(attachmentInfo.getAttachment()).build();
}
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class AttachmentResourceImpl method deleteAttachment.
@Override
public void deleteAttachment(String wikiName, String spaceName, String pageName, String attachmentName) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, true);
Document doc = documentInfo.getDocument();
if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName);
if (xwikiAttachment == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
XWikiAttachment baseXWikiAttachment = xwikiDocument.getAttachment(attachmentName);
xwikiDocument.removeAttachment(baseXWikiAttachment);
Utils.getXWiki(componentManager).saveDocument(xwikiDocument, "Deleted attachment [" + baseXWikiAttachment.getFilename() + "]", Utils.getXWikiContext(componentManager));
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
Aggregations