try {
Credentials creds = new SimpleCredentials("admin", "admin".toCharArray());
Session session = repo.login(creds);
String folderPath = "/uploads";
VersionManager versionManager = session.getWorkspace().getVersionManager();
Node node = session.getNode(folderPath);
Node originalNode = node.addNode("originalNode", NodeType.NT_FOLDER);
originalNode.addMixin(NodeType.MIX_VERSIONABLE);
originalNode.addMixin(NodeType.MIX_TITLE);
System.out.println("Original node added.");
session.save();
versionManager.checkout(originalNode.getPath());
originalNode.setProperty(Property.JCR_TITLE, "originalNode");
session.save();
versionManager.checkin(originalNode.getPath());
System.out.println("Original node updated.");
session.getWorkspace().copy(originalNode.getPath(), "/uploads/copiedNode");
System.out.println("Node has been copied.");
VersionHistory history = versionManager.getVersionHistory(originalNode.getPath());
VersionIterator it = history.getAllVersions();
while (it.hasNext()) {
Version version = it.nextVersion();
history.removeVersion(version.getName());
}
System.out.println("All versions of original node removed.");
originalNode.remove();
System.out.println("Original node removed.");
session.save();
session.logout();
}
catch (Exception e) {
e.printStackTrace();
}