Search in sources :

Example 1 with NewNoteRequest

use of org.apache.zeppelin.rest.message.NewNoteRequest in project zeppelin by apache.

the class NotebookRestApi method createNote.

/**
   * Create new note REST API
   *
   * @param message - JSON with new note name
   * @return JSON with new note ID
   * @throws IOException
   */
@POST
@Path("/")
@ZeppelinApi
public Response createNote(String message) throws IOException {
    LOG.info("Create new note by JSON {}", message);
    NewNoteRequest request = gson.fromJson(message, NewNoteRequest.class);
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    Note note = notebook.createNote(subject);
    List<NewParagraphRequest> initialParagraphs = request.getParagraphs();
    if (initialParagraphs != null) {
        for (NewParagraphRequest paragraphRequest : initialParagraphs) {
            Paragraph p = note.addParagraph(subject);
            p.setTitle(paragraphRequest.getTitle());
            p.setText(paragraphRequest.getText());
        }
    }
    // add one paragraph to the last
    note.addParagraph(subject);
    String noteName = request.getName();
    if (noteName.isEmpty()) {
        noteName = "Note " + note.getId();
    }
    note.setName(noteName);
    note.persist(subject);
    notebookServer.broadcastNote(note);
    notebookServer.broadcastNoteList(subject, SecurityUtils.getRoles());
    return new JsonResponse<>(Status.OK, "", note.getId()).build();
}
Also used : NewNoteRequest(org.apache.zeppelin.rest.message.NewNoteRequest) NewParagraphRequest(org.apache.zeppelin.rest.message.NewParagraphRequest) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 2 with NewNoteRequest

use of org.apache.zeppelin.rest.message.NewNoteRequest in project zeppelin by apache.

the class NotebookRestApi method cloneNote.

/**
   * Clone note REST API
   *
   * @param noteId ID of Note
   * @return JSON with status.OK
   * @throws IOException, CloneNotSupportedException, IllegalArgumentException
   */
@POST
@Path("{noteId}")
@ZeppelinApi
public Response cloneNote(@PathParam("noteId") String noteId, String message) throws IOException, CloneNotSupportedException, IllegalArgumentException {
    LOG.info("clone note by JSON {}", message);
    checkIfUserCanWrite(noteId, "Insufficient privileges you cannot clone this note");
    NewNoteRequest request = gson.fromJson(message, NewNoteRequest.class);
    String newNoteName = null;
    if (request != null) {
        newNoteName = request.getName();
    }
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    Note newNote = notebook.cloneNote(noteId, newNoteName, subject);
    notebookServer.broadcastNote(newNote);
    notebookServer.broadcastNoteList(subject, SecurityUtils.getRoles());
    return new JsonResponse<>(Status.OK, "", newNote.getId()).build();
}
Also used : NewNoteRequest(org.apache.zeppelin.rest.message.NewNoteRequest) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Aggregations

POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)2 Note (org.apache.zeppelin.notebook.Note)2 NewNoteRequest (org.apache.zeppelin.rest.message.NewNoteRequest)2 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)2 Paragraph (org.apache.zeppelin.notebook.Paragraph)1 NewParagraphRequest (org.apache.zeppelin.rest.message.NewParagraphRequest)1