Search in sources :

Example 1 with RestoreContentsResult

use of com.enonic.xp.archive.RestoreContentsResult 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 2 with RestoreContentsResult

use of com.enonic.xp.archive.RestoreContentsResult in project xp by enonic.

the class ContentServiceImplTest_restore method restore_to_custom_root_path.

@Test
public void restore_to_custom_root_path() throws Exception {
    final Content parent = createContent(ContentPath.ROOT, "archive");
    final Content child1 = createContent(parent.getPath(), "child1");
    createContent(child1.getPath(), "child1_1");
    createContent(child1.getPath(), "child2_1");
    this.contentService.archive(ArchiveContentParams.create().contentId(child1.getId()).build());
    RestoreContentsResult result = this.contentService.restore(RestoreContentParams.create().contentId(child1.getId()).restoreContentListener(listener).path(ContentPath.ROOT).build());
    assertEquals(3, listener.getRestored());
    assertEquals("/", result.getParentPath().toString());
}
Also used : RestoreContentsResult(com.enonic.xp.archive.RestoreContentsResult) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 3 with RestoreContentsResult

use of com.enonic.xp.archive.RestoreContentsResult in project xp by enonic.

the class ContentServiceImplTest_restore method restore_to_custom_path.

@Test
public void restore_to_custom_path() throws Exception {
    final Content parent = createContent(ContentPath.ROOT, "archive");
    final Content target = createContent(ContentPath.ROOT, "target");
    final Content child1 = createContent(parent.getPath(), "child1");
    createContent(child1.getPath(), "child1_1");
    createContent(child1.getPath(), "child2_1");
    this.contentService.archive(ArchiveContentParams.create().contentId(parent.getId()).build());
    RestoreContentsResult result = this.contentService.restore(RestoreContentParams.create().contentId(parent.getId()).restoreContentListener(listener).path(target.getPath()).build());
    assertEquals(4, listener.getRestored());
    assertEquals("/target", result.getParentPath().toString());
}
Also used : RestoreContentsResult(com.enonic.xp.archive.RestoreContentsResult) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 4 with RestoreContentsResult

use of com.enonic.xp.archive.RestoreContentsResult in project xp by enonic.

the class ContentServiceImplTest_restore method restore_to_not_existed_parent.

@Test
public void restore_to_not_existed_parent() throws Exception {
    final Content parent = createContent(ContentPath.ROOT, "archive");
    final Content child1 = createContent(parent.getPath(), "child1");
    createContent(child1.getPath(), "child1_1");
    createContent(child1.getPath(), "child2_1");
    this.contentService.archive(ArchiveContentParams.create().contentId(child1.getId()).build());
    this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(parent.getPath()).build());
    final RestoreContentsResult result = this.contentService.restore(RestoreContentParams.create().contentId(child1.getId()).restoreContentListener(listener).build());
    assertEquals(3, listener.getRestored());
    assertEquals(ContentPath.ROOT, result.getParentPath());
}
Also used : RestoreContentsResult(com.enonic.xp.archive.RestoreContentsResult) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 5 with RestoreContentsResult

use of com.enonic.xp.archive.RestoreContentsResult in project xp by enonic.

the class ContentServiceImplTest_restore method restore_tree.

@Test
public void restore_tree() throws Exception {
    final Content parent = createContent(ContentPath.ROOT, "archive");
    final Content child1 = createContent(parent.getPath(), "child1");
    final Content child1_1 = createContent(child1.getPath(), "child1_1");
    final Content child1_2 = createContent(child1.getPath(), "child2_1");
    this.contentService.archive(ArchiveContentParams.create().contentId(parent.getId()).build());
    final RestoreContentsResult result = this.contentService.restore(RestoreContentParams.create().contentId(parent.getId()).restoreContentListener(listener).build());
    assertEquals(1, result.getRestoredContents().getSize());
    assertEquals(4, listener.getRestored());
    assertTrue(this.contentService.contentExists(child1.getId()));
    assertTrue(this.contentService.contentExists(child1.getPath()));
    assertTrue(this.contentService.contentExists(child1_1.getId()));
    assertTrue(this.contentService.contentExists(child1_1.getPath()));
    assertTrue(this.contentService.contentExists(child1_2.getId()));
    assertTrue(this.contentService.contentExists(child1_2.getPath()));
    archiveContext().runWith(() -> {
        assertFalse(this.contentService.contentExists(child1.getId()));
        assertFalse(this.contentService.contentExists(child1.getPath()));
        assertFalse(this.contentService.contentExists(child1_1.getId()));
        assertFalse(this.contentService.contentExists(child1_1.getPath()));
        assertFalse(this.contentService.contentExists(child1_2.getId()));
        assertFalse(this.contentService.contentExists(child1_2.getPath()));
    });
}
Also used : RestoreContentsResult(com.enonic.xp.archive.RestoreContentsResult) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Aggregations

RestoreContentsResult (com.enonic.xp.archive.RestoreContentsResult)9 Content (com.enonic.xp.content.Content)5 Test (org.junit.jupiter.api.Test)5 RestoreContentException (com.enonic.xp.archive.RestoreContentException)1 RestoreContentParams (com.enonic.xp.archive.RestoreContentParams)1 ContentAccessException (com.enonic.xp.content.ContentAccessException)1 MoveNodeException (com.enonic.xp.node.MoveNodeException)1 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)1 Node (com.enonic.xp.node.Node)1 NodeAccessException (com.enonic.xp.node.NodeAccessException)1 NodePath (com.enonic.xp.node.NodePath)1