use of com.enonic.xp.content.UpdateMediaParams in project xp by enonic.
the class ContentServiceImplTest_media method update_media_image_invalid_file_name.
@Test
public void update_media_image_invalid_file_name() 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);
// file ending with point is illegal on Windows
final UpdateMediaParams updateMediaParams = new UpdateMediaParams().content(content.getId()).name("dart-small.").byteSource(loadImage("darth-small.jpg"));
assertThrows(IllegalArgumentException.class, () -> this.contentService.update(updateMediaParams));
}
use of com.enonic.xp.content.UpdateMediaParams in project xp by enonic.
the class ContentServiceImplTest_media method update_media_image.
@Test
public void update_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());
final UpdateMediaParams updateMediaParams = new UpdateMediaParams().content(content.getId()).name("dart-small").byteSource(loadImage("darth-small.jpg"));
this.contentService.update(updateMediaParams);
final Content updatedContent = this.contentService.getById(storedContent.getId());
final Attachments attachments = updatedContent.getAttachments();
assertNotNull(attachments);
assertEquals(1, attachments.getSize());
for (final Attachment attachment : attachments) {
assertTrue(attachment.getName().startsWith("dart-small"));
}
}
use of com.enonic.xp.content.UpdateMediaParams in project xp by enonic.
the class ParentContentSynchronizerTest method updateMediaChanged.
@Test
public void updateMediaChanged() throws Exception {
final Content sourceContent = sourceContext.callWith(() -> createMedia("media", ContentPath.ROOT));
final Content targetContent = syncCreated(sourceContent.getId());
sourceContext.runWith(() -> {
try {
contentService.update(new UpdateMediaParams().content(sourceContent.getId()).name("new name").byteSource(loadImage("darth-small.jpg")).mimeType("image/jpeg").artist("artist").copyright("copy").tags("my new tags").caption("caption"));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
final Content targetContentUpdated = syncUpdated(sourceContent.getId());
assertNotEquals(targetContent.getAttachments().first().getBinaryReference(), targetContentUpdated.getAttachments().first().getBinaryReference());
assertEquals("new name", targetContentUpdated.getAttachments().first().getName());
assertEquals("artist", targetContentUpdated.getData().getString("artist"));
assertEquals("caption", targetContentUpdated.getData().getString("caption"));
assertEquals("copy", targetContentUpdated.getData().getString("copyright"));
assertEquals("my new tags", targetContentUpdated.getData().getString("tags"));
}
use of com.enonic.xp.content.UpdateMediaParams in project xp by enonic.
the class ReprocessContentCommand method reprocessMedia.
private Content reprocessMedia(final Media media) {
final Attachment source = media.getSourceAttachment();
if (source == null) {
return media;
}
final ContentId id = media.getId();
final ByteSource binary = GetBinaryCommand.create(id, source.getBinaryReference(), this).build().execute();
final UpdateMediaParams updateMediaParams = new UpdateMediaParams().byteSource(binary).mimeType(source.getMimeType()).content(id).name(source.getName());
return UpdateMediaCommand.create(updateMediaParams, this).mediaInfoService(mediaInfoService).siteService(this.siteService).contentTypeService(this.contentTypeService).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).build().execute();
}
Aggregations