Search in sources :

Example 1 with Attachments

use of com.enonic.xp.attachment.Attachments 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 2 with Attachments

use of com.enonic.xp.attachment.Attachments 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)

Example 3 with Attachments

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

the class ContentDataSerializer method toUpdateNodeData.

public PropertyTree toUpdateNodeData(final UpdateContentTranslatorParams params) {
    final PropertyTree newPropertyTree = new PropertyTree();
    final PropertySet contentAsData = newPropertyTree.getRoot();
    final Content content = params.getEditedContent();
    addMetadata(contentAsData, content, params.getModifier());
    contentAsData.addSet(DATA, content.getData().getRoot().copy(contentAsData.getTree()));
    if (content.hasExtraData()) {
        extraDataSerializer.toData(content.getAllExtraData(), contentAsData);
    }
    final Attachments attachments = mergeExistingAndUpdatedAttachments(content.getAttachments(), params);
    applyAttachmentsAsData(attachments, contentAsData);
    if (content.hasPage()) {
        pageDataSerializer.toData(content.getPage(), contentAsData);
    }
    addProcessedReferences(contentAsData, content.getProcessedReferences());
    return newPropertyTree;
}
Also used : Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) Attachments(com.enonic.xp.attachment.Attachments)

Example 4 with Attachments

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

the class ContentServiceImplTest_create method create_with_attachments.

@Test
public void create_with_attachments() throws Exception {
    final String name = "cat-small.jpg";
    final ByteSource image = loadImage(name);
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.imageMedia()).createAttachments(createAttachment("cat", "image/jpeg", image)).build();
    final Content content = this.contentService.create(createContentParams);
    final Content storedContent = this.contentService.getById(content.getId());
    final Attachments attachments = storedContent.getAttachments();
    assertEquals(1, attachments.getSize());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ByteSource(com.google.common.io.ByteSource) Attachments(com.enonic.xp.attachment.Attachments) Test(org.junit.jupiter.api.Test)

Example 5 with Attachments

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

the class ContentServiceImplTest_media method create_media_image.

@Test
public void create_media_image() throws Exception {
    final CreateMediaParams createMediaParams = new CreateMediaParams();
    createMediaParams.byteSource(loadImage("cat-small.jpg")).name("Small cat").parent(ContentPath.ROOT);
    Mockito.when(this.xDataService.getFromContentType(Mockito.any(ContentType.class))).thenReturn(XDatas.empty());
    final Content content = this.contentService.create(createMediaParams);
    final Content storedContent = this.contentService.getById(content.getId());
    assertNotNull(storedContent.getName());
    assertNotNull(storedContent.getCreatedTime());
    assertNotNull(storedContent.getCreator());
    assertNotNull(storedContent.getModifiedTime());
    assertNotNull(storedContent.getModifier());
    assertNotNull(storedContent.getData().getString(ContentPropertyNames.MEDIA));
    final Attachments attachments = storedContent.getAttachments();
    assertEquals(1, attachments.getSize());
}
Also used : CreateMediaParams(com.enonic.xp.content.CreateMediaParams) ContentType(com.enonic.xp.schema.content.ContentType) Content(com.enonic.xp.content.Content) Attachments(com.enonic.xp.attachment.Attachments) Test(org.junit.jupiter.api.Test)

Aggregations

Attachments (com.enonic.xp.attachment.Attachments)13 Content (com.enonic.xp.content.Content)10 Test (org.junit.jupiter.api.Test)8 Attachment (com.enonic.xp.attachment.Attachment)7 CreateMediaParams (com.enonic.xp.content.CreateMediaParams)4 ContentType (com.enonic.xp.schema.content.ContentType)4 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 ProcessHtmlParams (com.enonic.xp.portal.url.ProcessHtmlParams)2 ByteSource (com.google.common.io.ByteSource)2 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)1 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)1 UpdateMediaParams (com.enonic.xp.content.UpdateMediaParams)1 ContentConfig (com.enonic.xp.core.impl.content.ContentConfig)1 PropertySet (com.enonic.xp.data.PropertySet)1 Thumbnail (com.enonic.xp.icon.Thumbnail)1 BinaryReference (com.enonic.xp.util.BinaryReference)1 ServletRequestUrlHelper.contentDispositionAttachment (com.enonic.xp.web.servlet.ServletRequestUrlHelper.contentDispositionAttachment)1