Search in sources :

Example 1 with CorruptedNoteException

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

Example 2 with CorruptedNoteException

use of org.apache.zeppelin.notebook.exception.CorruptedNoteException in project zeppelin by apache.

the class NotebookService method removeNote.

public void removeNote(String noteId, ServiceContext context, ServiceCallback<String> callback) throws IOException {
    if (!checkPermission(noteId, Permission.OWNER, Message.OP.DEL_NOTE, context, callback)) {
        return;
    }
    if (notebook.containsNoteById(noteId)) {
        try {
            notebook.removeNote(noteId, context.getAutheInfo());
            callback.onSuccess("Delete note successfully", context);
        } catch (CorruptedNoteException e) {
            notebook.removeCorruptedNote(noteId, context.getAutheInfo());
            callback.onSuccess("Delete note successfully", context);
        }
    } else {
        callback.onFailure(new NoteNotFoundException(noteId), context);
    }
}
Also used : NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException) CorruptedNoteException(org.apache.zeppelin.notebook.exception.CorruptedNoteException)

Example 3 with CorruptedNoteException

use of org.apache.zeppelin.notebook.exception.CorruptedNoteException in project zeppelin by apache.

the class Note method fromJson.

/**
 * Parse note json from note file. Throw IOException if fail to parse note json.
 *
 * @param json
 * @return Note
 * @throws IOException if fail to parse note json (note file may be corrupted)
 */
public static Note fromJson(String noteId, String json) throws IOException {
    try {
        Note note = GSON.fromJson(json, Note.class);
        convertOldInput(note);
        note.info.remove("isRunning");
        note.postProcessParagraphs();
        return note;
    } catch (Exception e) {
        LOGGER.error("Fail to parse note json: {}", e.toString());
        throw new CorruptedNoteException(noteId, "Fail to parse note json: " + json, e);
    }
}
Also used : CorruptedNoteException(org.apache.zeppelin.notebook.exception.CorruptedNoteException) IOException(java.io.IOException) InterpreterNotFoundException(org.apache.zeppelin.interpreter.InterpreterNotFoundException) CorruptedNoteException(org.apache.zeppelin.notebook.exception.CorruptedNoteException)

Aggregations

CorruptedNoteException (org.apache.zeppelin.notebook.exception.CorruptedNoteException)3 NoteNotFoundException (org.apache.zeppelin.rest.exception.NoteNotFoundException)2 IOException (java.io.IOException)1 InterpreterNotFoundException (org.apache.zeppelin.interpreter.InterpreterNotFoundException)1