Search in sources :

Example 31 with UpdateContentParams

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

the class CreateFragmentCommand method execute.

public Content execute() {
    final String displayName = generateDisplayName(params.getComponent());
    final String name = generateUniqueContentName(params.getParent(), "fragment-" + displayName);
    final CreateContentParams createContent = CreateContentParams.create().parent(params.getParent()).displayName(displayName).name(name).type(ContentTypeName.fragment()).contentData(new PropertyTree()).workflowInfo(params.getWorkflowInfo()).build();
    final Content content = contentService.create(createContent);
    final Page page = Page.create().config(this.params.getConfig()).fragment(this.params.getComponent()).build();
    final UpdateContentParams params = new UpdateContentParams().contentId(content.getId()).modifier(getCurrentUser().getKey()).editor(edit -> edit.page = page);
    return this.contentService.update(params);
}
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) Page(com.enonic.xp.page.Page)

Example 32 with UpdateContentParams

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

the class ProjectContentEventListenerTest method testUpdatedFromReadyToInProgress.

@Test
public void testUpdatedFromReadyToInProgress() throws InterruptedException {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "name"));
    sourceContext.callWith(() -> {
        contentService.update(new UpdateContentParams().contentId(sourceContent.getId()).editor((edit -> edit.workflowInfo = WorkflowInfo.create().state(WorkflowState.READY).build())));
        handleEvents();
        final Content sourceContentReady = contentService.update(new UpdateContentParams().contentId(sourceContent.getId()).editor((edit -> edit.workflowInfo = WorkflowInfo.create().state(WorkflowState.IN_PROGRESS).build())));
        handleEvents();
        return sourceContentReady;
    });
    final Content targetContent = targetContext.callWith(() -> contentService.getById(sourceContent.getId()));
    assertEquals(WorkflowState.READY, targetContent.getWorkflowInfo().getState());
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 33 with UpdateContentParams

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

the class ProjectContentEventListenerTest method testUpdatedLocally.

@Test
public void testUpdatedLocally() throws InterruptedException {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "name"));
    handleEvents();
    final Content updatedInChild = targetContext.callWith(() -> contentService.update(new UpdateContentParams().contentId(sourceContent.getId()).editor((edit -> edit.data = new PropertyTree()))));
    assertEquals(2, updatedInChild.getInherit().size());
    assertFalse(updatedInChild.getInherit().contains(ContentInheritType.CONTENT));
    assertFalse(updatedInChild.getInherit().contains(ContentInheritType.NAME));
    final Content updatedInParent = sourceContext.callWith(() -> contentService.update(new UpdateContentParams().contentId(sourceContent.getId()).editor((edit -> edit.displayName = "new source display name"))));
    handleEvents();
    assertNotEquals(updatedInParent.getDisplayName(), targetContext.callWith(() -> contentService.getById(updatedInChild.getId()).getDisplayName()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) DuplicateContentParams(com.enonic.xp.content.DuplicateContentParams) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Page(com.enonic.xp.page.Page) ContentName(com.enonic.xp.content.ContentName) ParentContentSynchronizer(com.enonic.xp.core.impl.content.ParentContentSynchronizer) Region(com.enonic.xp.region.Region) ContentId(com.enonic.xp.content.ContentId) MEDIA_INFO_BYTE_SIZE(com.enonic.xp.media.MediaInfo.MEDIA_INFO_BYTE_SIZE) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) Locale(java.util.Locale) PageRegions(com.enonic.xp.page.PageRegions) ContextBuilder(com.enonic.xp.context.ContextBuilder) XDataName(com.enonic.xp.schema.xdata.XDataName) IMAGE_INFO_PIXEL_SIZE(com.enonic.xp.media.MediaInfo.IMAGE_INFO_PIXEL_SIZE) ImmutableMap(com.google.common.collect.ImmutableMap) PageTemplateKey(com.enonic.xp.page.PageTemplateKey) Set(java.util.Set) IMAGE_INFO_IMAGE_WIDTH(com.enonic.xp.media.MediaInfo.IMAGE_INFO_IMAGE_WIDTH) ExtraDatas(com.enonic.xp.content.ExtraDatas) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) Test(org.junit.jupiter.api.Test) List(java.util.List) PushContentParams(com.enonic.xp.content.PushContentParams) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) PartComponent(com.enonic.xp.region.PartComponent) ArchiveContentParams(com.enonic.xp.archive.ArchiveContentParams) IMAGE_INFO_IMAGE_HEIGHT(com.enonic.xp.media.MediaInfo.IMAGE_INFO_IMAGE_HEIGHT) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) ProjectContentEventListener(com.enonic.xp.core.impl.content.ProjectContentEventListener) ChildOrder(com.enonic.xp.index.ChildOrder) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContentConstants(com.enonic.xp.content.ContentConstants) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) WorkflowState(com.enonic.xp.content.WorkflowState) PartDescriptor(com.enonic.xp.region.PartDescriptor) Sets(org.assertj.core.util.Sets) DeleteContentParams(com.enonic.xp.content.DeleteContentParams) RestoreContentParams(com.enonic.xp.archive.RestoreContentParams) ReorderChildParams(com.enonic.xp.content.ReorderChildParams) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtraData(com.enonic.xp.content.ExtraData) Event(com.enonic.xp.event.Event) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) Iterator(java.util.Iterator) ContentPath(com.enonic.xp.content.ContentPath) ContentInheritType(com.enonic.xp.content.ContentInheritType) Content(com.enonic.xp.content.Content) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Form(com.enonic.xp.form.Form) Mockito(org.mockito.Mockito) PrincipalKey(com.enonic.xp.security.PrincipalKey) ContentIds(com.enonic.xp.content.ContentIds) DescriptorKey(com.enonic.xp.page.DescriptorKey) RenameContentParams(com.enonic.xp.content.RenameContentParams) 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) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 34 with UpdateContentParams

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

