use of org.apache.zeppelin.notebook.Folder in project zeppelin by apache.
the class NotebookServer method restoreFolder.
private void restoreFolder(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws SchedulerException, IOException {
String folderId = (String) fromMessage.get("id");
if (folderId == null) {
return;
}
Folder folder = notebook.getFolder(folderId);
if (folder != null && folder.isTrash()) {
String restoreName = folder.getId().replaceFirst(Folder.TRASH_FOLDER_ID + "/", "").trim();
// if the folder had conflict when it had moved to trash before
Pattern p = Pattern.compile("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$");
Matcher m = p.matcher(restoreName);
restoreName = m.replaceAll("").trim();
fromMessage.put("name", restoreName);
renameFolder(conn, userAndRoles, notebook, fromMessage, "restore");
}
}
use of org.apache.zeppelin.notebook.Folder in project zeppelin by apache.
the class NotebookServer method renameFolder.
private void renameFolder(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage, String op) throws SchedulerException, IOException {
String oldFolderId = (String) fromMessage.get("id");
String newFolderId = (String) fromMessage.get("name");
if (oldFolderId == null) {
return;
}
for (Note note : notebook.getNotesUnderFolder(oldFolderId)) {
String noteId = note.getId();
if (!hasParagraphOwnerPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, op + " folder of '" + note.getName() + "'")) {
return;
}
}
Folder oldFolder = notebook.renameFolder(oldFolderId, newFolderId);
if (oldFolder != null) {
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
List<Note> renamedNotes = oldFolder.getNotesRecursively();
for (Note note : renamedNotes) {
note.persist(subject);
broadcastNote(note);
}
broadcastNoteList(subject, userAndRoles);
}
}
use of org.apache.zeppelin.notebook.Folder in project zeppelin by apache.
the class NotebookServer method moveFolderToTrash.
private void moveFolderToTrash(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws SchedulerException, IOException {
String folderId = (String) fromMessage.get("id");
if (folderId == null) {
return;
}
Folder folder = notebook.getFolder(folderId);
if (folder != null && !folder.isTrash()) {
String trashFolderId = Folder.TRASH_FOLDER_ID + "/" + folderId;
if (notebook.hasFolder(trashFolderId)) {
DateTime currentDate = new DateTime();
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
trashFolderId += Folder.TRASH_FOLDER_CONFLICT_INFIX + formatter.print(currentDate);
}
fromMessage.put("name", trashFolderId);
renameFolder(conn, userAndRoles, notebook, fromMessage, "move");
}
}
use of org.apache.zeppelin.notebook.Folder in project zeppelin by apache.
the class NotebookServer method restoreAll.
private void restoreAll(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws SchedulerException, IOException {
Folder trashFolder = notebook.getFolder(Folder.TRASH_FOLDER_ID);
if (trashFolder != null) {
fromMessage.data = new HashMap<>();
fromMessage.put("id", Folder.TRASH_FOLDER_ID);
fromMessage.put("name", Folder.ROOT_FOLDER_ID);
renameFolder(conn, userAndRoles, notebook, fromMessage, "restore trash");
}
}
Aggregations