Search in sources :

Example 1 with DeleteContentsResult

use of com.enonic.xp.content.DeleteContentsResult in project xp by enonic.

the class ContentServiceImpl method deleteWithoutFetch.

@Override
public DeleteContentsResult deleteWithoutFetch(final DeleteContentParams params) {
    final DeleteContentsResult result = DeleteContentCommand.create().nodeService(this.nodeService).contentTypeService(this.contentTypeService).translator(this.translator).eventPublisher(this.eventPublisher).params(params).build().execute();
    contentAuditLogSupport.delete(params, result);
    return result;
}
Also used : DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult)

Example 2 with DeleteContentsResult

use of com.enonic.xp.content.DeleteContentsResult in project xp by enonic.

the class DeleteContentCommand method doDeleteContent.

private DeleteContentsResult doDeleteContent(NodeId nodeToDelete) {
    final CompareStatus rootNodeStatus = getCompareStatus(nodeToDelete);
    final DeleteContentsResult.Builder result = DeleteContentsResult.create();
    if (rootNodeStatus == CompareStatus.NEW) {
        // Root node is new, just delete all children
        final NodeIds nodes = this.nodeService.deleteById(nodeToDelete, this);
        result.addDeleted(ContentIds.from(nodes.getAsStrings()));
    } else if (this.params.isDeleteOnline()) {
        deleteNodeInDraftAndMaster(nodeToDelete, result);
    } else {
        this.nodeService.setNodeState(SetNodeStateParams.create().nodeId(nodeToDelete).nodeState(NodeState.PENDING_DELETE).build());
        result.addPending(ContentId.from(nodeToDelete.toString()));
        this.nodesDeleted(1);
        final NodeIds children = getDirectChildren(nodeToDelete);
        for (final NodeId child : children) {
            final DeleteContentsResult childDeleteResult = this.doDeleteContent(child);
            result.addDeleted(childDeleteResult.getDeletedContents());
            result.addPending(childDeleteResult.getPendingContents());
        }
    }
    return result.build();
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) CompareStatus(com.enonic.xp.content.CompareStatus) NodeId(com.enonic.xp.node.NodeId) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult)

Example 3 with DeleteContentsResult

use of com.enonic.xp.content.DeleteContentsResult 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 4 with DeleteContentsResult

use of com.enonic.xp.content.DeleteContentsResult in project xp by enonic.

the class ContentServiceImplTest_delete method move_to_folder_starting_with_same_name_and_delete.

@Test
public void move_to_folder_starting_with_same_name_and_delete() throws Exception {
    final Content site = createContent(ContentPath.ROOT, "site");
    final Content child1 = createContent(site.getPath(), "child1");
    createContent(child1.getPath(), "child1_1");
    createContent(child1.getPath(), "child2_1");
    final Content site2 = createContent(ContentPath.ROOT, "site2");
    refresh();
    final MoveContentParams params = MoveContentParams.create().contentId(child1.getId()).parentContentPath(site2.getPath()).build();
    this.contentService.move(params);
    final DeleteContentsResult result = this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(site.getPath()).build());
    assertEquals(1, result.getDeletedContents().getSize());
}
Also used : MoveContentParams(com.enonic.xp.content.MoveContentParams) Content(com.enonic.xp.content.Content) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Example 5 with DeleteContentsResult

use of com.enonic.xp.content.DeleteContentsResult in project xp by enonic.

the class ContentServiceImplTest_delete method create_delete_content.

@Test
public void create_delete_content() throws Exception {
    // Creates a content
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").name("myContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    // Deletes the content
    final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(content.getPath()).build();
    final DeleteContentsResult deletedContents = this.contentService.deleteWithoutFetch(deleteContentParams);
    assertNotNull(deletedContents);
    assertEquals(1, deletedContents.getDeletedContents().getSize());
    assertEquals(content.getId(), deletedContents.getDeletedContents().first());
    // Checks that the content is deleted
    final ContentIds contentIds = ContentIds.from(content.getId());
    final GetContentByIdsParams getContentByIdsParams = new GetContentByIdsParams(contentIds);
    final Contents foundContents = this.contentService.getByIds(getContentByIdsParams);
    assertEquals(0, foundContents.getSize());
}
Also used : DeleteContentParams(com.enonic.xp.content.DeleteContentParams) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Contents(com.enonic.xp.content.Contents) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIds(com.enonic.xp.content.ContentIds) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Aggregations

DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)17 Content (com.enonic.xp.content.Content)12 Test (org.junit.jupiter.api.Test)12 PropertyTree (com.enonic.xp.data.PropertyTree)11 CreateContentParams (com.enonic.xp.content.CreateContentParams)9 PublishContentResult (com.enonic.xp.content.PublishContentResult)5 ContentIds (com.enonic.xp.content.ContentIds)4 Contents (com.enonic.xp.content.Contents)4 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)4 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)3 Node (com.enonic.xp.node.Node)2 NodeIds (com.enonic.xp.node.NodeIds)2 CompareStatus (com.enonic.xp.content.CompareStatus)1 ContentAccessException (com.enonic.xp.content.ContentAccessException)1 ContentId (com.enonic.xp.content.ContentId)1 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)1 ContentPath (com.enonic.xp.content.ContentPath)1 MoveContentParams (com.enonic.xp.content.MoveContentParams)1 PushContentParams (com.enonic.xp.content.PushContentParams)1 NodeAccessException (com.enonic.xp.node.NodeAccessException)1