Search in sources :

Example 11 with UpdateContentParams

use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.

the class ParentContentSynchronizerTest method updateThumbnailCreated.

@Test
public void updateThumbnailCreated() throws Exception {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "content"));
    final Content targetContent = syncCreated(sourceContent.getId());
    sourceContext.runWith(() -> {
        try {
            final UpdateContentParams updateContentParams = new UpdateContentParams();
            updateContentParams.contentId(targetContent.getId()).editor(edit -> {
                edit.displayName = "new display name";
            }).createAttachments(CreateAttachments.from(CreateAttachment.create().byteSource(loadImage("darth-small.jpg")).name(AttachmentNames.THUMBNAIL).mimeType("image/jpeg").build()));
            this.contentService.update(updateContentParams);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    final Content targetContentUpdated = syncUpdated(sourceContent.getId());
    assertNotNull(targetContentUpdated.getThumbnail());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) ChildOrder(com.enonic.xp.index.ChildOrder) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) BinaryReferences(com.enonic.xp.util.BinaryReferences) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ContentName(com.enonic.xp.content.ContentName) DeleteContentParams(com.enonic.xp.content.DeleteContentParams) ContentSyncEventType(com.enonic.xp.core.impl.content.ContentSyncEventType) ParentContentSynchronizer(com.enonic.xp.core.impl.content.ParentContentSynchronizer) ContentId(com.enonic.xp.content.ContentId) ReorderChildParams(com.enonic.xp.content.ReorderChildParams) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ResetContentInheritParams(com.enonic.xp.content.ResetContentInheritParams) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ProjectName(com.enonic.xp.project.ProjectName) ContentEventsSyncParams(com.enonic.xp.core.impl.content.ContentEventsSyncParams) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) ContentPropertyNames(com.enonic.xp.content.ContentPropertyNames) UpdateMediaParams(com.enonic.xp.content.UpdateMediaParams) ContentPath(com.enonic.xp.content.ContentPath) ContentSyncParams(com.enonic.xp.core.impl.content.ContentSyncParams) ContentInheritType(com.enonic.xp.content.ContentInheritType) Content(com.enonic.xp.content.Content) IOException(java.io.IOException) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Test(org.junit.jupiter.api.Test) SyncContentServiceImpl(com.enonic.xp.core.impl.content.SyncContentServiceImpl) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) AttachmentNames(com.enonic.xp.attachment.AttachmentNames) List(java.util.List) RenameContentParams(com.enonic.xp.content.RenameContentParams) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) MoveContentParams(com.enonic.xp.content.MoveContentParams) ReorderChildContentsParams(com.enonic.xp.content.ReorderChildContentsParams) SetContentChildOrderParams(com.enonic.xp.content.SetContentChildOrderParams) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 12 with UpdateContentParams

use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.

the class ParentContentSynchronizerTest method updateThumbnailUpdated.

