Search in sources :

Example 21 with ContentPath

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();
}
Also used : BinaryAttachments(com.enonic.xp.node.BinaryAttachments) ByteSource(com.google.common.io.ByteSource) ContentPath(com.enonic.xp.content.ContentPath) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) ContentInheritType(com.enonic.xp.content.ContentInheritType)

Example 22 with ContentPath

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());
                }
            });
        }
    });
}
Also used : CONTENT_ROOT_PATH_ATTRIBUTE(com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE) ContentPath(com.enonic.xp.content.ContentPath) ArchiveConstants(com.enonic.xp.archive.ArchiveConstants) ContentInheritType(com.enonic.xp.content.ContentInheritType) Set(java.util.Set) Content(com.enonic.xp.content.Content) Collectors(java.util.stream.Collectors) ContentName(com.enonic.xp.content.ContentName) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) RenameContentParams(com.enonic.xp.content.RenameContentParams) MoveContentParams(com.enonic.xp.content.MoveContentParams) Preconditions(com.google.common.base.Preconditions) Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath)

Example 23 with ContentPath

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()));
    });
}
Also used : RestoreContentParams(com.enonic.xp.archive.RestoreContentParams) List(java.util.List) CONTENT_ROOT_PATH_ATTRIBUTE(com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE) ContentPath(com.enonic.xp.content.ContentPath) Set(java.util.Set) Content(com.enonic.xp.content.Content) Context(com.enonic.xp.context.Context) ContextBuilder(com.enonic.xp.context.ContextBuilder) Collectors(java.util.stream.Collectors) Context(com.enonic.xp.context.Context) Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath)

Example 24 with ContentPath

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());
}
Also used : Node(com.enonic.xp.node.Node) ContentIds(com.enonic.xp.content.ContentIds) ContentPath(com.enonic.xp.content.ContentPath) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult)

Example 25 with ContentPath

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();
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) PageTemplate(com.enonic.xp.page.PageTemplate) Content(com.enonic.xp.content.Content) PageTemplates(com.enonic.xp.page.PageTemplates) ValueFilter(com.enonic.xp.query.filter.ValueFilter) ContentPath(com.enonic.xp.content.ContentPath)

Aggregations

ContentPath (com.enonic.xp.content.ContentPath)56 Content (com.enonic.xp.content.Content)30 Test (org.junit.jupiter.api.Test)30 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)13 ContentId (com.enonic.xp.content.ContentId)11 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)10 WebException (com.enonic.xp.web.WebException)8 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)6 ArrayList (java.util.ArrayList)5 FindContentIdsByParentResult (com.enonic.xp.content.FindContentIdsByParentResult)4 Node (com.enonic.xp.node.Node)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 ContentInheritType (com.enonic.xp.content.ContentInheritType)3 Context (com.enonic.xp.context.Context)3 Site (com.enonic.xp.site.Site)3 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)2 CONTENT_ROOT_PATH_ATTRIBUTE (com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE)2 ContentVersionId (com.enonic.xp.content.ContentVersionId)2 List (java.util.List)2 Set (java.util.Set)2