Search in sources :

Example 1 with Attachment

use of com.enonic.xp.attachment.Attachment in project xp by enonic.

the class GetAttachmentStreamHandlerTest method getById_AttachmentNotFound.

@Test
public void getById_AttachmentNotFound() throws Exception {
    final Content content = TestDataFixtures.newContent();
    final Attachment attachment = content.getAttachments().byName("document.pdf");
    Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
    Mockito.when(this.contentService.getBinary(content.getId(), attachment.getBinaryReference())).thenReturn(ByteSource.wrap(ATTACHMENT_DATA));
    runFunction("/test/GetAttachmentStreamHandlerTest.js", "getAttachmentStreamById_AttachmentNotFound");
}
Also used : Content(com.enonic.xp.content.Content) Attachment(com.enonic.xp.attachment.Attachment) Test(org.junit.jupiter.api.Test)

Example 2 with Attachment

use of com.enonic.xp.attachment.Attachment in project xp by enonic.

the class GetAttachmentStreamHandlerTest method mockAttachmentBinary.

private void mockAttachmentBinary() {
    final Content content = TestDataFixtures.newContent();
    final Attachment attachment = content.getAttachments().byName("document.pdf");
    Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
    Mockito.when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    Mockito.when(this.contentService.getBinary(content.getId(), attachment.getBinaryReference())).thenReturn(ByteSource.wrap(ATTACHMENT_DATA));
}
Also used : Content(com.enonic.xp.content.Content) Attachment(com.enonic.xp.attachment.Attachment)

Example 3 with Attachment

use of com.enonic.xp.attachment.Attachment in project xp by enonic.

the class TestDataFixtures method newAttachments.

public static Attachments newAttachments() {
    final Attachment a1 = Attachment.create().name("logo.png").mimeType("image/png").label("small").size(6789).build();
    final Attachment a2 = Attachment.create().name("document.pdf").mimeType("application/pdf").size(12345).build();
    return Attachments.from(a1, a2);
}
Also used : Attachment(com.enonic.xp.attachment.Attachment)

Example 4 with Attachment

use of com.enonic.xp.attachment.Attachment in project xp by enonic.

the class AttachmentHandlerWorker method resolveAttachment.

private Attachment resolveAttachment(final Content content, final String name) {
    final Attachments attachments = content.getAttachments();
    final Attachment attachment = attachments.byName(name);
    if (attachment != null) {
        return attachment;
    }
    throw WebException.notFound(String.format("Attachment [%s] not found for [%s]", name, content.getPath()));
}
Also used : ServletRequestUrlHelper.contentDispositionAttachment(com.enonic.xp.web.servlet.ServletRequestUrlHelper.contentDispositionAttachment) Attachment(com.enonic.xp.attachment.Attachment) Attachments(com.enonic.xp.attachment.Attachments)

Example 5 with Attachment

use of com.enonic.xp.attachment.Attachment in project xp by enonic.

the class AttachmentUrlBuilder method resolveAttachment.

private Attachment resolveAttachment(final Content content) {
    final Attachments attachments = content.getAttachments();
    final Attachment attachment;
    if (this.params.getName() != null) {
        attachment = attachments.byName(this.params.getName());
        if (attachment == null) {
            throw new IllegalArgumentException("Could not find attachment with name [" + this.params.getName() + "] on content [" + content.getId() + "]");
        }
    } else {
        final String label = this.params.getLabel() != null ? this.params.getLabel() : "source";
        attachment = attachments.byLabel(label);
        if (attachment == null) {
            throw new IllegalArgumentException("Could not find attachment with label [" + label + "] on content [" + content.getId() + "]");
        }
    }
    return attachment;
}
Also used : Attachment(com.enonic.xp.attachment.Attachment) Attachments(com.enonic.xp.attachment.Attachments)

Aggregations

Attachment (com.enonic.xp.attachment.Attachment)29 Content (com.enonic.xp.content.Content)14 BinaryReference (com.enonic.xp.util.BinaryReference)12 ByteSource (com.google.common.io.ByteSource)11 ContentId (com.enonic.xp.content.ContentId)10 Attachments (com.enonic.xp.attachment.Attachments)9 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)6 Media (com.enonic.xp.content.Media)6 ReadImageParams (com.enonic.xp.image.ReadImageParams)6 Test (org.junit.jupiter.api.Test)5 PropertyTree (com.enonic.xp.data.PropertyTree)4 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)3 ContentPath (com.enonic.xp.content.ContentPath)2 ContentService (com.enonic.xp.content.ContentService)2 UpdateMediaParams (com.enonic.xp.content.UpdateMediaParams)2 Thumbnail (com.enonic.xp.icon.Thumbnail)2 PortalRequest (com.enonic.xp.portal.PortalRequest)2 PortalResponse (com.enonic.xp.portal.PortalResponse)2 ProcessHtmlParams (com.enonic.xp.portal.url.ProcessHtmlParams)2 ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)2