@Test
public void updateThumbnailUpdated() throws Exception {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "content"));
    final Content targetContent = syncCreated(sourceContent.getId());
    sourceContext.runWith(() -> {
        try {
            final UpdateContentParams updateContentParams = new UpdateContentParams();
            updateContentParams.contentId(targetContent.getId()).editor(edit -> {
                edit.displayName = "new display name";
            }).createAttachments(CreateAttachments.from(CreateAttachment.create().byteSource(loadImage("darth-small.jpg")).name(AttachmentNames.THUMBNAIL).mimeType("image/jpeg").build()));
            this.contentService.update(updateContentParams);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    final Content thumbnailCreated = syncUpdated(sourceContent.getId());
    sourceContext.runWith(() -> {
        try {
            final UpdateContentParams updateContentParams = new UpdateContentParams();
            updateContentParams.contentId(targetContent.getId()).editor(edit -> {
                edit.displayName = "new display name";
            }).createAttachments(CreateAttachments.from(CreateAttachment.create().byteSource(loadImage("cat-small.jpg")).name(AttachmentNames.THUMBNAIL).mimeType("image/jpeg").build()));
            this.contentService.update(updateContentParams);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    final Content thumbnailUpdated = syncUpdated(sourceContent.getId());
    assertNotEquals(thumbnailCreated.getThumbnail().getSize(), thumbnailUpdated.getThumbnail().getSize());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) ChildOrder(com.enonic.xp.index.ChildOrder) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) BinaryReferences(com.enonic.xp.util.BinaryReferences) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ContentName(com.enonic.xp.content.ContentName) DeleteContentParams(com.enonic.xp.content.DeleteContentParams) ContentSyncEventType(com.enonic.xp.core.impl.content.ContentSyncEventType) ParentContentSynchronizer(com.enonic.xp.core.impl.content.ParentContentSynchronizer) ContentId(com.enonic.xp.content.ContentId) ReorderChildParams(com.enonic.xp.content.ReorderChildParams) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ResetContentInheritParams(com.enonic.xp.content.ResetContentInheritParams) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ProjectName(com.enonic.xp.project.ProjectName) ContentEventsSyncParams(com.enonic.xp.core.impl.content.ContentEventsSyncParams) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) ContentPropertyNames(com.enonic.xp.content.ContentPropertyNames) UpdateMediaParams(com.enonic.xp.content.UpdateMediaParams) ContentPath(com.enonic.xp.content.ContentPath) ContentSyncParams(com.enonic.xp.core.impl.content.ContentSyncParams) ContentInheritType(com.enonic.xp.content.ContentInheritType) Content(com.enonic.xp.content.Content) IOException(java.io.IOException) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Test(org.junit.jupiter.api.Test) SyncContentServiceImpl(com.enonic.xp.core.impl.content.SyncContentServiceImpl) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) AttachmentNames(com.enonic.xp.attachment.AttachmentNames) List(java.util.List) RenameContentParams(com.enonic.xp.content.RenameContentParams) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) MoveContentParams(com.enonic.xp.content.MoveContentParams) ReorderChildContentsParams(com.enonic.xp.content.ReorderChildContentsParams) SetContentChildOrderParams(com.enonic.xp.content.SetContentChildOrderParams) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 13 with UpdateContentParams

use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.

the class ContentServiceImplTest_update method update_content_modified_time_updated.

@Test
public void update_content_modified_time_updated() throws Exception {
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final UpdateContentParams updateContentParams = new UpdateContentParams();
    updateContentParams.contentId(content.getId()).editor(edit -> {
        edit.displayName = "new display name";
    });
    this.contentService.update(updateContentParams);
    final Content updatedContent = this.contentService.getById(content.getId());
    assertEquals("new display name", updatedContent.getDisplayName());
    assertNotNull(updatedContent.getCreator());
    assertNotNull(updatedContent.getCreatedTime());
    assertNotNull(updatedContent.getModifier());
    assertNotNull(updatedContent.getModifiedTime());
    assertTrue(updatedContent.getModifiedTime().isAfter(content.getModifiedTime()));
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 14 with UpdateContentParams

use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.

the class ContentServiceImplTest_update method update_publish_info.

@Test
public void update_publish_info() throws Exception {
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final UpdateContentParams updateContentParams = new UpdateContentParams();
    updateContentParams.contentId(content.getId()).editor(edit -> {
        edit.publishInfo = ContentPublishInfo.create().from(Instant.parse("2016-11-03T10:43:44Z")).to(Instant.parse("2016-11-23T10:43:44Z")).build();
    });
    this.contentService.update(updateContentParams);
    final Content storedContent = this.contentService.getById(content.getId());
    assertNotNull(storedContent.getPublishInfo());
    assertNotNull(storedContent.getPublishInfo().getFrom());
    assertNotNull(storedContent.getPublishInfo().getTo());
    assertEquals(storedContent.getPublishInfo().getFrom(), Instant.parse("2016-11-03T10:43:44Z"));
    assertEquals(storedContent.getPublishInfo().getTo(), Instant.parse("2016-11-23T10:43:44Z"));
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 15 with UpdateContentParams

use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.

the class ModifyContentHandler method doExecute.

@Override
protected Object doExecute() {
    final Content existingContent = getExistingContent(this.key);
    if (existingContent == null) {
        return null;
    }
    final UpdateContentParams params = new UpdateContentParams();
    params.contentId(existingContent.getId());
    params.editor(newContentEditor(existingContent));
    params.requireValid(this.requireValid);
    final Content result = this.contentService.update(params);
    return result != null ? new ContentMapper(result) : null;
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) ContentMapper(com.enonic.xp.lib.content.mapper.ContentMapper)

Aggregations

UpdateContentParams (com.enonic.xp.content.UpdateContentParams)49 Content (com.enonic.xp.content.Content)43 Test (org.junit.jupiter.api.Test)35 PropertyTree (com.enonic.xp.data.PropertyTree)27 CreateContentParams (com.enonic.xp.content.CreateContentParams)14 ContentPath (com.enonic.xp.content.ContentPath)9 EditableContent (com.enonic.xp.content.EditableContent)9 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)9 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)9 ContentId (com.enonic.xp.content.ContentId)8 ContentInheritType (com.enonic.xp.content.ContentInheritType)7 WorkflowInfo (com.enonic.xp.content.WorkflowInfo)7 ByteSource (com.google.common.io.ByteSource)7 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)7 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)7 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)6 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)6 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)6 ResetContentInheritParams (com.enonic.xp.content.ResetContentInheritParams)6 SetContentChildOrderParams (com.enonic.xp.content.SetContentChildOrderParams)6