Notebook { public Note cloneNote(String sourceNoteId, String newNotePath, AuthenticationInfo subject) throws IOException { Note sourceNote = getNote(sourceNoteId); if (sourceNote == null) { throw new IOException("Source note: " + sourceNoteId + " not found"); } Note newNote = createNote(newNotePath, subject, false); List<Paragraph> paragraphs = sourceNote.getParagraphs(); for (Paragraph p : paragraphs) { newNote.addCloneParagraph(p, subject); } saveNote(newNote, subject); authorizationService.cloneNoteMeta(newNote.getId(), sourceNoteId, subject); return newNote; } Notebook(
      ZeppelinConfiguration conf,
      AuthorizationService authorizationService,
      NotebookRepo notebookRepo,
      NoteManager noteManager,
      InterpreterFactory replFactory,
      InterpreterSettingManager interpreterSettingManager,
      SearchService noteSearchService,
      Credentials credentials); @Inject  Notebook(
      ZeppelinConfiguration conf,
      AuthorizationService authorizationService,
      NotebookRepo notebookRepo,
      NoteManager noteManager,
      InterpreterFactory replFactory,
      InterpreterSettingManager interpreterSettingManager,
      SearchService noteSearchService,
      Credentials credentials,
      NoteEventListener noteEventListener); void recoveryIfNecessary(); NoteManager getNoteManager(); void setParagraphJobListener(ParagraphJobListener paragraphJobListener); Note createNote(String notePath,
                         AuthenticationInfo subject); Note createNote(String notePath,
                         AuthenticationInfo subject,
                         boolean save); Note createNote(String notePath,
                         String defaultInterpreterGroup,
                         AuthenticationInfo subject); Note createNote(String notePath,
                         String defaultInterpreterGroup,
                         AuthenticationInfo subject,
                         boolean save); String exportNote(String noteId); Note importNote(String sourceJson, String notePath, AuthenticationInfo subject); Note cloneNote(String sourceNoteId, String newNotePath, AuthenticationInfo subject); void removeNote(Note note, AuthenticationInfo subject); Note getNote(String noteId); Note getNote(String noteId, boolean reload); void saveNote(Note note, AuthenticationInfo subject); boolean containsNote(String notePath); boolean containsFolder(String folderPath); void moveNote(String noteId, String newNotePath, AuthenticationInfo subject); void moveFolder(String folderPath, String newFolderPath, AuthenticationInfo subject); void removeFolder(String folderPath, AuthenticationInfo subject); void emptyTrash(AuthenticationInfo subject); void restoreAll(AuthenticationInfo subject); Revision checkpointNote(String noteId, String notePath, String checkpointMessage,
      AuthenticationInfo subject); List<Revision> listRevisionHistory(String noteId,
                                            String notePath,
                                            AuthenticationInfo subject); Note setNoteRevision(String noteId, String notePath, String revisionId, AuthenticationInfo subject); Note getNoteByRevision(String noteId, String noteName,
                                String revisionId, AuthenticationInfo subject); @SuppressWarnings("rawtypes") Note loadNoteFromRepo(String id, AuthenticationInfo subject); void reloadAllNotes(AuthenticationInfo subject); List<NoteInfo> getNotesInfo(); Stream<Note> getNoteStream(); @VisibleForTesting List<Note> getAllNotes(Function<Note, Boolean> func); @VisibleForTesting List<Note> getAllNotes(); List<NoteInfo> getNotesInfo(Function<String, Boolean> func); List<InterpreterSetting> getBindedInterpreterSettings(String noteId); InterpreterFactory getInterpreterFactory(); InterpreterSettingManager getInterpreterSettingManager(); ZeppelinConfiguration getConf(); void close(); void addNotebookEventListener(NoteEventListener listener); Boolean isRevisionSupported();  }
@Test public void testCloneNote() throws Exception { Note note = notebook.createNote("note1", anonymous); final Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); p.setText("hello world"); note.runAll(anonymous, true, false, new HashMap<>()); p.setStatus(Status.RUNNING); Note cloneNote = notebook.cloneNote(note.getId(), "clone note", anonymous); Paragraph cp = cloneNote.getParagraph(0); assertEquals(cp.getStatus(), Status.READY); assertEquals(cp.getId(), p.getId()); assertEquals(cp.getText(), p.getText()); assertEquals(cp.getReturn().message().get(0).getData(), p.getReturn().message().get(0).getData()); AuthenticationInfo subject = new AuthenticationInfo("user1"); Note cloneNote2 = notebook.cloneNote(note.getId(), "clone note2", subject); assertNotNull(authorizationService.getOwners(cloneNote2.getId())); assertEquals(1, authorizationService.getOwners(cloneNote2.getId()).size()); Set<String> owners = new HashSet<>(); owners.add("user1"); assertEquals(owners, authorizationService.getOwners(cloneNote2.getId())); notebook.removeNote(note, anonymous); notebook.removeNote(cloneNote, anonymous); notebook.removeNote(cloneNote2, anonymous); }