Search in sources :

Example 1 with SetContentChildOrderParams

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

the class SortedEventSyncCommand method doSync.

private void doSync(final ContentToSync content) {
    content.getTargetContext().runWith(() -> {
        if (isToSyncSort(content.getTargetContent())) {
            if (needToSort(content.getSourceContent(), content.getTargetContent())) {
                final SetContentChildOrderParams sortParams = SetContentChildOrderParams.create().childOrder(content.getSourceContent().getChildOrder()).contentId(content.getSourceContent().getId()).stopInherit(false).build();
                contentService.setChildOrder(sortParams);
            }
            if (needToReorderChildren(content.getSourceContent())) {
                final List<ContentToSync> childrenToSync = contentService.findByParent(FindContentByParentParams.create().parentId(content.getTargetContent().getId()).size(-1).build()).getContents().stream().map(currContent -> {
                    final Content sourceContent = content.getSourceContext().callWith(() -> contentService.contentExists(currContent.getId()) ? contentService.getById(currContent.getId()) : null);
                    return sourceContent != null ? ContentToSync.create().sourceContext(content.getSourceContext()).targetContext(content.getTargetContext()).sourceContent(sourceContent).targetContent(currContent).build() : null;
                }).filter(Objects::nonNull).collect(Collectors.toList());
                if (!childrenToSync.isEmpty()) {
                    ManualOrderUpdatedEventSyncCommand.create().contentService(contentService).params(ContentEventSyncCommandParams.create().addContents(childrenToSync).build()).build().sync();
                }
            }
        }
    });
}
Also used : Content(com.enonic.xp.content.Content) SetContentChildOrderParams(com.enonic.xp.content.SetContentChildOrderParams)

Aggregations

Content (com.enonic.xp.content.Content)1 SetContentChildOrderParams (com.enonic.xp.content.SetContentChildOrderParams)1