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