Search in sources :

Example 1 with BadRequestException

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

the class NotebookService method moveParagraph.

public void moveParagraph(String noteId, String paragraphId, int newIndex, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
    if (!checkPermission(noteId, Permission.WRITER, Message.OP.MOVE_PARAGRAPH, context, callback)) {
        return;
    }
    notebook.processNote(noteId, note -> {
        if (note == null) {
            throw new NoteNotFoundException(noteId);
        }
        if (note.getParagraph(paragraphId) == null) {
            throw new ParagraphNotFoundException(paragraphId);
        }
        if (newIndex >= note.getParagraphCount()) {
            callback.onFailure(new BadRequestException("newIndex " + newIndex + " is out of bounds"), context);
            return null;
        }
        note.moveParagraph(paragraphId, newIndex);
        notebook.saveNote(note, context.getAutheInfo());
        callback.onSuccess(note.getParagraph(newIndex), context);
        return null;
    });
}
Also used : BadRequestException(org.apache.zeppelin.rest.exception.BadRequestException) ParagraphNotFoundException(org.apache.zeppelin.rest.exception.ParagraphNotFoundException) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException)

Aggregations

BadRequestException (org.apache.zeppelin.rest.exception.BadRequestException)1 NoteNotFoundException (org.apache.zeppelin.rest.exception.NoteNotFoundException)1 ParagraphNotFoundException (org.apache.zeppelin.rest.exception.ParagraphNotFoundException)1