NotebookService { String normalizeNotePath(String notePath) throws IOException { if (StringUtils.isBlank(notePath)) { notePath = "/Untitled Note"; } if (!notePath.startsWith("/")) { notePath = "/" + notePath; } notePath = notePath.replace("\r", " ").replace("\n", " "); int pos = notePath.lastIndexOf("/"); if ((notePath.length() - pos) > 255) { throw new IOException("Note name must be less than 255"); } if (notePath.contains("..")) { throw new IOException("Note name can not contain '..'"); } return notePath; } @Inject  NotebookService(
      Notebook notebook,
      AuthorizationService authorizationService,
      ZeppelinConfiguration zeppelinConfiguration,
      SchedulerService schedulerService); Note getHomeNote(ServiceContext context,
                          ServiceCallback<Note> callback); Note getNote(String noteId,
                      ServiceContext context,
                      ServiceCallback<Note> callback); Note createNote(String notePath,
                         String defaultInterpreterGroup,
                         boolean addingEmptyParagraph,
                         ServiceContext context,
                         ServiceCallback<Note> callback); void removeNote(String noteId,
                         ServiceContext context,
                         ServiceCallback<String> callback); List<NoteInfo> listNotesInfo(boolean needsReload,
                                      ServiceContext context,
                                      ServiceCallback<List<NoteInfo>> callback); void renameNote(String noteId,
                         String newNotePath,
                         boolean isRelative,
                         ServiceContext context,
                         ServiceCallback<Note> callback); Note cloneNote(String noteId,
                        String newNotePath,
                        ServiceContext context,
                        ServiceCallback<Note> callback); Note importNote(String notePath,
                         String noteJson,
                         ServiceContext context,
                         ServiceCallback<Note> callback); boolean runParagraph(String noteId,
                              String paragraphId,
                              String title,
                              String text,
                              Map<String, Object> params,
                              Map<String, Object> config,
                              String sessionId,
                              boolean failIfDisabled,
                              boolean blocking,
                              ServiceContext context,
                              ServiceCallback<Paragraph> callback); boolean runAllParagraphs(String noteId,
                                  List<Map<String, Object>> paragraphs,
                                  ServiceContext context,
                                  ServiceCallback<Paragraph> callback); void cancelParagraph(String noteId,
                              String paragraphId,
                              ServiceContext context,
                              ServiceCallback<Paragraph> callback); void moveParagraph(String noteId,
                            String paragraphId,
                            int newIndex,
                            ServiceContext context,
                            ServiceCallback<Paragraph> callback); void removeParagraph(String noteId,
                              String paragraphId,
                              ServiceContext context,
                              ServiceCallback<Paragraph> callback); Paragraph insertParagraph(String noteId,
                                   int index,
                                   Map<String, Object> config,
                                   ServiceContext context,
                                   ServiceCallback<Paragraph> callback); void restoreNote(String noteId,
                          ServiceContext context,
                          ServiceCallback<Note> callback); void restoreFolder(String folderPath,
                            ServiceContext context,
                            ServiceCallback<Void> callback); void restoreAll(ServiceContext context,
                         ServiceCallback callback); void updateParagraph(String noteId,
                              String paragraphId,
                              String title,
                              String text,
                              Map<String, Object> params,
                              Map<String, Object> config,
                              ServiceContext context,
                              ServiceCallback<Paragraph> callback); Paragraph getNextSessionParagraph(String noteId,
                                        int maxParagraph,
                                        ServiceContext context,
                                        ServiceCallback<Paragraph> callback); void clearParagraphOutput(String noteId,
                                   String paragraphId,
                                   ServiceContext context,
                                   ServiceCallback<Paragraph> callback); void clearAllParagraphOutput(String noteId,
                                      ServiceContext context,
                                      ServiceCallback<Note> callback); void updateNote(String noteId,
                         String name,
                         Map<String, Object> config,
                         ServiceContext context,
                         ServiceCallback<Note> callback); void saveNoteForms(String noteId,
                            Map<String, Object> noteParams,
                            ServiceContext context,
                            ServiceCallback<Note> callback); void removeNoteForms(String noteId,
                              String formName,
                              ServiceContext context,
                              ServiceCallback<Note> callback); NotebookRepoWithVersionControl.Revision checkpointNote(
      String noteId,
      String commitMessage,
      ServiceContext context,
      ServiceCallback<NotebookRepoWithVersionControl.Revision> callback); List<NotebookRepoWithVersionControl.Revision> listRevisionHistory(
      String noteId,
      ServiceContext context,
      ServiceCallback<List<NotebookRepoWithVersionControl.Revision>> callback); Note setNoteRevision(String noteId,
                              String revisionId,
                              ServiceContext context,
                              ServiceCallback<Note> callback); void getNotebyRevision(String noteId,
                                String revisionId,
                                ServiceContext context,
                                ServiceCallback<Note> callback); void getNoteByRevisionForCompare(String noteId,
                                          String revisionId,
                                          ServiceContext context,
                                          ServiceCallback<Note> callback); List<InterpreterCompletion> completion(
      String noteId,
      String paragraphId,
      String buffer,
      int cursor,
      ServiceContext context,
      ServiceCallback<List<InterpreterCompletion>> callback); void getEditorSetting(String noteId,
                               String paragraphText,
                               ServiceContext context,
                               ServiceCallback<Map<String, Object>> callback); void updatePersonalizedMode(String noteId,
                                     boolean isPersonalized,
                                     ServiceContext context,
                                     ServiceCallback<Note> callback); void moveNoteToTrash(String noteId,
                              ServiceContext context,
                              ServiceCallback<Note> callback); void moveFolderToTrash(String folderPath,
                              ServiceContext context,
                              ServiceCallback<Void> callback); void emptyTrash(ServiceContext context,
                         ServiceCallback<Void> callback); List<NoteInfo> removeFolder(String folderPath,
                           ServiceContext context,
                           ServiceCallback<List<NoteInfo>> callback); List<NoteInfo> renameFolder(String folderPath,
                           String newFolderPath,
                           ServiceContext context,
                           ServiceCallback<List<NoteInfo>> callback); void spell(String noteId,
                    Message message,
                    ServiceContext context,
                    ServiceCallback<Paragraph> callback); void updateAngularObject(String noteId, String paragraphId, String interpreterGroupId,
                                  String varName, Object varValue,
                                  ServiceContext context,
                                  ServiceCallback<AngularObject> callback); void patchParagraph(final String noteId, final String paragraphId, String patchText,
                             ServiceContext context,
                             ServiceCallback<String> callback);  }
@Test public void testNormalizeNotePath() throws IOException { assertEquals("/Untitled Note", notebookService.normalizeNotePath(" ")); assertEquals("/Untitled Note", notebookService.normalizeNotePath(null)); assertEquals("/my_note", notebookService.normalizeNotePath("my_note")); assertEquals("/my note", notebookService.normalizeNotePath("my\r\nnote")); try { String longNoteName = StringUtils.join( IntStream.range(0, 256).boxed().collect(Collectors.toList()), ""); notebookService.normalizeNotePath(longNoteName); fail("Should fail"); } catch (IOException e) { assertEquals("Note name must be less than 255", e.getMessage()); } try { notebookService.normalizeNotePath("my..note"); fail("Should fail"); } catch (IOException e) { assertEquals("Note name can not contain '..'", e.getMessage()); } }