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());
}
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;
});
}
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());
}
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());
}
});
}
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());
});
}
Aggregations