use of org.xwiki.rest.model.jaxb.Attachments in project xwiki-platform by xwiki.
the class SpacesResourceTest method testAttachments.
@Test
public void testAttachments() throws Exception {
DocumentReference reference = new DocumentReference(getWiki(), getTestClassName(), getTestMethodName());
this.testUtils.rest().delete(reference);
this.testUtils.rest().savePage(reference);
this.testUtils.rest().attachFile(new AttachmentReference("attachment.txt", reference), new ReaderInputStream(new StringReader("content")), true);
// Matches Sandbox.WebHome@XWikLogo.png
GetMethod getMethod = executeGet(String.format("%s", buildURI(SpaceAttachmentsResource.class, getWiki(), Arrays.asList(getTestClassName()))));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Attachments attachments = (Attachments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(getAttachmentsInfo(attachments), 1, attachments.getAttachments().size());
for (Attachment attachment : attachments.getAttachments()) {
checkLinks(attachment);
}
}
use of org.xwiki.rest.model.jaxb.Attachments in project xwiki-platform by xwiki.
the class WikisResourceTest method testAttachments.
@Test
public void testAttachments() throws Exception {
this.testUtils.rest().delete(reference);
this.testUtils.rest().attachFile(new AttachmentReference(getTestClassName() + ".txt", reference), new ReaderInputStream(new StringReader("attachment content")), true);
// Verify there are attachments in the whole wiki
GetMethod getMethod = executeGet(buildURI(WikiAttachmentsResource.class, getWiki()).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Attachments attachments = (Attachments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertTrue(attachments.getAttachments().size() > 0);
for (Attachment attachment : attachments.getAttachments()) {
checkLinks(attachment);
}
// Verify we can search for a specific attachment name in the whole wiki
getMethod = executeGet(String.format("%s?name=" + getTestClassName(), buildURI(WikiAttachmentsResource.class, getWiki())));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
attachments = (Attachments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(getAttachmentsInfo(attachments), 1, attachments.getAttachments().size());
for (Attachment attachment : attachments.getAttachments()) {
checkLinks(attachment);
}
// Verify we can search for all attachments in a given space (sandbox)
// Also verify that a space can be looked up independtly of its case ("sandbox" will match the "Sandbox" space)
getMethod = executeGet(String.format("%s?space=" + getTestClassName(), buildURI(WikiAttachmentsResource.class, getWiki())));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
attachments = (Attachments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(getAttachmentsInfo(attachments), 1, attachments.getAttachments().size());
for (Attachment attachment : attachments.getAttachments()) {
checkLinks(attachment);
}
// Verify we can search for an attachment in a given space (sandbox)
getMethod = executeGet(String.format("%s?name=" + getTestClassName() + "&space=" + getTestClassName(), buildURI(WikiAttachmentsResource.class, getWiki())));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
attachments = (Attachments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(getAttachmentsInfo(attachments), 1, attachments.getAttachments().size());
for (Attachment attachment : attachments.getAttachments()) {
checkLinks(attachment);
}
}
use of org.xwiki.rest.model.jaxb.Attachments 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);
}
}
Aggregations