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