This is an automated email from the ASF dual-hosted git repository.

zjffdu pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/branch-0.9 by this push:
     new 85e37da  [ZEPPELIN-5288]. Add rest api to reload note
85e37da is described below

commit 85e37da3038b486c5c05a712b37a79c28cd267ec
Author: Jeff Zhang <zjf...@apache.org>
AuthorDate: Fri Apr 2 16:19:28 2021 +0800

    [ZEPPELIN-5288]. Add rest api to reload note
    
    ### What is this PR for?
    
    Add simple rest api to reload note, Unit test is added.
    
    ### What type of PR is it?
    [ Improvement]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    *https://issues.apache.org/jira/browse/ZEPPELIN-5288
    
    ### How should this be tested?
    * CI pass
    
    ### Screenshots (if appropriate)
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: Jeff Zhang <zjf...@apache.org>
    
    Closes #4079 from zjffdu/ZEPPELIN-5288 and squashes the following commits:
    
    1ee165850 [Jeff Zhang] address comment
    83dac3954 [Jeff Zhang] [ZEPPELIN-5288]. Add rest api to reload note
    
    (cherry picked from commit 034154206ce66b73a7439f7a7ed4102130ffd1ba)
    Signed-off-by: Jeff Zhang <zjf...@apache.org>
---
 .../org/apache/zeppelin/rest/NotebookRestApi.java  |  6 ++--
 .../apache/zeppelin/rest/NotebookRestApiTest.java  | 33 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git 
a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java 
b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
index caddc20..62bb374 100644
--- 
a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
+++ 
b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
@@ -327,15 +327,17 @@ public class NotebookRestApi extends AbstractRestApi {
    * Get note of this specified noteId.
    *
    * @param noteId
+   * @param reload
    * @return
    * @throws IOException
    */
   @GET
   @Path("{noteId}")
   @ZeppelinApi
-  public Response getNote(@PathParam("noteId") String noteId) throws 
IOException {
+  public Response getNote(@PathParam("noteId") String noteId,
+                          @QueryParam("reload") boolean reload) throws 
IOException {
     Note note =
-            notebookService.getNote(noteId, getServiceContext(), new 
RestServiceCallback());
+            notebookService.getNote(noteId, reload, getServiceContext(), new 
RestServiceCallback());
     return new JsonResponse<>(Status.OK, "", note).build();
   }
 
diff --git 
a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
 
b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
index 60f8643..7e57435 100644
--- 
a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
+++ 
b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
@@ -79,6 +79,39 @@ public class NotebookRestApiTest extends AbstractTestRestApi 
{
   }
 
   @Test
+  public void testGetReloadNote() throws IOException {
+    LOG.info("Running testGetNote");
+    Note note1 = null;
+    try {
+      note1 = TestUtils.getInstance(Notebook.class).createNote("note1", 
anonymous);
+      note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
+      TestUtils.getInstance(Notebook.class).saveNote(note1, anonymous);
+      CloseableHttpResponse get = httpGet("/notebook/" + note1.getId());
+      assertThat(get, isAllowed());
+      Map<String, Object> resp = 
gson.fromJson(EntityUtils.toString(get.getEntity(), StandardCharsets.UTF_8),
+              new TypeToken<Map<String, Object>>() {}.getType());
+      Map<String, Object> noteObject = (Map<String, Object>) resp.get("body");
+      assertEquals(1, ((List)noteObject.get("paragraphs")).size());
+
+      // add one new paragraph, but don't save it and reload it again
+      note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
+
+      get = httpGet("/notebook/" + note1.getId() + "?reload=true");
+      assertThat(get, isAllowed());
+      resp = gson.fromJson(EntityUtils.toString(get.getEntity(), 
StandardCharsets.UTF_8),
+              new TypeToken<Map<String, Object>>() {}.getType());
+      noteObject = (Map<String, Object>) resp.get("body");
+      assertEquals(1, ((List)noteObject.get("paragraphs")).size());
+      get.close();
+    } finally {
+      // cleanup
+      if (null != note1) {
+        TestUtils.getInstance(Notebook.class).removeNote(note1, anonymous);
+      }
+    }
+  }
+
+  @Test
   public void testGetNoteParagraphJobStatus() throws IOException {
     LOG.info("Running testGetNoteParagraphJobStatus");
     Note note1 = null;

Reply via email to