Search in sources :

Example 6 with NoteNotFoundException

use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.

the class NotebookService method clearParagraphOutput.

public void clearParagraphOutput(String noteId, String paragraphId, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
    if (!checkPermission(noteId, Permission.WRITER, Message.OP.PARAGRAPH_CLEAR_OUTPUT, context, callback)) {
        return;
    }
    notebook.processNote(noteId, note -> {
        if (note == null) {
            callback.onFailure(new NoteNotFoundException(noteId), context);
            return null;
        }
        Paragraph p = note.getParagraph(paragraphId);
        if (p == null) {
            callback.onFailure(new ParagraphNotFoundException(paragraphId), context);
            return null;
        }
        Paragraph returnedParagraph;
        if (note.isPersonalizedMode()) {
            returnedParagraph = note.clearPersonalizedParagraphOutput(paragraphId, context.getAutheInfo().getUser());
        } else {
            note.clearParagraphOutput(paragraphId);
            returnedParagraph = note.getParagraph(paragraphId);
        }
        callback.onSuccess(returnedParagraph, context);
        return null;
    });
}
Also used : ParagraphNotFoundException(org.apache.zeppelin.rest.exception.ParagraphNotFoundException) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 7 with NoteNotFoundException

use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.

the class NotebookService method saveNoteForms.

public void saveNoteForms(String noteId, Map<String, Object> noteParams, ServiceContext context, ServiceCallback<Note> callback) throws IOException {
    if (!checkPermission(noteId, Permission.WRITER, Message.OP.SAVE_NOTE_FORMS, context, callback)) {
        return;
    }
    // use write lock because noteParams are overwritten
    notebook.processNote(noteId, note -> {
        if (note == null) {
            callback.onFailure(new NoteNotFoundException(noteId), context);
            return null;
        }
        note.setNoteParams(noteParams);
        notebook.saveNote(note, context.getAutheInfo());
        callback.onSuccess(note, context);
        return null;
    });
}
Also used : NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException)

Example 8 with NoteNotFoundException

use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.

the class NotebookService method getNote.

public <T> T getNote(String noteId, boolean reload, ServiceContext context, ServiceCallback<Note> callback, NoteProcessor<T> noteProcessor) throws IOException {
    return notebook.processNote(noteId, reload, note -> {
        if (note == null) {
            callback.onFailure(new NoteNotFoundException(noteId), context);
            return null;
        }
        if (!checkPermission(noteId, Permission.READER, Message.OP.GET_NOTE, context, callback)) {
            return null;
        }
        Note newNote = note;
        if (note.isPersonalizedMode()) {
            newNote = note.getUserNote(context.getAutheInfo().getUser());
        }
        callback.onSuccess(newNote, context);
        if (noteProcessor == null) {
            return null;
        }
        return noteProcessor.process(newNote);
    });
}
Also used : Note(org.apache.zeppelin.notebook.Note) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException)

Example 9 with NoteNotFoundException

use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.

the class NotebookService method getNoteByRevisionForCompare.

public void getNoteByRevisionForCompare(String noteId, String revisionId, ServiceContext context, ServiceCallback<Note> callback) throws IOException {
    notebook.processNote(noteId, note -> {
        if (note == null) {
            callback.onFailure(new NoteNotFoundException(noteId), context);
            return null;
        }
        if (!checkPermission(noteId, Permission.READER, Message.OP.NOTE_REVISION_FOR_COMPARE, context, callback)) {
            return null;
        }
        Note revisionNote;
        if (revisionId.equals("Head")) {
            revisionNote = note;
        } else {
            revisionNote = notebook.getNoteByRevision(noteId, note.getPath(), revisionId, context.getAutheInfo());
        }
        callback.onSuccess(revisionNote, context);
        return null;
    });
}
Also used : Note(org.apache.zeppelin.notebook.Note) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException)

Example 10 with NoteNotFoundException

use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.

the class NotebookService method completion.

public List<InterpreterCompletion> completion(String noteId, String paragraphId, String buffer, int cursor, ServiceContext context, ServiceCallback<List<InterpreterCompletion>> callback) throws IOException {
    return notebook.processNote(noteId, note -> {
        if (note == null) {
            callback.onFailure(new NoteNotFoundException(noteId), context);
            return null;
        }
        if (!checkPermission(noteId, Permission.WRITER, Message.OP.COMPLETION, context, callback)) {
            return null;
        }
        try {
            List<InterpreterCompletion> completions = note.completion(paragraphId, buffer, cursor, context.getAutheInfo());
            callback.onSuccess(completions, context);
            return completions;
        } catch (RuntimeException e) {
            callback.onFailure(new IOException("Fail to get completion", e), context);
            return null;
        }
    });
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) IOException(java.io.IOException) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException)

Aggregations

NoteNotFoundException (org.apache.zeppelin.rest.exception.NoteNotFoundException)25 ParagraphNotFoundException (org.apache.zeppelin.rest.exception.ParagraphNotFoundException)8 IOException (java.io.IOException)6 Paragraph (org.apache.zeppelin.notebook.Paragraph)6 CorruptedNoteException (org.apache.zeppelin.notebook.exception.CorruptedNoteException)5 Note (org.apache.zeppelin.notebook.Note)4 NotePathAlreadyExistsException (org.apache.zeppelin.notebook.exception.NotePathAlreadyExistsException)4 BadRequestException (org.apache.zeppelin.rest.exception.BadRequestException)4 ParseException (java.text.ParseException)3 ForbiddenException (org.apache.zeppelin.rest.exception.ForbiddenException)3 AngularObject (org.apache.zeppelin.display.AngularObject)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1 InterpreterCompletion (org.apache.zeppelin.interpreter.thrift.InterpreterCompletion)1 NotebookRepoWithVersionControl (org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl)1