NotebookRestApi extends AbstractRestApi { @POST @Path("{noteId}") @ZeppelinApi public Response cloneNote(@PathParam("noteId") String noteId, String message) throws IOException, IllegalArgumentException { LOGGER.info("Clone note by JSON {}", message); checkIfUserCanWrite(noteId, "Insufficient privileges you cannot clone this note"); NewNoteRequest request = NewNoteRequest.fromJson(message); String newNoteName = null; if (request != null) { newNoteName = request.getName(); } AuthenticationInfo subject = new AuthenticationInfo(authenticationService.getPrincipal()); Note newNote = notebookService.cloneNote(noteId, newNoteName, getServiceContext(), new RestServiceCallback<Note>() { @Override public void onSuccess(Note newNote, ServiceContext context) throws IOException { notebookServer.broadcastNote(newNote); notebookServer.broadcastNoteList(subject, context.getUserAndRoles()); } }); return new JsonResponse<>(Status.OK, "", newNote.getId()).build(); } @Inject  NotebookRestApi(
      Notebook notebook,
      NotebookServer notebookServer,
      NotebookService notebookService,
      SearchService search,
      AuthorizationService authorizationService,
      ZeppelinConfiguration zConf,
      AuthenticationService authenticationService,
      JobManagerService jobManagerService,
      SchedulerService schedulerService); @GET @Path("{noteId}/permissions") @ZeppelinApi Response getNotePermissions(@PathParam("noteId") String noteId); @PUT @Path("{noteId}/permissions") @ZeppelinApi Response putNotePermissions(@PathParam("noteId") String noteId, String req); @GET @ZeppelinApi Response getNoteList(); @GET @Path("{noteId}") @ZeppelinApi Response getNote(@PathParam("noteId") String noteId); @GET @Path("export/{noteId}") @ZeppelinApi Response exportNote(@PathParam("noteId") String noteId); @POST @Path("import") @ZeppelinApi Response importNote(@QueryParam("notePath") String notePath, String noteJson); @POST @ZeppelinApi Response createNote(String message); @DELETE @Path("{noteId}") @ZeppelinApi Response deleteNote(@PathParam("noteId") String noteId); @POST @Path("{noteId}") @ZeppelinApi Response cloneNote(@PathParam("noteId") String noteId, String message); @PUT @Path("{noteId}/rename") @ZeppelinApi Response renameNote(@PathParam("noteId") String noteId,
                             String message); @POST @Path("{noteId}/paragraph") @ZeppelinApi Response insertParagraph(@PathParam("noteId") String noteId, String message); @GET @Path("{noteId}/paragraph/{paragraphId}") @ZeppelinApi Response getParagraph(@PathParam("noteId") String noteId,
                               @PathParam("paragraphId") String paragraphId); @PUT @Path("{noteId}/paragraph/{paragraphId}") @ZeppelinApi Response updateParagraph(@PathParam("noteId") String noteId,
                                  @PathParam("paragraphId") String paragraphId,
                                  String message); @PUT @Path("{noteId}/paragraph/{paragraphId}/config") @ZeppelinApi Response updateParagraphConfig(@PathParam("noteId") String noteId,
                                        @PathParam("paragraphId") String paragraphId,
                                        String message); @POST @Path("{noteId}/paragraph/{paragraphId}/move/{newIndex}") @ZeppelinApi Response moveParagraph(@PathParam("noteId") String noteId,
                                @PathParam("paragraphId") String paragraphId,
                                @PathParam("newIndex") String newIndex); @DELETE @Path("{noteId}/paragraph/{paragraphId}") @ZeppelinApi Response deleteParagraph(@PathParam("noteId") String noteId,
                                  @PathParam("paragraphId") String paragraphId); @POST @Path("{noteId}/paragraph/next") Response nextSessionParagraph(@PathParam("noteId") String noteId,
                                       @QueryParam("maxParagraph") int maxParagraph); @PUT @Path("{noteId}/clear") @ZeppelinApi Response clearAllParagraphOutput(@PathParam("noteId") String noteId); @POST @Path("job/{noteId}") @ZeppelinApi Response runNoteJobs(@PathParam("noteId") String noteId,
                              @QueryParam("blocking") Boolean blocking,
                              @QueryParam("isolated") Boolean isolated,
                              String message); @DELETE @Path("job/{noteId}") @ZeppelinApi Response stopNoteJobs(@PathParam("noteId") String noteId); @GET @Path("job/{noteId}") @ZeppelinApi Response getNoteJobStatus(@PathParam("noteId") String noteId); @GET @Path("job/{noteId}/{paragraphId}") @ZeppelinApi Response getNoteParagraphJobStatus(@PathParam("noteId") String noteId,
                                            @PathParam("paragraphId") String paragraphId); @POST @Path("job/{noteId}/{paragraphId}") @ZeppelinApi Response runParagraph(@PathParam("noteId") String noteId,
                               @PathParam("paragraphId") String paragraphId,
                               @QueryParam("sessionId") String sessionId,
                               String message); @POST @Path("run/{noteId}/{paragraphId}") @ZeppelinApi Response runParagraphSynchronously(@PathParam("noteId") String noteId,
                                            @PathParam("paragraphId") String paragraphId,
                                            @QueryParam("sessionId") String sessionId,
                                            String message); @DELETE @Path("job/{noteId}/{paragraphId}") @ZeppelinApi Response cancelParagraph(@PathParam("noteId") String noteId,
                                  @PathParam("paragraphId") String paragraphId); @POST @Path("cron/{noteId}") @ZeppelinApi Response registerCronJob(@PathParam("noteId") String noteId, String message); @DELETE @Path("cron/{noteId}") @ZeppelinApi Response removeCronJob(@PathParam("noteId") String noteId); @GET @Path("cron/{noteId}") @ZeppelinApi Response getCronJob(@PathParam("noteId") String noteId); @GET @Path("jobmanager/") @ZeppelinApi Response getJobListforNote(); @GET @Path("jobmanager/{lastUpdateUnixtime}/") @ZeppelinApi Response getUpdatedJobListforNote(@PathParam("lastUpdateUnixtime") long lastUpdateUnixTime); @GET @Path("search") @ZeppelinApi Response search(@QueryParam("q") String queryTerm);  }
@Test public void testCloneNote() throws IOException { LOG.info("Running testCloneNote"); Note note1 = null; String clonedNoteId = null; try { note1 = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); PostMethod post = httpPost("/notebook/" + note1.getId(), ""); LOG.info("testCloneNote response\n" + post.getResponseBodyAsString()); assertThat(post, isAllowed()); Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {}.getType()); clonedNoteId = (String) resp.get("body"); post.releaseConnection(); GetMethod get = httpGet("/notebook/" + clonedNoteId); assertThat(get, isAllowed()); Map<String, Object> resp2 = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {}.getType()); Map<String, Object> resp2Body = (Map<String, Object>) resp2.get("body"); get.releaseConnection(); } finally { if (null != note1) { TestUtils.getInstance(Notebook.class).removeNote(note1, anonymous); } if (null != clonedNoteId) { Note clonedNote = TestUtils.getInstance(Notebook.class).getNote(clonedNoteId); if (clonedNote != null) { TestUtils.getInstance(Notebook.class).removeNote(clonedNote, anonymous); } } } }