use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookServer method runParagraph.
private void runParagraph(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
final String paragraphId = (String) fromMessage.get("id");
if (paragraphId == null) {
return;
}
String noteId = getOpenNoteId(conn);
if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "write")) {
return;
}
String text = (String) fromMessage.get("paragraph");
String title = (String) fromMessage.get("title");
Map<String, Object> params = (Map<String, Object>) fromMessage.get("params");
Map<String, Object> config = (Map<String, Object>) fromMessage.get("config");
final Note note = notebook.getNote(noteId);
Paragraph p = setParagraphUsingMessage(note, fromMessage, paragraphId, text, title, params, config);
persistAndExecuteSingleParagraph(conn, note, p);
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookServer method insertParagraph.
private String insertParagraph(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
final int index = (int) Double.parseDouble(fromMessage.get("index").toString());
String noteId = getOpenNoteId(conn);
final Note note = notebook.getNote(noteId);
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "write")) {
return null;
}
Paragraph newPara = note.insertParagraph(index, subject);
note.persist(subject);
broadcastNewParagraph(note, newPara);
return newPara.getId();
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookRestApi method insertParagraph.
/**
* Insert paragraph REST API
*
* @param message - JSON containing paragraph's information
* @return JSON with status.OK
* @throws IOException
*/
@POST
@Path("{noteId}/paragraph")
@ZeppelinApi
public Response insertParagraph(@PathParam("noteId") String noteId, String message) throws IOException {
LOG.info("insert paragraph {} {}", noteId, message);
Note note = notebook.getNote(noteId);
checkIfNoteIsNotNull(note);
checkIfUserCanWrite(noteId, "Insufficient privileges you cannot add paragraph to this note");
NewParagraphRequest request = gson.fromJson(message, NewParagraphRequest.class);
AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
Paragraph p;
Double indexDouble = request.getIndex();
if (indexDouble == null) {
p = note.addParagraph(subject);
} else {
p = note.insertParagraph(indexDouble.intValue(), subject);
}
p.setTitle(request.getTitle());
p.setText(request.getText());
note.persist(subject);
notebookServer.broadcastNote(note);
return new JsonResponse<>(Status.OK, "", p.getId()).build();
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookRestApi method updateParagraphConfig.
@PUT
@Path("{noteId}/paragraph/{paragraphId}/config")
@ZeppelinApi
public Response updateParagraphConfig(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId, String message) throws IOException {
String user = SecurityUtils.getPrincipal();
LOG.info("{} will update paragraph config {} {}", user, noteId, paragraphId);
Note note = notebook.getNote(noteId);
checkIfNoteIsNotNull(note);
checkIfUserCanWrite(noteId, "Insufficient privileges you cannot update this paragraph config");
Paragraph p = note.getParagraph(paragraphId);
checkIfParagraphIsNotNull(p);
Map<String, Object> newConfig = gson.fromJson(message, HashMap.class);
if (newConfig == null || newConfig.isEmpty()) {
LOG.warn("{} is trying to update paragraph {} of note {} with empty config", user, paragraphId, noteId);
throw new BadRequestException("paragraph config cannot be empty");
}
Map<String, Object> origConfig = p.getConfig();
for (String key : newConfig.keySet()) {
origConfig.put(key, newConfig.get(key));
}
p.setConfig(origConfig);
AuthenticationInfo subject = new AuthenticationInfo(user);
note.persist(subject);
return new JsonResponse<>(Status.OK, "", p).build();
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookRestApi method getParagraph.
/**
* Get paragraph REST API
*
* @param noteId ID of Note
* @return JSON with information of the paragraph
* @throws IOException
*/
@GET
@Path("{noteId}/paragraph/{paragraphId}")
@ZeppelinApi
public Response getParagraph(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId) throws IOException {
LOG.info("get paragraph {} {}", noteId, paragraphId);
Note note = notebook.getNote(noteId);
checkIfNoteIsNotNull(note);
checkIfUserCanRead(noteId, "Insufficient privileges you cannot get this paragraph");
Paragraph p = note.getParagraph(paragraphId);
checkIfParagraphIsNotNull(p);
return new JsonResponse<>(Status.OK, "", p).build();
}
Aggregations