NotebookServer extends WebSocketServlet implements NotebookSocketListener,
        AngularObjectRegistryListener,
        RemoteInterpreterProcessListener,
        ApplicationEventListener,
        ParagraphJobListener,
        NoteEventListener,
        ClusterEventListener { @Override public List<ParagraphInfo> getParagraphList(String user, String noteId) throws TException, IOException { Notebook notebook = getNotebook(); Note note = notebook.getNote(noteId); if (null == note) { throw new ServiceException("Not found this note : " + noteId); } Set<String> userAndRoles = new HashSet<>(); userAndRoles.add(user); AuthorizationService notebookAuthorization = getNotebookAuthorizationService(); boolean isAllowed = notebookAuthorization.isReader(noteId, userAndRoles); Set<String> allowed = notebookAuthorization.getReaders(noteId); if (false == isAllowed) { String errorMsg = "Insufficient privileges to READER note. " + "Allowed users or roles: " + allowed; throw new ServiceException(errorMsg); } List<ParagraphInfo> paragraphInfos = new ArrayList(); List<Paragraph> paragraphs = note.getParagraphs(); for (Iterator<Paragraph> iter = paragraphs.iterator(); iter.hasNext();) { Paragraph paragraph = iter.next(); ParagraphInfo paraInfo = new ParagraphInfo(); paraInfo.setNoteId(noteId); paraInfo.setParagraphId(paragraph.getId()); paraInfo.setParagraphTitle(paragraph.getTitle()); paraInfo.setParagraphText(paragraph.getText()); paragraphInfos.add(paraInfo); } return paragraphInfos; } NotebookServer(); @Inject void setServiceLocator(ServiceLocator serviceLocator); @Inject void setNotebook(Provider<Notebook> notebookProvider); @Inject void setNotebookService(
      Provider<NotebookService> notebookServiceProvider); @Inject void setAuthorizationServiceProvider(Provider<AuthorizationService>
                                                      authorizationServiceProvider); @Inject void setConnectionManagerProvider(Provider<ConnectionManager> connectionManagerProvider); @Inject void setConfigurationService(
      Provider<ConfigurationService> configurationServiceProvider); @Inject void setJobManagerService(
      Provider<JobManagerService> jobManagerServiceProvider); static NotebookServer getInstance(); Notebook getNotebook(); ConnectionManager getConnectionManager(); NotebookService getNotebookService(); ConfigurationService getConfigurationService(); synchronized JobManagerService getJobManagerService(); AuthorizationService getNotebookAuthorizationService(); @Override void configure(WebSocketServletFactory factory); boolean checkOrigin(HttpServletRequest request, String origin); @Override void onOpen(NotebookSocket conn); @Override void onMessage(NotebookSocket conn, String msg); @Override void onClose(NotebookSocket conn, int code, String reason); void broadcast(Message m); void unicastNoteJobInfo(NotebookSocket conn, Message fromMessage); void broadcastUpdateNoteJobInfo(Note note, long lastUpdateUnixTime); void unsubscribeNoteJobInfo(NotebookSocket conn); void getInterpreterBindings(NotebookSocket conn, Message fromMessage); void saveInterpreterBindings(NotebookSocket conn, Message fromMessage); void broadcastNote(Note note); void broadcastParagraph(Note note, Paragraph p, String msgId); void inlineBroadcastNoteList(AuthenticationInfo subject, Set<String> userAndRoles); void broadcastNoteList(AuthenticationInfo subject, Set<String> userAndRoles); @Override void onClusterEvent(String msg); void listNotesInfo(NotebookSocket conn, Message message); void broadcastReloadedNoteList(NotebookSocket conn, ServiceContext context); @Override void onOutputAppend(String noteId, String paragraphId, int index, String output); @Override void onOutputUpdated(String noteId, String paragraphId, int index,
                              InterpreterResult.Type type, String output); @Override void onOutputClear(String noteId, String paragraphId); @Override void onOutputAppend(String noteId, String paragraphId, int index, String appId,
                             String output); @Override void onOutputUpdated(String noteId, String paragraphId, int index, String appId,
                              InterpreterResult.Type type, String output); @Override void onLoad(String noteId, String paragraphId, String appId, HeliumPackage pkg); @Override void onStatusChange(String noteId, String paragraphId, String appId, String status); @Override void runParagraphs(String noteId,
                            List<Integer> paragraphIndices,
                            List<String> paragraphIds,
                            String curParagraphId); @Override void onParagraphRemove(Paragraph p); @Override void onNoteRemove(Note note, AuthenticationInfo subject); @Override void onParagraphCreate(Paragraph p); @Override void onParagraphUpdate(Paragraph p); @Override void onNoteCreate(Note note, AuthenticationInfo subject); @Override void onNoteUpdate(Note note, AuthenticationInfo subject); @Override void onParagraphStatusChange(Paragraph p, Status status); @Override void onProgressUpdate(Paragraph p, int progress); @Override void onStatusChange(Paragraph p, Status before, Status after); @Override void checkpointOutput(String noteId, String paragraphId); @Override void noteRunningStatusChange(String noteId, boolean newStatus); @Override void onAddAngularObject(String interpreterGroupId, AngularObject angularObject); @Override void onUpdateAngularObject(String interpreterGroupId, AngularObject angularObject); @Override void onRemoveAngularObject(String interpreterGroupId, AngularObject angularObject); @Override void onParaInfosReceived(String noteId, String paragraphId,
                                  String interpreterSettingId, Map<String, String> metaInfos); @Override List<ParagraphInfo> getParagraphList(String user, String noteId); @ManagedAttribute Set<String> getConnectedUsers(); @ManagedOperation void sendMessage(String message);  }
