use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class CreatedEventSyncCommand method createImportParams.
private ImportContentParams createImportParams(final ContentToSync content, final ContentPath parentPath, final InsertManualStrategy insertManualStrategy) {
final BinaryAttachments.Builder builder = BinaryAttachments.create();
content.getSourceContent().getAttachments().forEach(attachment -> {
final ByteSource binary = content.getSourceContext().callWith(() -> contentService.getBinary(content.getId(), attachment.getBinaryReference()));
builder.add(new BinaryAttachment(attachment.getBinaryReference(), binary));
});
final ContentPath targetPath = buildNewPath(parentPath, content.getSourceContent().getName());
final EnumSet<ContentInheritType> inheritTypes = content.getSourceContent().getName().toString().equals(targetPath.getName()) ? EnumSet.allOf(ContentInheritType.class) : EnumSet.complementOf(EnumSet.of(ContentInheritType.NAME));
return ImportContentParams.create().importContent(content.getSourceContent()).targetPath(targetPath).binaryAttachments(builder.build()).inherit(inheritTypes).originProject(ProjectName.from(content.getSourceContext().getRepositoryId())).importPermissionsOnCreate(false).dryRun(false).insertManualStrategy(insertManualStrategy).build();
}
use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class MovedEventSyncCommand method doMove.
private void doMove(final List<ContentToSync> contents) {
final Set<ContentPath> paths = contents.stream().map(content -> content.getSourceContent().getPath()).collect(Collectors.toSet());
final List<ContentToSync> rootsToSync = contents.stream().filter(content -> !paths.contains(content.getSourceContent().getParentPath())).collect(Collectors.toList());
rootsToSync.forEach(content -> {
if (isToSync(content.getTargetContent())) {
content.getTargetContext().runWith(() -> {
final Content sourceParent = content.getSourceContext().callWith(() -> contentService.getByPath(content.getSourceContent().getParentPath()));
final Content sourceRoot = content.getSourceContext().callWith(() -> contentService.getByPath(ContentPath.ROOT));
final ContentPath targetParentPath = contentService.contentExists(sourceParent.getId()) ? contentService.getById(sourceParent.getId()).getPath() : sourceRoot.getId().equals(sourceParent.getId()) ? ContentPath.ROOT : null;
if (targetParentPath == null) {
return;
}
if (!targetParentPath.equals(content.getTargetContent().getParentPath())) {
final ContentPath newPath = buildNewPath(targetParentPath, content.getTargetContent().getName());
if (!Objects.equals(newPath.getName(), content.getTargetContent().getPath().getName())) {
contentService.rename(RenameContentParams.create().contentId(content.getTargetContent().getId()).newName(ContentName.from(newPath.getName())).build());
}
contentService.move(MoveContentParams.create().contentId(content.getTargetContent().getId()).parentContentPath(targetParentPath).stopInherit(false).build());
}
});
}
});
}
use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class MovedEventSyncRestorer method execute.
protected void execute() {
final List<ContentToSync> contentToSync = contents.stream().filter(content -> isToSyncContent(content.getTargetContent())).collect(Collectors.toList());
getRoots(contentToSync).forEach(content -> {
final Content sourceParent = content.getSourceContext().callWith(() -> contentService.getByPath(content.getSourceContent().getParentPath()));
final Context targetContextToRestore = ContextBuilder.from(content.getTargetContext()).attribute(CONTENT_ROOT_PATH_ATTRIBUTE, content.getSourceContext().getAttribute(CONTENT_ROOT_PATH_ATTRIBUTE)).build();
final ContentPath targetParentPath = targetContextToRestore.callWith(() -> contentService.contentExists(sourceParent.getId()) ? contentService.getById(sourceParent.getId()).getPath() : ContentPath.ROOT);
content.getTargetContext().runWith(() -> contentService.restore(RestoreContentParams.create().contentId(content.getTargetContent().getId()).path(targetParentPath).stopInherit(false).build()));
});
}
use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class PublishContentCommand method doDeleteNodes.
private void doDeleteNodes(final NodeIds nodeIdsToDelete) {
final ContentIds.Builder deleted = ContentIds.create();
final ContentIds.Builder unpublished = ContentIds.create();
totalToDelete(nodeIdsToDelete.getSize());
nodeIdsToDelete.forEach((id) -> {
if (nodeService.nodeExists(id)) {
final Node nodeToDelete = nodeService.getById(id);
final ContentPath contentPathToDelete = ContentNodeHelper.translateNodePathToContentPath(nodeToDelete.path());
final DeleteContentsResult deleteResult = DeleteContentCommand.create().contentTypeService(contentTypeService).nodeService(nodeService).translator(translator).eventPublisher(eventPublisher).params(DeleteContentParams.create().deleteOnline(true).contentPath(contentPathToDelete).build()).build().execute();
deleted.addAll(deleteResult.getDeletedContents());
unpublished.addAll(deleteResult.getUnpublishedContents());
if (nodeIdsToDelete.getSize() == 1) {
this.resultBuilder.setDeletedPath(contentPathToDelete);
}
}
nodesDeleted(1);
});
nodesPushed(nodeIdsToDelete.getSize());
this.resultBuilder.setDeleted(deleted.build());
this.resultBuilder.setUnpublishedContents(unpublished.build());
}
use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class GetPageTemplateBySiteCommand method execute.
public PageTemplates execute() {
final PageTemplates.Builder pageTemplatesBuilder = PageTemplates.create();
if (sitePath == null) {
final Content site = contentService.getById(siteId);
sitePath = site.getPath();
}
final ContentPath pageTemplatesFolderPath = ContentPath.from(sitePath, ContentServiceImpl.TEMPLATES_FOLDER_NAME);
final FindContentByParentParams.Builder findContentByParentParams = FindContentByParentParams.create().parentPath(pageTemplatesFolderPath);
if (supportedContentTypes != null) {
final ValueFilter.Builder supportsContentTypeFilter = ValueFilter.create().fieldName("data.supports");
supportedContentTypes.forEach(supportedContentType -> {
supportsContentTypeFilter.addValue(ValueFactory.newString(supportedContentType.toString()));
});
findContentByParentParams.queryFilter(supportsContentTypeFilter.build());
}
if (size != null) {
findContentByParentParams.size(size);
}
final FindContentByParentResult result = contentService.findByParent(findContentByParentParams.build());
for (final Content content : result.getContents()) {
if (content instanceof PageTemplate) {
pageTemplatesBuilder.add((PageTemplate) content);
}
}
return pageTemplatesBuilder.build();
}
Aggregations