Search in sources :

Example 11 with NoteNotFoundException

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

the class NotebookService method updatePersonalizedMode.

public void updatePersonalizedMode(String noteId, boolean isPersonalized, 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.WRITER, Message.OP.UPDATE_PERSONALIZED_MODE, context, callback)) {
            return null;
        }
        note.setPersonalizedMode(isPersonalized);
        notebook.saveNote(note, context.getAutheInfo());
        callback.onSuccess(note, context);
        return null;
    });
}
Also used : NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException)

Example 12 with NoteNotFoundException

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

the class NotebookService method clearAllParagraphOutput.

public void clearAllParagraphOutput(String noteId, ServiceContext context, ServiceCallback<Note> callback) throws IOException {
    if (!checkPermission(noteId, Permission.WRITER, Message.OP.PARAGRAPH_CLEAR_ALL_OUTPUT, context, callback)) {
        return;
    }
    notebook.processNote(noteId, note -> {
        if (note == null) {
            callback.onFailure(new NoteNotFoundException(noteId), context);
            return null;
        }
        note.clearAllParagraphOutput();
        notebook.saveNote(note, context.getAutheInfo());
        callback.onSuccess(note, context);
        return null;
    });
}
Also used : NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException)

Example 13 with NoteNotFoundException

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

the class NotebookService method getNotebyRevision.

public void getNotebyRevision(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, context, callback)) {
            return null;
        }
        Note 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 14 with NoteNotFoundException

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

the class NotebookService method setNoteRevision.

public void setNoteRevision(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.WRITER, Message.OP.SET_NOTE_REVISION, context, callback)) {
            return null;
        }
        try {
            Note resultNote = notebook.setNoteRevision(noteId, note.getPath(), revisionId, context.getAutheInfo());
            callback.onSuccess(resultNote, context);
        } catch (Exception e) {
            callback.onFailure(new IOException("Fail to set given note revision", e), context);
        }
        return null;
    });
}
Also used : Note(org.apache.zeppelin.notebook.Note) IOException(java.io.IOException) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException) ParagraphNotFoundException(org.apache.zeppelin.rest.exception.ParagraphNotFoundException) ParseException(java.text.ParseException) IOException(java.io.IOException) NotePathAlreadyExistsException(org.apache.zeppelin.notebook.exception.NotePathAlreadyExistsException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) BadRequestException(org.apache.zeppelin.rest.exception.BadRequestException) CorruptedNoteException(org.apache.zeppelin.notebook.exception.CorruptedNoteException)

Example 15 with NoteNotFoundException

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

the class NotebookService method moveNoteToTrash.

public void moveNoteToTrash(String noteId, ServiceContext context, ServiceCallback<Note> callback) throws IOException {
    if (!checkPermission(noteId, Permission.OWNER, Message.OP.MOVE_NOTE_TO_TRASH, context, callback)) {
        return;
    }
    String destNotePath = "/" + NoteManager.TRASH_FOLDER + notebook.getNoteManager().getNotesInfo().get(noteId);
    if (notebook.containsNote(destNotePath)) {
        destNotePath = destNotePath + " " + TRASH_CONFLICT_TIMESTAMP_FORMATTER.format(Instant.now());
    }
    final String finalDestNotePath = destNotePath;
    try {
        notebook.processNote(noteId, note -> {
            if (note == null) {
                callback.onFailure(new NoteNotFoundException(noteId), context);
                return null;
            }
            notebook.moveNote(noteId, finalDestNotePath, context.getAutheInfo());
            callback.onSuccess(note, context);
            return null;
        });
    } catch (CorruptedNoteException e) {
        LOGGER.info("Move corrupted note to trash");
        notebook.moveNote(noteId, destNotePath, context.getAutheInfo());
    }
}
Also used : NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException) CorruptedNoteException(org.apache.zeppelin.notebook.exception.CorruptedNoteException)

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