Search in sources :

Example 1 with Thumbnail

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

use of com.enonic.xp.icon.Thumbnail in project xp by enonic.

the class ContentServiceImplTest_update method update_content_with_thumbnail_keep_on_update.

@Test
public void update_content_with_thumbnail_keep_on_update() throws Exception {
    final ByteSource thumbnail = loadImage("cat-small.jpg");
    final CreateContentParams createContentParams = CreateContentParams.create().displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).contentData(new PropertyTree()).build();
    final Content content = this.contentService.create(createContentParams);
    final UpdateContentParams updateContentParams = new UpdateContentParams();
    updateContentParams.contentId(content.getId()).editor(edit -> {
        edit.displayName = "new display name";
    }).createAttachments(CreateAttachments.from(CreateAttachment.create().byteSource(thumbnail).name(AttachmentNames.THUMBNAIL).mimeType("image/jpeg").build()));
    this.contentService.update(updateContentParams);
    final Content updatedContent = this.contentService.getById(content.getId());
    assertNotNull(updatedContent.getThumbnail());
    assertEquals(thumbnail.size(), updatedContent.getThumbnail().getSize());
    final UpdateContentParams updateContentParams2 = new UpdateContentParams();
    updateContentParams2.contentId(content.getId()).editor(edit -> {
        edit.displayName = "brand new display name";
    });
    this.contentService.update(updateContentParams2);
    final Content reUpdatedContent = this.contentService.getById(content.getId());
    assertNotNull(reUpdatedContent.getThumbnail());
    assertEquals(thumbnail.size(), reUpdatedContent.getThumbnail().getSize());
    assertEquals("brand new display name", reUpdatedContent.getDisplayName());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) LocalDateTime(java.time.LocalDateTime) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) WorkflowState(com.enonic.xp.content.WorkflowState) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) MixinName(com.enonic.xp.schema.mixin.MixinName) Mixin(com.enonic.xp.schema.mixin.Mixin) ArgumentCaptor(org.mockito.ArgumentCaptor) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ExtraData(com.enonic.xp.content.ExtraData) WorkflowCheckState(com.enonic.xp.content.WorkflowCheckState) Map(java.util.Map) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) Thumbnail(com.enonic.xp.icon.Thumbnail) XDataName(com.enonic.xp.schema.xdata.XDataName) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) ContentPath(com.enonic.xp.content.ContentPath) PropertySet(com.enonic.xp.data.PropertySet) Content(com.enonic.xp.content.Content) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) ExtraDatas(com.enonic.xp.content.ExtraDatas) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) AttachmentNames(com.enonic.xp.attachment.AttachmentNames) List(java.util.List) InputTypeName(com.enonic.xp.inputtype.InputTypeName) LocalDate(java.time.LocalDate) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Attachments(com.enonic.xp.attachment.Attachments) Input(com.enonic.xp.form.Input) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ByteSource(com.google.common.io.ByteSource) Test(org.junit.jupiter.api.Test)

Example 3 with Thumbnail

use of com.enonic.xp.icon.Thumbnail in project xp by enonic.

the class ContentServiceImplTest_update method update_thumbnail.

