Search in sources :

Example 26 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method listRevisionHistory.

private void listRevisionHistory(NotebookSocket conn, Notebook notebook, Message fromMessage) throws IOException {
    String noteId = (String) fromMessage.get("noteId");
    AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
    List<Revision> revisions = notebook.listRevisionHistory(noteId, subject);
    conn.send(serializeMessage(new Message(OP.LIST_REVISION_HISTORY).put("revisionList", revisions)));
}
Also used : Revision(org.apache.zeppelin.notebook.repo.NotebookRepo.Revision) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 27 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method setNoteRevision.

private void setNoteRevision(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    String noteId = (String) fromMessage.get("noteId");
    String revisionId = (String) fromMessage.get("revisionId");
    AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
    if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "update")) {
        return;
    }
    Note headNote = null;
    boolean setRevisionStatus;
    try {
        headNote = notebook.setNoteRevision(noteId, revisionId, subject);
        setRevisionStatus = headNote != null;
    } catch (Exception e) {
        setRevisionStatus = false;
        LOG.error("Failed to set given note revision", e);
    }
    if (setRevisionStatus) {
        notebook.loadNoteFromRepo(noteId, subject);
    }
    conn.send(serializeMessage(new Message(OP.SET_NOTE_REVISION).put("status", setRevisionStatus)));
    if (setRevisionStatus) {
        Note reloadedNote = notebook.getNote(headNote.getId());
        broadcastNote(reloadedNote);
    } else {
        conn.send(serializeMessage(new Message(OP.ERROR_INFO).put("info", "Couldn't set note to the given revision. " + "Please check the logs for more details.")));
    }
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) URISyntaxException(java.net.URISyntaxException) FileSystemException(org.apache.commons.vfs2.FileSystemException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 28 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo 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 29 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method saveInterpreterBindings.

public void saveInterpreterBindings(NotebookSocket conn, Message fromMessage) {
    String noteId = (String) fromMessage.data.get("noteId");
    try {
        List<String> settingIdList = gson.fromJson(String.valueOf(fromMessage.data.get("selectedSettingIds")), new TypeToken<ArrayList<String>>() {
        }.getType());
        AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
        notebook().bindInterpretersToNote(subject.getUser(), noteId, settingIdList);
        broadcastInterpreterBindings(noteId, InterpreterBindingUtils.getInterpreterBindings(notebook(), noteId));
    } catch (Exception e) {
        LOG.error("Error while saving interpreter bindings", e);
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) URISyntaxException(java.net.URISyntaxException) FileSystemException(org.apache.commons.vfs2.FileSystemException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 30 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method removeNote.

private void removeNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    String noteId = (String) fromMessage.get("id");
    if (noteId == null) {
        return;
    }
    if (!hasParagraphOwnerPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "remove")) {
        return;
    }
    AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
    notebook.removeNote(noteId, subject);
    removeNote(noteId);
    broadcastNoteList(subject, userAndRoles);
}
Also used : AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Aggregations

AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)88 HashMap (java.util.HashMap)27 Note (org.apache.zeppelin.notebook.Note)27 Test (org.junit.Test)22 LinkedList (java.util.LinkedList)19 Properties (java.util.Properties)19 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)19 GUI (org.apache.zeppelin.display.GUI)19 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)17 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)16 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)15 Path (javax.ws.rs.Path)14 Message (org.apache.zeppelin.notebook.socket.Message)14 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)14 Paragraph (org.apache.zeppelin.notebook.Paragraph)12 Before (org.junit.Before)12 Map (java.util.Map)11 File (java.io.File)10 AngularObject (org.apache.zeppelin.display.AngularObject)9 POST (javax.ws.rs.POST)6