Search in sources :

Example 26 with FindContentByParentResult

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

the class ContentServiceImplTest_findByParent method params_from.

@Test
public void params_from() throws Exception {
    final Content parentContent = createContent(ContentPath.ROOT);
    createContent(parentContent.getPath());
    createContent(parentContent.getPath());
    createContent(parentContent.getPath());
    createContent(parentContent.getPath());
    final ContentPath parentContentPath = parentContent.getPath();
    this.nodeService.refresh(RefreshMode.SEARCH);
    final FindContentByParentParams params = FindContentByParentParams.create().from(2).parentPath(parentContentPath).build();
    final FindContentByParentResult result = contentService.findByParent(params);
    assertNotNull(result);
    assertEquals(2, result.getHits());
    assertEquals(4, result.getTotalHits());
    assertEquals(2, result.getContents().getSize());
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath) Test(org.junit.jupiter.api.Test)

Example 27 with FindContentByParentResult

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

the class ContentServiceImplTest_findByParent method test_publish_expired_master.

@Test
public void test_publish_expired_master() throws Exception {
    authorizedMasterContext().callWith(() -> {
        final FindContentByParentResult result = createAndFindContent(ContentPublishInfo.create().from(Instant.now().minus(Duration.ofDays(1))).to(Instant.now().minus(Duration.ofDays(1))).build());
        assertEquals(0, result.getTotalHits());
        return null;
    });
}
Also used : FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Test(org.junit.jupiter.api.Test)

Example 28 with FindContentByParentResult

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

the class ParentContentSynchronizerTest method sortRestoredToManual.

@Test
public void sortRestoredToManual() throws Exception {
    final Content sourceParent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "parent"));
    final Content sourceChild1 = sourceContext.callWith(() -> createContent(sourceParent.getPath(), "name1"));
    final Content sourceChild2 = sourceContext.callWith(() -> createContent(sourceParent.getPath(), "name2"));
    final Content sourceChild3 = sourceContext.callWith(() -> createContent(sourceParent.getPath(), "name3"));
    syncCreated(sourceParent.getId());
    syncCreated(sourceChild1.getId());
    syncCreated(sourceChild2.getId());
    syncCreated(sourceChild3.getId());
    sourceContext.runWith(() -> {
        contentService.setChildOrder(SetContentChildOrderParams.create().contentId(sourceParent.getId()).childOrder(ChildOrder.manualOrder()).build());
        contentService.reorderChildren(ReorderChildContentsParams.create().contentId(sourceParent.getId()).add(ReorderChildParams.create().contentToMove(sourceChild1.getId()).contentToMoveBefore(sourceChild3.getId()).build()).build());
    });
    syncSorted(sourceParent.getId());
    syncManualOrderUpdated(sourceChild1.getId());
    syncManualOrderUpdated(sourceChild2.getId());
    syncManualOrderUpdated(sourceChild3.getId());
    targetContext.runWith(() -> {
        contentService.setChildOrder(SetContentChildOrderParams.create().contentId(sourceParent.getId()).childOrder(ChildOrder.manualOrder()).stopInherit(true).build());
        contentService.reorderChildren(ReorderChildContentsParams.create().contentId(sourceParent.getId()).add(ReorderChildParams.create().contentToMove(sourceChild1.getId()).contentToMoveBefore(sourceChild2.getId()).build()).build());
        syncContentService.resetInheritance(ResetContentInheritParams.create().contentId(sourceParent.getId()).inherit(List.of(ContentInheritType.SORT)).projectName(ProjectName.from(targetContext.getRepositoryId())).build());
    });
    syncSorted(sourceParent.getId());
    Thread.sleep(1000);
    final FindContentByParentResult sourceOrderedChildren = sourceContext.callWith(() -> contentService.findByParent(FindContentByParentParams.create().parentId(sourceParent.getId()).build()));
    final FindContentByParentResult targetOrderedChildren = targetContext.callWith(() -> contentService.findByParent(FindContentByParentParams.create().parentId(sourceParent.getId()).build()));
    assertArrayEquals(sourceOrderedChildren.getContents().getIds().getSet().toArray(), targetOrderedChildren.getContents().getIds().getSet().toArray());
}
Also used : FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 29 with FindContentByParentResult

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

the class ParentContentSynchronizer method doSyncWithChildren.