@Test
public void update_thumbnail() throws Exception {
    final ByteSource thumbnail = loadImage("cat-small.jpg");
    final CreateContentParams createContentParams = CreateContentParams.create().displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).contentData(new PropertyTree()).build();
    final Content content = this.contentService.create(createContentParams);
    final UpdateContentParams updateContentParams = new UpdateContentParams();
    updateContentParams.contentId(content.getId()).editor(edit -> {
        edit.displayName = "new display name";
    }).createAttachments(CreateAttachments.from(CreateAttachment.create().byteSource(thumbnail).name(AttachmentNames.THUMBNAIL).mimeType("image/jpeg").build()));
    this.contentService.update(updateContentParams);
    final Content updatedContent = this.contentService.getById(content.getId());
    assertNotNull(updatedContent.getThumbnail());
    assertEquals(thumbnail.size(), updatedContent.getThumbnail().getSize());
    final ByteSource newThumbnail = loadImage("darth-small.jpg");
    final UpdateContentParams updateContentParams2 = new UpdateContentParams();
    updateContentParams2.contentId(content.getId()).editor(edit -> {
        edit.displayName = "yet another display name";
    }).createAttachments(CreateAttachments.from(CreateAttachment.create().byteSource(newThumbnail).name(AttachmentNames.THUMBNAIL).mimeType("image/jpeg").build()));
    this.contentService.update(updateContentParams2);
    final Content reUpdatedContent = this.contentService.getById(content.getId());
    assertNotNull(reUpdatedContent.getThumbnail());
    final Thumbnail thumbnailAttachment = reUpdatedContent.getThumbnail();
    assertEquals(newThumbnail.size(), thumbnailAttachment.getSize());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) LocalDateTime(java.time.LocalDateTime) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) WorkflowState(com.enonic.xp.content.WorkflowState) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) MixinName(com.enonic.xp.schema.mixin.MixinName) Mixin(com.enonic.xp.schema.mixin.Mixin) ArgumentCaptor(org.mockito.ArgumentCaptor) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ExtraData(com.enonic.xp.content.ExtraData) WorkflowCheckState(com.enonic.xp.content.WorkflowCheckState) Map(java.util.Map) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) Thumbnail(com.enonic.xp.icon.Thumbnail) XDataName(com.enonic.xp.schema.xdata.XDataName) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) ContentPath(com.enonic.xp.content.ContentPath) PropertySet(com.enonic.xp.data.PropertySet) Content(com.enonic.xp.content.Content) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) ExtraDatas(com.enonic.xp.content.ExtraDatas) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) AttachmentNames(com.enonic.xp.attachment.AttachmentNames) List(java.util.List) InputTypeName(com.enonic.xp.inputtype.InputTypeName) LocalDate(java.time.LocalDate) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Attachments(com.enonic.xp.attachment.Attachments) Input(com.enonic.xp.form.Input) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ByteSource(com.google.common.io.ByteSource) Thumbnail(com.enonic.xp.icon.Thumbnail) Test(org.junit.jupiter.api.Test)

Example 4 with Thumbnail

use of com.enonic.xp.icon.Thumbnail in project xp by enonic.

the class ContentDataSerializer method extractAttachments.

private void extractAttachments(final PropertySet contentAsSet, final Content.Builder<?> builder) {
    final Attachments attachments = dataToAttachments(contentAsSet.getSets(ATTACHMENT));
    builder.attachments(attachments);
    final Attachment thumbnailAttachment = attachments.byName(AttachmentNames.THUMBNAIL);
    if (thumbnailAttachment != null) {
        final BinaryReference thumbnailBinaryRef = thumbnailAttachment.getBinaryReference();
        final Thumbnail thumbnail = Thumbnail.from(thumbnailBinaryRef, thumbnailAttachment.getMimeType(), thumbnailAttachment.getSize());
        builder.thumbnail(thumbnail);
    }
}
Also used : CreateAttachment(com.enonic.xp.attachment.CreateAttachment) Attachment(com.enonic.xp.attachment.Attachment) BinaryReference(com.enonic.xp.util.BinaryReference) Thumbnail(com.enonic.xp.icon.Thumbnail) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) Attachments(com.enonic.xp.attachment.Attachments)

Aggregations

CreateAttachment (com.enonic.xp.attachment.CreateAttachment)4 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)4 Thumbnail (com.enonic.xp.icon.Thumbnail)4 Attachments (com.enonic.xp.attachment.Attachments)3 ByteSource (com.google.common.io.ByteSource)3 AttachmentNames (com.enonic.xp.attachment.AttachmentNames)2 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)2 Content (com.enonic.xp.content.Content)2 ContentPath (com.enonic.xp.content.ContentPath)2 ContentPublishInfo (com.enonic.xp.content.ContentPublishInfo)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 ExtraData (com.enonic.xp.content.ExtraData)2 ExtraDatas (com.enonic.xp.content.ExtraDatas)2 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)2 WorkflowCheckState (com.enonic.xp.content.WorkflowCheckState)2 WorkflowInfo (com.enonic.xp.content.WorkflowInfo)2 WorkflowState (com.enonic.xp.content.WorkflowState)2 PropertySet (com.enonic.xp.data.PropertySet)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Input (com.enonic.xp.form.Input)2