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