Search in sources :

Example 1 with Folder

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");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Folder(org.apache.zeppelin.notebook.Folder)

Example 2 with Folder

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);
    }
}
Also used : Note(org.apache.zeppelin.notebook.Note) Folder(org.apache.zeppelin.notebook.Folder) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 3 with Folder

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");
    }
}
Also used : Folder(org.apache.zeppelin.notebook.Folder) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime)

Example 4 with Folder

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");
    }
}
Also used : Folder(org.apache.zeppelin.notebook.Folder)

Aggregations

Folder (org.apache.zeppelin.notebook.Folder)4 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Note (org.apache.zeppelin.notebook.Note)1 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)1 DateTime (org.joda.time.DateTime)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1