You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2021/10/08 02:18:10 UTC
[zeppelin] branch branch-0.10 updated: [ZEPPELIN-5547] Rename note
doesn't change the name field in file json
This is an automated email from the ASF dual-hosted git repository.
zjffdu pushed a commit to branch branch-0.10
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/branch-0.10 by this push:
new f51531a [ZEPPELIN-5547] Rename note doesn't change the name field in file json
f51531a is described below
commit f51531aba8838ef1e1f158731ab9232a24bb9a75
Author: Jeff Zhang <zj...@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 <zj...@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
(cherry picked from commit a0c3e5da00c0a8c51db527b27f6ec673d450ef14)
Signed-off-by: Jeff Zhang <zj...@apache.org>
---
.../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();