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;
});
}
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;
});
}
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;
});
}
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;
}
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;
});
}
Aggregations