/** * 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 notebook by JSON {}", message); NewNotebookRequest request = gson.fromJson(message, NewNotebookRequest.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(); p.setTitle(paragraphRequest.getTitle()); p.setText(paragraphRequest.getText()); } } note.addParagraph(); // add one paragraph to the last String noteName = request.getName(); if (noteName.isEmpty()) { noteName = "Note " + note.getId(); } note.setName(noteName); note.persist(subject); notebookServer.broadcastNote(note); notebookServer.broadcastNoteList(subject); return new JsonResponse<>(Status.CREATED, "", note.getId()).build(); }
/** * Clone note REST API * * @param * @return JSON with status.CREATED * @throws IOException, CloneNotSupportedException, IllegalArgumentException */ @POST @Path("{notebookId}") @ZeppelinApi public Response cloneNote(@PathParam("notebookId") String notebookId, String message) throws IOException, CloneNotSupportedException, IllegalArgumentException { LOG.info("clone notebook by JSON {}", message); NewNotebookRequest request = gson.fromJson(message, NewNotebookRequest.class); String newNoteName = request.getName(); AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); Note newNote = notebook.cloneNote(notebookId, newNoteName, subject); notebookServer.broadcastNote(newNote); notebookServer.broadcastNoteList(subject); return new JsonResponse<>(Status.CREATED, "", newNote.getId()).build(); }