Search in sources :

Example 1 with NoteNotFoundException

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

the class NotebookService method insertParagraph.

public Paragraph insertParagraph(String noteId, int index, Map<String, Object> config, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
    if (!checkPermission(noteId, Permission.WRITER, Message.OP.INSERT_PARAGRAPH, context, callback)) {
        return null;
    }
    return notebook.processNote(noteId, note -> {
        if (note == null) {
            throw new NoteNotFoundException(noteId);
        }
        Paragraph newPara = note.insertNewParagraph(index, context.getAutheInfo());
        newPara.mergeConfig(config);
        notebook.saveNote(note, context.getAutheInfo());
        callback.onSuccess(newPara, context);
        return newPara;
    });
}
Also used : NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 2 with NoteNotFoundException

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

the class NotebookService method updateParagraph.

public void updateParagraph(String noteId, String paragraphId, String title, String text, Map<String, Object> params, Map<String, Object> config, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
    if (!checkPermission(noteId, Permission.WRITER, Message.OP.COMMIT_PARAGRAPH, 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;
        }
        p.settings.setParams(params);
        p.mergeConfig(config);
        p.setTitle(title);
        p.setText(text);
        if (note.isPersonalizedMode()) {
            p = p.getUserParagraph(context.getAutheInfo().getUser());
            p.settings.setParams(params);
            p.mergeConfig(config);
            p.setTitle(title);
            p.setText(text);
        }
        notebook.saveNote(note, context.getAutheInfo());
        callback.onSuccess(p, 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 3 with NoteNotFoundException

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

the class NotebookService method removeNoteForms.

public void removeNoteForms(String noteId, String formName, 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.REMOVE_NOTE_FORMS, context, callback)) {
            return null;
        }
        note.getNoteForms().remove(formName);
        note.getNoteParams().remove(formName);
        notebook.saveNote(note, context.getAutheInfo());
        callback.onSuccess(note, context);
        return null;
    });
}
Also used : NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException)

Example 4 with NoteNotFoundException

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

the class NotebookService method checkpointNote.

public NotebookRepoWithVersionControl.Revision checkpointNote(String noteId, String commitMessage, ServiceContext context, ServiceCallback<NotebookRepoWithVersionControl.Revision> callback) throws IOException {
    NotebookRepoWithVersionControl.Revision revision = notebook.processNote(noteId, note -> {
        if (note == null) {
            callback.onFailure(new NoteNotFoundException(noteId), context);
            return null;
        }
        if (!checkPermission(noteId, Permission.WRITER, Message.OP.REMOVE_NOTE_FORMS, context, callback)) {
            return null;
        }
        return notebook.checkpointNote(noteId, note.getPath(), commitMessage, context.getAutheInfo());
    });
    callback.onSuccess(revision, context);
    return revision;
}
Also used : NotebookRepoWithVersionControl(org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException)

Example 5 with NoteNotFoundException

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

the class NotebookService method restoreNote.

public void restoreNote(String noteId, ServiceContext context, ServiceCallback<Note> callback) throws IOException {
    if (!checkPermission(noteId, Permission.WRITER, Message.OP.RESTORE_NOTE, context, callback)) {
        return;
    }
    notebook.processNote(noteId, note -> {
        if (note == null) {
            callback.onFailure(new NoteNotFoundException(noteId), context);
            return null;
        }
        if (!note.getPath().startsWith("/" + NoteManager.TRASH_FOLDER)) {
            callback.onFailure(new IOException("Can not restore this note " + note.getPath() + " as it is not in trash folder"), context);
            return null;
        }
        try {
            String destNotePath = note.getPath().replace("/" + NoteManager.TRASH_FOLDER, "");
            notebook.moveNote(noteId, destNotePath, context.getAutheInfo());
            callback.onSuccess(note, context);
        } catch (IOException e) {
            callback.onFailure(new IOException("Fail to restore note: " + noteId, e), context);
        }
        return null;
    });
}
Also used : 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