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

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


The following commit(s) were added to refs/heads/master by this push:
     new a0c3e5d  [ZEPPELIN-5547] Rename note doesn't change the name field in 
file json
a0c3e5d is described below

commit a0c3e5da00c0a8c51db527b27f6ec673d450ef14
Author: Jeff Zhang <zjf...@apache.org>
AuthorDate: Mon Oct 4 20:36:11 2021 +0800

    [ZEPPELIN-5547] Rename note doesn't change the name field in file json
    
    ### What is this PR for?
    
    This PR would update note file if the file name is changed. Otherwise the 
`name` field in note json would be inconsistent with note file name. They would 
become consistent when user do save note operation afterwards.
    
    ### What type of PR is it?
    [Bug Fix ]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-5547
    
    ### 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 #4240 from zjffdu/ZEPPELIN-5547 and squashes the following commits:
    
    84eb8cd336 [Jeff Zhang] address comments
    92e0c73bf0 [Jeff Zhang] [ZEPPELIN-5547] Rename note doesn't change the name 
field in file json
---
 .../org/apache/zeppelin/notebook/NoteManager.java  |  7 +++++++
 .../org/apache/zeppelin/notebook/NotebookTest.java | 22 ++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git 
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java 
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java
index 484ee09..85e318d 100644
--- 
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java
+++ 
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java
@@ -246,6 +246,13 @@ public class NoteManager {
 
     // update notebookrepo
     this.notebookRepo.move(noteId, notePath, newNotePath, subject);
+
+    // save note if note name is changed, because we need to update the note 
field in note json.
+    String oldNoteName = getNoteName(notePath);
+    String newNoteName = getNoteName(newNotePath);
+    if (!StringUtils.equalsIgnoreCase(oldNoteName, newNoteName)) {
+      this.notebookRepo.save(noteNode.note, subject);
+    }
   }
 
   public void moveFolder(String folderPath,
diff --git 
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java 
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
index 1f5fb70..63a9d4d 100644
--- 
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
+++ 
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.zeppelin.notebook;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.zeppelin.conf.ZeppelinConfiguration;
 import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
 import org.apache.zeppelin.display.AngularObjectRegistry;
@@ -49,6 +50,7 @@ import org.slf4j.LoggerFactory;
 import org.eclipse.aether.RepositoryException;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -1582,6 +1584,26 @@ public class NotebookTest extends 
AbstractInterpreterTest implements ParagraphJo
     }
   }
 
+  @Test
+  public void testMoveNote() throws InterruptedException, IOException {
+    Note note = null;
+    try {
+      note = notebook.createNote("note1", anonymous);
+      assertEquals("note1", note.getName());
+      assertEquals("/note1", note.getPath());
+      notebook.moveNote(note.getId(), "/tmp/note2", anonymous);
+
+      // read note json file to check the name field is updated
+      File noteFile = new File(conf.getNotebookDir() + "/" + 
notebookRepo.buildNoteFileName(note));
+      String noteJson = IOUtils.toString(new FileInputStream(noteFile));
+      assertTrue(noteJson, noteJson.contains("note2"));
+    } finally {
+      if (note != null) {
+        notebook.removeNote(note, anonymous);
+      }
+    }
+  }
+
   private void delete(File file) {
     if (file.isFile()) {
       file.delete();

Reply via email to