NotebookRestApi { @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(); 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(); } NotebookRestApi();  NotebookRestApi(Notebook notebook, NotebookServer notebookServer, SearchService search); @GET @Path("{noteId}/permissions") @ZeppelinApi Response getNotePermissions(@PathParam("noteId") String noteId); @PUT @Path("{noteId}/permissions") @ZeppelinApi Response putNotePermissions(@PathParam("noteId") String noteId, String req); @PUT @Path("interpreter/bind/{noteId}") @ZeppelinApi Response bind(@PathParam("noteId") String noteId, String req); @GET @Path("interpreter/bind/{noteId}") @ZeppelinApi Response bind(@PathParam("noteId") String noteId); @GET @Path("/") @ZeppelinApi Response getNotebookList(); @GET @Path("{notebookId}") @ZeppelinApi Response getNotebook(@PathParam("notebookId") String notebookId); @GET @Path("export/{id}") @ZeppelinApi Response exportNoteBook(@PathParam("id") String noteId); @POST @Path("import") @ZeppelinApi Response importNotebook(String req); @POST @Path("/") @ZeppelinApi Response createNote(String message); @DELETE @Path("{notebookId}") @ZeppelinApi Response deleteNote(@PathParam("notebookId") String notebookId); @POST @Path("{notebookId}") @ZeppelinApi Response cloneNote(@PathParam("notebookId") String notebookId, String message); @POST @Path("{notebookId}/paragraph") @ZeppelinApi Response insertParagraph(@PathParam("notebookId") String notebookId, String message); @GET @Path("{notebookId}/paragraph/{paragraphId}") @ZeppelinApi Response getParagraph(@PathParam("notebookId") String notebookId,
                               @PathParam("paragraphId") String paragraphId); @POST @Path("{notebookId}/paragraph/{paragraphId}/move/{newIndex}") @ZeppelinApi Response moveParagraph(@PathParam("notebookId") String notebookId,
                                @PathParam("paragraphId") String paragraphId,
                                @PathParam("newIndex") String newIndex); @DELETE @Path("{notebookId}/paragraph/{paragraphId}") @ZeppelinApi Response deleteParagraph(@PathParam("notebookId") String notebookId,
                                  @PathParam("paragraphId") String paragraphId); @POST @Path("job/{notebookId}") @ZeppelinApi Response runNoteJobs(@PathParam("notebookId") String notebookId); @DELETE @Path("job/{notebookId}") @ZeppelinApi Response stopNoteJobs(@PathParam("notebookId") String notebookId); @GET @Path("job/{notebookId}") @ZeppelinApi Response getNoteJobStatus(@PathParam("notebookId") String notebookId); @POST @Path("job/{notebookId}/{paragraphId}") @ZeppelinApi Response runParagraph(@PathParam("notebookId") String notebookId, 
                               @PathParam("paragraphId") String paragraphId,
                               String message); @DELETE @Path("job/{notebookId}/{paragraphId}") @ZeppelinApi Response stopParagraph(@PathParam("notebookId") String notebookId, 
                                @PathParam("paragraphId") String paragraphId); @POST @Path("cron/{notebookId}") @ZeppelinApi Response registerCronJob(@PathParam("notebookId") String notebookId, String message); @DELETE @Path("cron/{notebookId}") @ZeppelinApi Response removeCronJob(@PathParam("notebookId") String notebookId); @GET @Path("cron/{notebookId}") @ZeppelinApi Response getCronJob(@PathParam("notebookId") String notebookId); @GET @Path("jobmanager/") @ZeppelinApi Response getJobListforNotebook(); @GET @Path("jobmanager/{lastUpdateUnixtime}/") @ZeppelinApi Response getUpdatedJobListforNotebook(
      @PathParam("lastUpdateUnixtime") long lastUpdateUnixTime); @GET @Path("search") @ZeppelinApi Response search(@QueryParam("q") String queryTerm);  }
@Test public void testPermissions() throws IOException { Note note1 = ZeppelinServer.notebook.createNote(null); String jsonRequest = "{\"readers\":[\"admin-team\"],\"owners\":[]," + "\"writers\":[]}"; PutMethod put = httpPut("/notebook/" + note1.getId() + "/permissions/", jsonRequest); LOG.info("testPermissions response\n" + put.getResponseBodyAsString()); assertThat("test update method:", put, isAllowed()); put.releaseConnection(); GetMethod get = httpGet("/notebook/" + note1.getId() + "/permissions/"); assertThat(get, isAllowed()); Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() { }.getType()); Map<String, Set<String>> authInfo = (Map<String, Set<String>>) resp.get("body"); assertEquals(authInfo.get("readers"), Lists.newArrayList("admin-team")); assertEquals(authInfo.get("owners"), Lists.newArrayList("anonymous")); assertEquals(authInfo.get("writers"), Lists.newArrayList("anonymous")); get.releaseConnection(); Note note2 = ZeppelinServer.notebook.createNote(null); jsonRequest = "{\"readers\":[],\"owners\":[]," + "\"writers\":[\"admin-team\"]}"; put = httpPut("/notebook/" + note2.getId() + "/permissions/", jsonRequest); assertThat("test update method:", put, isAllowed()); put.releaseConnection(); get = httpGet("/notebook/" + note2.getId() + "/permissions/"); assertThat(get, isAllowed()); resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() { }.getType()); authInfo = (Map<String, Set<String>>) resp.get("body"); assertEquals(authInfo.get("owners"), Lists.newArrayList("anonymous")); assertEquals(authInfo.get("writers"), Lists.newArrayList("admin-team")); get.releaseConnection(); jsonRequest = "{\"readers\":[],\"owners\":[],\"writers\":[]}"; put = httpPut("/notebook/" + note2.getId() + "/permissions/", jsonRequest); put.releaseConnection(); get = httpGet("/notebook/" + note2.getId() + "/permissions/"); assertThat(get, isAllowed()); resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() { }.getType()); authInfo = (Map<String, Set<String>>) resp.get("body"); assertEquals(authInfo.get("readers"), Lists.newArrayList()); assertEquals(authInfo.get("writers"), Lists.newArrayList()); assertEquals(authInfo.get("owners"), Lists.newArrayList()); get.releaseConnection(); ZeppelinServer.notebook.removeNote(note1.getId(), null); ZeppelinServer.notebook.removeNote(note2.getId(), null); }