the class SyncContentServiceImplTest method testWorkflowInfo.

@Test
public void testWorkflowInfo() throws Exception {
    final Content source = sourceContext.callWith(() -> createContent(ContentPath.ROOT));
    syncCreated(source.getId());
    targetContext.runWith(() -> {
        contentService.update(new UpdateContentParams().contentId(source.getId()).editor(edit -> {
            edit.workflowInfo = WorkflowInfo.ready();
            edit.data = new PropertyTree();
        }));
    });
    syncContentService.resetInheritance(ResetContentInheritParams.create().contentId(source.getId()).inherit(EnumSet.of(ContentInheritType.CONTENT)).projectName(targetProject.getName()).build());
    targetContext.runWith(() -> {
        final Content changed = contentService.getById(source.getId());
        assertTrue(changed.getInherit().contains(ContentInheritType.CONTENT));
        assertTrue(changed.getData().hasProperty("stringField"));
    });
}
Also used : ChildOrder(com.enonic.xp.index.ChildOrder) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) ContentPath(com.enonic.xp.content.ContentPath) ProjectSyncParams(com.enonic.xp.content.ProjectSyncParams) ContentInheritType(com.enonic.xp.content.ContentInheritType) Content(com.enonic.xp.content.Content) DeleteContentParams(com.enonic.xp.content.DeleteContentParams) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) ContentSyncEventType(com.enonic.xp.core.impl.content.ContentSyncEventType) Test(org.junit.jupiter.api.Test) ParentContentSynchronizer(com.enonic.xp.core.impl.content.ParentContentSynchronizer) SyncContentServiceImpl(com.enonic.xp.core.impl.content.SyncContentServiceImpl) ContentId(com.enonic.xp.content.ContentId) ResetContentInheritParams(com.enonic.xp.content.ResetContentInheritParams) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ProjectName(com.enonic.xp.project.ProjectName) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SetContentChildOrderParams(com.enonic.xp.content.SetContentChildOrderParams) ContentEventsSyncParams(com.enonic.xp.core.impl.content.ContentEventsSyncParams) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EnumSet(java.util.EnumSet) PropertyTree(com.enonic.xp.data.PropertyTree) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 35 with UpdateContentParams

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

the class ParentContentSynchronizerTest method updateBinaryChanged.

@Test
public void updateBinaryChanged() throws Exception {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "content1"));
    syncCreated(sourceContent.getId());
    sourceContext.runWith(() -> {
        contentService.update(new UpdateContentParams().contentId(sourceContent.getId()).createAttachments(CreateAttachments.create().add(CreateAttachment.create().name(AttachmentNames.THUMBNAIL).byteSource(ByteSource.wrap("this is image".getBytes())).mimeType("image/png").text("This is the image").build()).build()).editor(edit -> {
        }));
    });
    final Content targetContentWithThumbnail = syncUpdated(sourceContent.getId());
    assertTrue(targetContentWithThumbnail.hasThumbnail());
    sourceContext.runWith(() -> {
        contentService.update(new UpdateContentParams().contentId(sourceContent.getId()).removeAttachments(BinaryReferences.from(AttachmentNames.THUMBNAIL)).editor(edit -> {
        }));
    });
    final Content targetContentWithoutThumbnail = syncUpdated(sourceContent.getId());
    assertFalse(targetContentWithoutThumbnail.hasThumbnail());
}
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) Test(org.junit.jupiter.api.Test)

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