Search in sources :

Example 26 with UpdateContentParams

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

the class ProjectContentEventListenerTest method testUpdated.

@Test
public void testUpdated() throws InterruptedException {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "name"));
    final Content updatedContent = sourceContext.callWith(() -> {
        final Content updated = contentService.update(new UpdateContentParams().contentId(sourceContent.getId()).editor((edit -> {
            edit.data = new PropertyTree();
            edit.displayName = "newDisplayName";
            edit.extraDatas = ExtraDatas.create().add(createExtraData()).build();
            edit.owner = PrincipalKey.from("user:system:newOwner");
            edit.language = Locale.forLanguageTag("no");
            edit.page = createPage();
        })));
        return updated;
    });
    handleEvents();
    final Content targetContent = targetContext.callWith(() -> contentService.getById(sourceContent.getId()));
    compareSynched(updatedContent, targetContent);
    assertEquals(4, targetContent.getInherit().size());
}
Also used : 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 27 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) 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) 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) 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 28 with UpdateContentParams

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

the class ProjectContentEventListenerTest method testArchivedNotInherited.

@Test
public void testArchivedNotInherited() throws InterruptedException {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "content"));
    handleEvents();
    targetContext.runWith(() -> contentService.update(new UpdateContentParams().contentId(sourceContent.getId()).editor(edit -> edit.data = new PropertyTree())));
    handleEvents();
    sourceContext.runWith(() -> contentService.archive(ArchiveContentParams.create().contentId(sourceContent.getId()).build()));
    handleEvents();
    final Content targetContent = targetContext.callWith(() -> contentService.getById(sourceContent.getId()));
    assertEquals("/content", targetContent.getPath().toString());
}
Also used : 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 29 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 30 with UpdateContentParams

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

the class RemoveAttachmentHandler method execute.

public void execute() {
    UpdateContentParams updateContent = new UpdateContentParams();
    if (!this.key.startsWith("/")) {
        updateContent.contentId(ContentId.from(this.key));
    } else {
        final Content contentByPath = this.contentService.getByPath(ContentPath.from(key));
        updateContent.contentId(contentByPath.getId());
    }
    BinaryReferences binaryRefs = BinaryReferences.from(Arrays.stream(this.names).map(BinaryReference::from).collect(toList()));
    updateContent.removeAttachments(binaryRefs);
    contentService.update(updateContent);
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) BinaryReferences(com.enonic.xp.util.BinaryReferences) BinaryReference(com.enonic.xp.util.BinaryReference)

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