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()));
}
}
}
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());
}
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());
}
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);
}
}
Aggregations