private void doSyncWithChildren(final Collection<ContentToSync> sourceContents) {
    final Queue<ContentToSync> queue = new ArrayDeque<>(sourceContents);
    final Map<NodePath, Context> targetContexts = !sourceContents.isEmpty() ? initContexts(ProjectName.from(sourceContents.stream().findAny().get().getTargetContext().getRepositoryId())) : Map.of();
    final List<ContentToSync> contentsToSync = sourceContents.stream().filter(sourceContent -> {
        final Content root = sourceContent.getSourceContext().callWith(() -> contentService.getByPath(ContentPath.ROOT));
        return !root.getId().equals(sourceContent.getSourceContent().getId());
    }).collect(Collectors.toList());
    if (!contentsToSync.isEmpty()) {
        this.doSync(contentsToSync);
    }
    while (queue.size() > 0) {
        final ContentToSync currentContentToSync = queue.poll();
        final FindContentByParentResult result = currentContentToSync.getSourceContext().callWith(() -> contentService.findByParent(FindContentByParentParams.create().parentId(currentContentToSync.getId()).recursive(false).childOrder(currentContentToSync.getSourceContent().getChildOrder()).size(-1).build()));
        if (result.getContents().isNotEmpty()) {
            final List<ContentToSync> childrenToSync = result.getContents().stream().map(content -> {
                final Context actualTargetContext = getActualContext(content.getId(), targetContexts.values());
                return ContentToSync.create().sourceContent(content).targetContent(actualTargetContext != null ? actualTargetContext.callWith(() -> contentService.getById(content.getId())) : null).sourceContext(currentContentToSync.getSourceContext()).targetContext(actualTargetContext != null ? actualTargetContext : currentContentToSync.getTargetContext()).build();
            }).collect(Collectors.toList());
            this.doSync(childrenToSync);
            for (final ContentToSync content : childrenToSync) {
                if (content.getSourceContent().hasChildren()) {
                    queue.offer(content);
                }
            }
        }
    }
    sourceContents.forEach(sourceContent -> {
        if (sourceContent.getTargetContent() != null) {
            cleanDeletedContents(sourceContent);
            return;
        }
        final Content root = sourceContent.getSourceContext().callWith(() -> contentService.getByPath(ContentPath.ROOT));
        if (root.getId().equals(sourceContent.getSourceContent().getId())) {
            cleanDeletedContents(ContentToSync.create(sourceContent).targetContent(sourceContent.getTargetContext().callWith(() -> contentService.getByPath(ContentPath.ROOT))).build());
        }
    });
}
Also used : Context(com.enonic.xp.context.Context) ContentService(com.enonic.xp.content.ContentService) ContentConstants(com.enonic.xp.content.ContentConstants) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) CONTENT_ROOT_PATH_ATTRIBUTE(com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE) Function(java.util.function.Function) LinkedHashMap(java.util.LinkedHashMap) ContentId(com.enonic.xp.content.ContentId) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) ContextAccessor(com.enonic.xp.context.ContextAccessor) MediaInfoService(com.enonic.xp.media.MediaInfoService) Map(java.util.Map) ProjectName(com.enonic.xp.project.ProjectName) Activate(org.osgi.service.component.annotations.Activate) ContextBuilder(com.enonic.xp.context.ContextBuilder) User(com.enonic.xp.security.User) ContentPath(com.enonic.xp.content.ContentPath) ArchiveConstants(com.enonic.xp.archive.ArchiveConstants) Collection(java.util.Collection) NodePath(com.enonic.xp.node.NodePath) Set(java.util.Set) Content(com.enonic.xp.content.Content) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Collectors(java.util.stream.Collectors) List(java.util.List) PrincipalKey(com.enonic.xp.security.PrincipalKey) BRANCH_DRAFT(com.enonic.xp.content.ContentConstants.BRANCH_DRAFT) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) Reference(org.osgi.service.component.annotations.Reference) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) ArrayDeque(java.util.ArrayDeque) NodePath(com.enonic.xp.node.NodePath)

Example 30 with FindContentByParentResult

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

the class ProjectContentEventListenerTest method testSorted.

@Test
public void testSorted() throws InterruptedException {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "content"));
    final Content sourceChild1 = sourceContext.callWith(() -> createContent(sourceContent.getPath(), "child1"));
    final Content sourceChild2 = sourceContext.callWith(() -> createContent(sourceContent.getPath(), "child2"));
    final Content sourceChild3 = sourceContext.callWith(() -> createContent(sourceContent.getPath(), "child3"));
    handleEvents();
    sourceContext.runWith(() -> contentService.setChildOrder(SetContentChildOrderParams.create().contentId(sourceContent.getId()).childOrder(ChildOrder.from("_name DESC")).build()));
    handleEvents();
    targetContext.runWith(() -> {
        final FindContentByParentResult result = contentService.findByParent(FindContentByParentParams.create().parentId(sourceContent.getId()).build());
        final Iterator<Content> iterator = result.getContents().iterator();
        assertEquals(sourceChild3.getId(), iterator.next().getId());
        assertEquals(sourceChild2.getId(), iterator.next().getId());
        assertEquals(sourceChild1.getId(), iterator.next().getId());
    });
}
Also used : FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Aggregations

FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)33 Test (org.junit.jupiter.api.Test)26 Content (com.enonic.xp.content.Content)18 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)18 ContentPath (com.enonic.xp.content.ContentPath)7 Contents (com.enonic.xp.content.Contents)4 ArrayDeque (java.util.ArrayDeque)2 ArchiveConstants (com.enonic.xp.archive.ArchiveConstants)1 ContentConstants (com.enonic.xp.content.ContentConstants)1 BRANCH_DRAFT (com.enonic.xp.content.ContentConstants.BRANCH_DRAFT)1 CONTENT_ROOT_PATH_ATTRIBUTE (com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE)1 ContentId (com.enonic.xp.content.ContentId)1 ContentService (com.enonic.xp.content.ContentService)1 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 MediaInfoService (com.enonic.xp.media.MediaInfoService)1 NodePath (com.enonic.xp.node.NodePath)1 PageTemplate (com.enonic.xp.page.PageTemplate)1 PageTemplates (com.enonic.xp.page.PageTemplates)1