Search in sources :

Example 31 with Node

use of com.enonic.xp.node.Node 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 32 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class RestoreContentCommand method doExecute.

private RestoreContentsResult doExecute() {
    final Node nodeToRestore = nodeService.getById(NodeId.from(params.getContentId()));
    validateLocation(nodeToRestore);
    final boolean isRootContent = nodeToRestore.path().asAbsolute().elementCount() == 2;
    final NodePath parentPathToRestore = getParentPathToRestore(nodeToRestore, isRootContent);
    final String originalSourceName = getOriginalSourceName(nodeToRestore, isRootContent);
    final RestoreContentsResult.Builder result = RestoreContentsResult.create();
    rename(nodeToRestore, parentPathToRestore, originalSourceName);
    final MoveNodeParams.Builder builder = MoveNodeParams.create().nodeId(nodeToRestore.id()).parentNodePath(parentPathToRestore).moveListener(this);
    stopInherit(builder);
    final Node movedNode = move(builder.build(), originalSourceName);
    updateProperties(movedNode, isRootContent);
    commitNode(movedNode.id(), ContentConstants.RESTORE_COMMIT_PREFIX);
    result.addRestored(ContentId.from(movedNode.id().toString())).parentPath(ContentNodeHelper.translateNodePathToContentPath(parentPathToRestore));
    return result.build();
}
Also used : MoveNodeParams(com.enonic.xp.node.MoveNodeParams) RestoreContentsResult(com.enonic.xp.archive.RestoreContentsResult) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 33 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class RestoreContentCommand method updateProperties.

private void updateProperties(final Node node, final boolean isRootContent) {
    final FindNodesByParentResult childrenToRestore = nodeService.findByParent(FindNodesByParentParams.create().size(-1).recursive(true).parentId(node.id()).build());
    childrenToRestore.getNodeIds().forEach(id -> nodeService.update(UpdateNodeParams.create().id(id).editor(toBeEdited -> {
        toBeEdited.data.removeProperties(ARCHIVED_TIME);
        toBeEdited.data.removeProperties(ARCHIVED_BY);
    }).build()));
    if (isRootContent) {
        nodeService.update(UpdateNodeParams.create().id(node.id()).editor(toBeEdited -> {
            toBeEdited.data.removeProperties(ORIGINAL_PARENT_PATH);
            toBeEdited.data.removeProperties(ORIGINAL_NAME);
            toBeEdited.data.removeProperties(ARCHIVED_TIME);
            toBeEdited.data.removeProperties(ARCHIVED_BY);
        }).build());
    }
}
Also used : RefreshMode(com.enonic.xp.node.RefreshMode) MoveNodeException(com.enonic.xp.node.MoveNodeException) ContentConstants(com.enonic.xp.content.ContentConstants) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) RestoreContentsResult(com.enonic.xp.archive.RestoreContentsResult) Node(com.enonic.xp.node.Node) ORIGINAL_PARENT_PATH(com.enonic.xp.content.ContentPropertyNames.ORIGINAL_PARENT_PATH) ORIGINAL_NAME(com.enonic.xp.content.ContentPropertyNames.ORIGINAL_NAME) RestoreContentParams(com.enonic.xp.archive.RestoreContentParams) ContentId(com.enonic.xp.content.ContentId) RestoreContentException(com.enonic.xp.archive.RestoreContentException) ContextAccessor(com.enonic.xp.context.ContextAccessor) EnumSet(java.util.EnumSet) Property(com.enonic.xp.data.Property) ContentAccessException(com.enonic.xp.content.ContentAccessException) ArchiveConstants(com.enonic.xp.archive.ArchiveConstants) ContentInheritType(com.enonic.xp.content.ContentInheritType) NodePath(com.enonic.xp.node.NodePath) ARCHIVED_BY(com.enonic.xp.content.ContentPropertyNames.ARCHIVED_BY) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) NodeId(com.enonic.xp.node.NodeId) MoveNodeListener(com.enonic.xp.node.MoveNodeListener) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodeName(com.enonic.xp.node.NodeName) RestoreContentListener(com.enonic.xp.archive.RestoreContentListener) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) NodeAccessException(com.enonic.xp.node.NodeAccessException) Preconditions(com.google.common.base.Preconditions) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) ARCHIVED_TIME(com.enonic.xp.content.ContentPropertyNames.ARCHIVED_TIME) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Example 34 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class UnpublishContentCommand method removePendingDeleteFromDraft.

private void removePendingDeleteFromDraft(final UnpublishContentsResult result) {
    final Branch currentBranch = ContextAccessor.current().getBranch();
    if (!currentBranch.equals(ContentConstants.BRANCH_DRAFT)) {
        final Context draftContext = ContextBuilder.from(ContextAccessor.current()).branch(ContentConstants.BRANCH_DRAFT).build();
        draftContext.callWith(() -> {
            final Nodes draftNodes = this.nodeService.getByIds(NodeIds.from(result.getUnpublishedContents().asStrings()));
            for (final Node draftNode : draftNodes) {
                if (draftNode.getNodeState().value().equalsIgnoreCase(ContentState.PENDING_DELETE.toString())) {
                    this.nodeService.deleteById(draftNode.id());
                }
            }
            return null;
        });
    }
}
Also used : Context(com.enonic.xp.context.Context) Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) Nodes(com.enonic.xp.node.Nodes)

Example 35 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class UpdateIssueCommand method doExecute.

private Issue doExecute() {
    Issue editedIssue = editIssue(params.getEditor(), getIssue(params.getId()));
    final UpdateNodeParams updateNodeParams = UpdateNodeParamsFactory.create(editedIssue);
    final Node updatedNode = this.nodeService.update(updateNodeParams);
    nodeService.refresh(RefreshMode.SEARCH);
    return IssueNodeTranslator.fromNode(updatedNode);
}
Also used : EditableIssue(com.enonic.xp.issue.EditableIssue) Issue(com.enonic.xp.issue.Issue) PublishRequestIssue(com.enonic.xp.issue.PublishRequestIssue) EditablePublishRequestIssue(com.enonic.xp.issue.EditablePublishRequestIssue) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Node(com.enonic.xp.node.Node)

Aggregations

Node (com.enonic.xp.node.Node)521 Test (org.junit.jupiter.api.Test)371 PropertyTree (com.enonic.xp.data.PropertyTree)114 NodeId (com.enonic.xp.node.NodeId)52 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)51 NodePath (com.enonic.xp.node.NodePath)45 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)42 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)34 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)32 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)29 NodeQuery (com.enonic.xp.node.NodeQuery)27 AccessControlList (com.enonic.xp.security.acl.AccessControlList)27 BinaryReference (com.enonic.xp.util.BinaryReference)26 ByteSource (com.google.common.io.ByteSource)24 Content (com.enonic.xp.content.Content)23 PropertySet (com.enonic.xp.data.PropertySet)20 NodeIds (com.enonic.xp.node.NodeIds)18 Context (com.enonic.xp.context.Context)17 InternalContext (com.enonic.xp.repo.impl.InternalContext)17 Application (com.enonic.xp.app.Application)16