destinationParent.checkout();
destinationParent.getNode(sourceNode.getName()).remove();
destinationSession.save();
}
final VersionManager destinationVersionManager = destinationSession.getWorkspace().getVersionManager();
try {
Set<String> denied = new HashSet<String>();
NodeIterator it = sourceNode.getNodes();
while (it.hasNext()) {
JCRNodeWrapper nodeWrapper = (JCRNodeWrapper) it.next();
if (nodeWrapper.isVersioned()) {
denied.add(nodeWrapper.getPath());
}
}
JahiaAccessManager.setDeniedPaths(denied);
if (!destinationVersionManager.isCheckedOut(destinationParentPath)) {
destinationVersionManager.checkout(destinationParentPath);
}
String destinationPath;
if (destinationParentPath.equals("/")) {
destinationPath = "/" + sourceNode.getName();
} else {
destinationPath = destinationParentPath + "/" + sourceNode.getName();
}
try {
String correspondingNodePath = sourceNode.getCorrespondingNodePath(destinationWorkspaceName);
logger.warn("Cloning existing node "+sourceNode.getPath());
if (sourceNode.isNodeType("mix:shareable")) {
// Shareable node - todo : check if we need to move or clone
String oldPath = handleSharedMove(sourceSession, sourceNode, destinationPath);
// Clone the node node in live space
destinationSession.getWorkspace()
.clone(destinationWorkspaceName, correspondingNodePath, destinationPath, false);
if (oldPath != null) {
try {
JCRNodeWrapper node = destinationSession.getNode(oldPath);
recurseCheckout(node, null, destinationVersionManager);
JCRNodeWrapper oldParent = node.getParent();
if (!destinationVersionManager.isCheckedOut(oldParent.getPath())) {
destinationVersionManager.checkout(oldParent.getPath());
}
node.remove();
node.getSession().save();
} catch (RepositoryException e) {
e.printStackTrace();
}
}
} else {
// Non shareable node has been moved
destinationVersionManager
.checkout(StringUtils.substringBeforeLast(correspondingNodePath, "/")); // previous parent
destinationVersionManager.checkout(destinationParentPath); // new parent
recurseCheckout(destinationSession.getNode(correspondingNodePath), null,
destinationVersionManager); // node and sub nodes
destinationSession.move(correspondingNodePath, destinationPath);
destinationSession.save();