Search in sources :

Example 1 with UpdateMediaParams

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));
}
Also used : CreateMediaParams(com.enonic.xp.content.CreateMediaParams) UpdateMediaParams(com.enonic.xp.content.UpdateMediaParams) ContentType(com.enonic.xp.schema.content.ContentType) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 2 with 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"));
    }
}
Also used : CreateMediaParams(com.enonic.xp.content.CreateMediaParams) UpdateMediaParams(com.enonic.xp.content.UpdateMediaParams) ContentType(com.enonic.xp.schema.content.ContentType) Content(com.enonic.xp.content.Content) Attachment(com.enonic.xp.attachment.Attachment) Attachments(com.enonic.xp.attachment.Attachments) Test(org.junit.jupiter.api.Test)

Example 3 with UpdateMediaParams

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"));
}
Also used : UpdateMediaParams(com.enonic.xp.content.UpdateMediaParams) Content(com.enonic.xp.content.Content) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 4 with UpdateMediaParams

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();
}
Also used : UpdateMediaParams(com.enonic.xp.content.UpdateMediaParams) ByteSource(com.google.common.io.ByteSource) Attachment(com.enonic.xp.attachment.Attachment) ContentId(com.enonic.xp.content.ContentId)

Aggregations

UpdateMediaParams (com.enonic.xp.content.UpdateMediaParams)4 Content (com.enonic.xp.content.Content)3 Test (org.junit.jupiter.api.Test)3 Attachment (com.enonic.xp.attachment.Attachment)2 CreateMediaParams (com.enonic.xp.content.CreateMediaParams)2 ContentType (com.enonic.xp.schema.content.ContentType)2 Attachments (com.enonic.xp.attachment.Attachments)1 ContentId (com.enonic.xp.content.ContentId)1 ByteSource (com.google.common.io.ByteSource)1 IOException (java.io.IOException)1