@Test public void testGetParagraphList() throws IOException { Note note = null; try { note = notebook.createNote("note1", anonymous); Paragraph p1 = note.addNewParagraph(anonymous); p1.setText("%md start remote interpreter process"); p1.setAuthenticationInfo(anonymous); notebook.saveNote(note, anonymous); String noteId = note.getId(); String user1Id = "user1", user2Id = "user2"; List<ParagraphInfo> paragraphList0 = null; try { paragraphList0 = notebookServer.getParagraphList(user1Id, noteId); } catch (ServiceException e) { e.printStackTrace(); } catch (TException e) { e.printStackTrace(); } assertNotNull(user1Id + " can get anonymous's note", paragraphList0); authorizationService.setOwners(noteId, new HashSet<>(Arrays.asList(user2Id))); authorizationService.setReaders(noteId, new HashSet<>(Arrays.asList(user2Id))); authorizationService.setRunners(noteId, new HashSet<>(Arrays.asList(user2Id))); authorizationService.setWriters(noteId, new HashSet<>(Arrays.asList(user2Id))); List<ParagraphInfo> paragraphList1 = null; try { paragraphList1 = notebookServer.getParagraphList(user1Id, noteId); } catch (ServiceException e) { e.printStackTrace(); } catch (TException e) { e.printStackTrace(); } assertNull(user1Id + " cannot get " + user2Id + "'s note", paragraphList1); authorizationService.setOwners(noteId, new HashSet<>(Arrays.asList(user2Id))); authorizationService.setReaders(noteId, new HashSet<>(Arrays.asList(user1Id, user2Id))); authorizationService.setRunners(noteId, new HashSet<>(Arrays.asList(user2Id))); authorizationService.setWriters(noteId, new HashSet<>(Arrays.asList(user2Id))); List<ParagraphInfo> paragraphList2 = null; try { paragraphList2 = notebookServer.getParagraphList(user1Id, noteId); } catch (ServiceException e) { e.printStackTrace(); } catch (TException e) { e.printStackTrace(); } assertNotNull(user1Id + " can get " + user2Id + "'s shared note", paragraphList2); } finally { if (null != note) { notebook.removeNote(note, anonymous); } } }