Search in sources :

Example 96 with Note

use of org.apache.zeppelin.notebook.Note in project zeppelin by apache.

the class NotebookServer method renameNote.

private void renameNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage, String op) throws SchedulerException, IOException {
    String noteId = (String) fromMessage.get("id");
    String name = (String) fromMessage.get("name");
    if (noteId == null) {
        return;
    }
    if (!hasParagraphOwnerPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "rename")) {
        return;
    }
    Note note = notebook.getNote(noteId);
    if (note != null) {
        note.setName(name);
        AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
        note.persist(subject);
        broadcastNote(note);
        broadcastNoteList(subject, userAndRoles);
    }
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 97 with Note

use of org.apache.zeppelin.notebook.Note in project zeppelin by apache.

the class NotebookServer method angularObjectUpdated.

/**
   * When angular object updated from client
   *
   * @param conn the web socket.
   * @param notebook the notebook.
   * @param fromMessage the message.
   */
private void angularObjectUpdated(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) {
    String noteId = (String) fromMessage.get("noteId");
    String paragraphId = (String) fromMessage.get("paragraphId");
    String interpreterGroupId = (String) fromMessage.get("interpreterGroupId");
    String varName = (String) fromMessage.get("name");
    Object varValue = fromMessage.get("value");
    String user = fromMessage.principal;
    AngularObject ao = null;
    boolean global = false;
    // propagate change to (Remote) AngularObjectRegistry
    Note note = notebook.getNote(noteId);
    if (note != null) {
        List<InterpreterSetting> settings = notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId());
        for (InterpreterSetting setting : settings) {
            if (setting.getInterpreterGroup(user, note.getId()) == null) {
                continue;
            }
            if (interpreterGroupId.equals(setting.getInterpreterGroup(user, note.getId()).getId())) {
                AngularObjectRegistry angularObjectRegistry = setting.getInterpreterGroup(user, note.getId()).getAngularObjectRegistry();
                // first trying to get local registry
                ao = angularObjectRegistry.get(varName, noteId, paragraphId);
                if (ao == null) {
                    // then try notebook scope registry
                    ao = angularObjectRegistry.get(varName, noteId, null);
                    if (ao == null) {
                        // then try global scope registry
                        ao = angularObjectRegistry.get(varName, null, null);
                        if (ao == null) {
                            LOG.warn("Object {} is not binded", varName);
                        } else {
                            // path from client -> server
                            ao.set(varValue, false);
                            global = true;
                        }
                    } else {
                        // path from client -> server
                        ao.set(varValue, false);
                        global = false;
                    }
                } else {
                    ao.set(varValue, false);
                    global = false;
                }
                break;
            }
        }
    }
    if (global) {
        // interpreter.
        for (Note n : notebook.getAllNotes()) {
            List<InterpreterSetting> settings = notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId());
            for (InterpreterSetting setting : settings) {
                if (setting.getInterpreterGroup(user, n.getId()) == null) {
                    continue;
                }
                if (interpreterGroupId.equals(setting.getInterpreterGroup(user, n.getId()).getId())) {
                    AngularObjectRegistry angularObjectRegistry = setting.getInterpreterGroup(user, n.getId()).getAngularObjectRegistry();
                    this.broadcastExcept(n.getId(), new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao).put("interpreterGroupId", interpreterGroupId).put("noteId", n.getId()).put("paragraphId", ao.getParagraphId()), conn);
                }
            }
        }
    } else {
        // broadcast to all web session for the note
        this.broadcastExcept(note.getId(), new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao).put("interpreterGroupId", interpreterGroupId).put("noteId", note.getId()).put("paragraphId", ao.getParagraphId()), conn);
    }
}
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) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) JsonObject(com.google.gson.JsonObject) AngularObject(org.apache.zeppelin.display.AngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 98 with Note

use of org.apache.zeppelin.notebook.Note in project zeppelin by apache.

the class NotebookServer method cloneNote.

private void cloneNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException, CloneNotSupportedException {
    String noteId = getOpenNoteId(conn);
    String name = (String) fromMessage.get("name");
    Note newNote = notebook.cloneNote(noteId, name, new AuthenticationInfo(fromMessage.principal));
    AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
    addConnectionToNote(newNote.getId(), (NotebookSocket) conn);
    conn.send(serializeMessage(new Message(OP.NEW_NOTE).put("note", newNote)));
    broadcastNoteList(subject, userAndRoles);
}
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)

Example 99 with Note

use of org.apache.zeppelin.notebook.Note in project zeppelin by apache.

the class NotebookServer method createNote.

private void createNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message message) throws IOException {
    AuthenticationInfo subject = new AuthenticationInfo(message.principal);
    try {
        Note note = null;
        String defaultInterpreterId = (String) message.get("defaultInterpreterId");
        if (!StringUtils.isEmpty(defaultInterpreterId)) {
            List<String> interpreterSettingIds = new LinkedList<>();
            interpreterSettingIds.add(defaultInterpreterId);
            for (String interpreterSettingId : notebook.getInterpreterSettingManager().getDefaultInterpreterSettingList()) {
                if (!interpreterSettingId.equals(defaultInterpreterId)) {
                    interpreterSettingIds.add(interpreterSettingId);
                }
            }
            note = notebook.createNote(interpreterSettingIds, subject);
        } else {
            note = notebook.createNote(subject);
        }
        // it's an empty note. so add one paragraph
        note.addParagraph(subject);
        if (message != null) {
            String noteName = (String) message.get("name");
            if (StringUtils.isEmpty(noteName)) {
                noteName = "Note " + note.getId();
            }
            note.setName(noteName);
        }
        note.persist(subject);
        addConnectionToNote(note.getId(), (NotebookSocket) conn);
        conn.send(serializeMessage(new Message(OP.NEW_NOTE).put("note", note)));
    } catch (FileSystemException e) {
        LOG.error("Exception from createNote", e);
        conn.send(serializeMessage(new Message(OP.ERROR_INFO).put("info", "Oops! There is something wrong with the notebook file system. " + "Please check the logs for more details.")));
        return;
    }
    broadcastNoteList(subject, userAndRoles);
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) 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) LinkedList(java.util.LinkedList)

Example 100 with Note

use of org.apache.zeppelin.notebook.Note in project zeppelin by apache.

the class NotebookServer method removeFolder.

private void removeFolder(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws SchedulerException, IOException {
    String folderId = (String) fromMessage.get("id");
    if (folderId == null) {
        return;
    }
    List<Note> notes = notebook.getNotesUnderFolder(folderId);
    for (Note note : notes) {
        String noteId = note.getId();
        if (!hasParagraphOwnerPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "remove folder of '" + note.getName() + "'")) {
            return;
        }
    }
    AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
    for (Note note : notes) {
        notebook.removeNote(note.getId(), subject);
        removeNote(note.getId());
    }
    broadcastNoteList(subject, userAndRoles);
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Aggregations

Note (org.apache.zeppelin.notebook.Note)142 Paragraph (org.apache.zeppelin.notebook.Paragraph)63 Test (org.junit.Test)63 Map (java.util.Map)35 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)31 IOException (java.io.IOException)24 Notebook (org.apache.zeppelin.notebook.Notebook)20 HashMap (java.util.HashMap)17 Message (org.apache.zeppelin.notebook.socket.Message)17 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)15 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)15 Path (javax.ws.rs.Path)13 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)13 NoteInfo (org.apache.zeppelin.notebook.NoteInfo)12 Gson (com.google.gson.Gson)11 TypeToken (com.google.gson.reflect.TypeToken)11 AngularObject (org.apache.zeppelin.display.AngularObject)11 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)9 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)9