Search in sources :

Example 6 with CreateAttachments

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

the class UpdatedEventSyncCommand method doSyncThumbnail.

private void doSyncThumbnail(final ContentToSync content, final UpdateContentParams updateParams) {
    if (!Objects.equals(content.getSourceContent().getThumbnail(), content.getTargetContent().getThumbnail())) {
        final Thumbnail sourceThumbnail = content.getSourceContent().getThumbnail();
        if (sourceThumbnail != null) {
            final ByteSource sourceBinary = content.getSourceContext().callWith(() -> contentService.getBinary(content.getSourceContent().getId(), sourceThumbnail.getBinaryReference()));
            final CreateAttachment createThumbnail = CreateAttachment.create().name(AttachmentNames.THUMBNAIL).mimeType(sourceThumbnail.getMimeType()).byteSource(sourceBinary).build();
            final CreateAttachments.Builder createAttachments = CreateAttachments.create().add(createThumbnail);
            if (updateParams.getCreateAttachments() != null) {
                createAttachments.add(updateParams.getCreateAttachments());
            }
            updateParams.createAttachments(createAttachments.build());
        } else {
            final Thumbnail targetThumbnail = content.getTargetContent().getThumbnail();
            updateParams.removeAttachments(BinaryReferences.from(targetThumbnail.getBinaryReference()));
        }
    }
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ByteSource(com.google.common.io.ByteSource) Thumbnail(com.enonic.xp.icon.Thumbnail)

Example 7 with CreateAttachments

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

the class UpdateNodeParamsFactory method produce.

public UpdateNodeParams produce() {
    final Content editedContent = params.getEditedContent();
    final CreateAttachments createAttachments = params.getCreateAttachments();
    final NodeEditor nodeEditor = toNodeEditor(params);
    final UpdateNodeParams.Builder builder = UpdateNodeParams.create().id(NodeId.from(editedContent.getId())).editor(nodeEditor);
    if (createAttachments != null) {
        for (final CreateAttachment createAttachment : createAttachments) {
            builder.attachBinary(createAttachment.getBinaryReference(), createAttachment.getByteSource());
        }
    }
    return builder.build();
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) Content(com.enonic.xp.content.Content) NodeEditor(com.enonic.xp.node.NodeEditor) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams)

Example 8 with CreateAttachments

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

the class ImageContentProcessor method processCreate.

@Override
public ProcessCreateResult processCreate(final ProcessCreateParams params) {
    final CreateContentParams createContentParams = params.getCreateContentParams();
    final MediaInfo mediaInfo = params.getMediaInfo();
    final CreateAttachments originalAttachments = createContentParams.getCreateAttachments();
    Preconditions.checkArgument(originalAttachments.getSize() == 1, "Expected only one attachment");
    final CreateAttachment sourceAttachment = originalAttachments.first();
    final XDatas contentXDatas = getXDatas(createContentParams.getType());
    ExtraDatas extraDatas = null;
    if (mediaInfo != null) {
        extraDatas = extractMetadata(mediaInfo, contentXDatas, sourceAttachment);
    }
    final CreateAttachments.Builder builder = CreateAttachments.create();
    builder.add(sourceAttachment);
    return new ProcessCreateResult(CreateContentParams.create(createContentParams).createAttachments(builder.build()).extraDatas(extraDatas).build());
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) MediaInfo(com.enonic.xp.media.MediaInfo) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) CreateContentParams(com.enonic.xp.content.CreateContentParams) XDatas(com.enonic.xp.schema.xdata.XDatas) ExtraDatas(com.enonic.xp.content.ExtraDatas) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult)

Example 9 with CreateAttachments

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

the class HtmlAreaContentProcessor method processUpdate.

@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
    final CreateAttachments createAttachments = params.getCreateAttachments();
    final ContentEditor editor;
    editor = editable -> {
        final ContentIds.Builder processedIds = ContentIds.create();
        final ContentType contentType = contentTypeService.getByName(GetContentTypeParams.from(editable.source.getType()));
        processContentData(editable.data, contentType, processedIds);
        processExtraData(editable.extraDatas, processedIds);
        processPageData(editable.page, processedIds);
        if (editable instanceof EditableSite) {
            processSiteConfigData(((EditableSite) editable).siteConfigs, processedIds);
        }
        editable.processedReferences = processedIds;
    };
    return new ProcessUpdateResult(createAttachments, editor);
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ContentEditor(com.enonic.xp.content.ContentEditor) ContentType(com.enonic.xp.schema.content.ContentType) EditableSite(com.enonic.xp.content.EditableSite) ContentIds(com.enonic.xp.content.ContentIds) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult)

Example 10 with CreateAttachments

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

the class ImageContentProcessorTest method testCreateMoreThanOneAttachmentFails.

@Test
public void testCreateMoreThanOneAttachmentFails() {
    final CreateAttachments createAttachments = CreateAttachments.create().add(CreateAttachment.create().name("myAtt1").byteSource(ByteSource.wrap("this is 1st stuff".getBytes())).text("This is the text").build()).add(CreateAttachment.create().name("myAtt2").byteSource(ByteSource.wrap("this is 2nd stuff".getBytes())).text("This is the text").build()).build();
    final CreateContentParams params = createContentParams(createAttachments);
    final ProcessCreateParams processCreateParams = new ProcessCreateParams(params, MediaInfo.create().build());
    assertThrows(IllegalArgumentException.class, () -> this.imageContentProcessor.processCreate(processCreateParams));
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) CreateContentParams(com.enonic.xp.content.CreateContentParams) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Test(org.junit.jupiter.api.Test)

Aggregations

CreateAttachments (com.enonic.xp.attachment.CreateAttachments)16 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)11 CreateContentParams (com.enonic.xp.content.CreateContentParams)10 Test (org.junit.jupiter.api.Test)10 PropertyTree (com.enonic.xp.data.PropertyTree)9 ByteSource (com.google.common.io.ByteSource)9 Content (com.enonic.xp.content.Content)8 ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)7 ContentPath (com.enonic.xp.content.ContentPath)6 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)6 AttachmentNames (com.enonic.xp.attachment.AttachmentNames)5 ExtraDatas (com.enonic.xp.content.ExtraDatas)5 ContentPropertyNames (com.enonic.xp.content.ContentPropertyNames)4 ExtraData (com.enonic.xp.content.ExtraData)4 List (java.util.List)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 Attachments (com.enonic.xp.attachment.Attachments)3 ContentId (com.enonic.xp.content.ContentId)3