Search in sources :

Example 11 with Note

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

the class NotebookServer method onGetParagraphRunners.

@Override
public void onGetParagraphRunners(String noteId, String paragraphId, RemoteWorksEventListener callback) {
    Notebook notebookIns = notebook();
    List<InterpreterContextRunner> runner = new LinkedList<>();
    if (notebookIns == null) {
        LOG.info("intepreter request notebook instance is null");
        callback.onFinished(notebookIns);
    }
    try {
        Note note = notebookIns.getNote(noteId);
        if (note != null) {
            if (paragraphId != null) {
                Paragraph paragraph = note.getParagraph(paragraphId);
                if (paragraph != null) {
                    runner.add(paragraph.getInterpreterContextRunner());
                }
            } else {
                for (Paragraph p : note.getParagraphs()) {
                    runner.add(p.getInterpreterContextRunner());
                }
            }
        }
        callback.onFinished(runner);
    } catch (NullPointerException e) {
        LOG.warn(e.getMessage());
        callback.onError();
    }
}
Also used : InterpreterContextRunner(org.apache.zeppelin.interpreter.InterpreterContextRunner) Notebook(org.apache.zeppelin.notebook.Notebook) Note(org.apache.zeppelin.notebook.Note) LinkedList(java.util.LinkedList) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 12 with Note

use of org.apache.zeppelin.notebook.Note 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 13 with Note

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

the class NotebookServer method moveNoteToTrash.

private void moveNoteToTrash(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws SchedulerException, IOException {
    String noteId = (String) fromMessage.get("id");
    if (noteId == null) {
        return;
    }
    Note note = notebook.getNote(noteId);
    if (note != null && !note.isTrash()) {
        fromMessage.put("name", Folder.TRASH_FOLDER_ID + "/" + note.getName());
        renameNote(conn, userAndRoles, notebook, fromMessage, "move");
    }
}
Also used : Note(org.apache.zeppelin.notebook.Note)

Example 14 with Note

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

the class ZeppelinRestApiTest method testexportNote.

@Test
public void testexportNote() throws IOException {
    LOG.info("testexportNote");
    Note note = ZeppelinServer.notebook.createNote(anonymous);
    assertNotNull("can't create new note", note);
    note.setName("source note for export");
    Paragraph paragraph = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    Map config = paragraph.getConfig();
    config.put("enabled", true);
    paragraph.setConfig(config);
    paragraph.setText("%md This is my new paragraph in my new note");
    note.persist(anonymous);
    String sourceNoteId = note.getId();
    // Call export Note REST API
    GetMethod get = httpGet("/notebook/export/" + sourceNoteId);
    LOG.info("testNoteExport \n" + get.getResponseBodyAsString());
    assertThat("test note export method:", get, isAllowed());
    Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
    }.getType());
    String exportJSON = (String) resp.get("body");
    assertNotNull("Can not find new notejson", exportJSON);
    LOG.info("export JSON:=" + exportJSON);
    ZeppelinServer.notebook.removeNote(sourceNoteId, anonymous);
    get.releaseConnection();
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 15 with Note

use of org.apache.zeppelin.notebook.Note 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)

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