diff --git a/docs/rest-api/rest-notebook.md b/docs/rest-api/rest-notebook.md
index 3c94268e707..a1e8de61fac 100644
--- a/docs/rest-api/rest-notebook.md
+++ b/docs/rest-api/rest-notebook.md
@@ -33,7 +33,7 @@ limitations under the License.
### Notebook REST API list
- Notebooks REST API supports the following operations: List, Create, Get, Delete, Clone, Run as detailed in the following table
+ Notebooks REST API supports the following operations: List, Create, Get, Delete, Clone, Run, Export, Import as detailed in the following table
@@ -773,3 +773,112 @@ limitations under the License.
+
+
+
+
+
+ | Export notebook |
+ |
+
+
+ | Description |
+ This ```GET``` method exports a notebook by the given id and gernerates a JSON
+ |
+
+
+ | URL |
+ ```http://[zeppelin-server]:[zeppelin-port]/api/notebook/export/[notebookId]``` |
+
+
+ | Success code |
+ 201 |
+
+
+ | Fail code |
+ 500 |
+
+ sample JSON response |
+ {
+ "paragraphs": [
+ {
+ "text": "%md This is my new paragraph in my new note",
+ "dateUpdated": "Jan 8, 2016 4:49:38 PM",
+ "config": {
+ "enabled": true
+ },
+ "settings": {
+ "params": {},
+ "forms": {}
+ },
+ "jobName": "paragraph_1452300578795_1196072540",
+ "id": "20160108-164938_1685162144",
+ "dateCreated": "Jan 8, 2016 4:49:38 PM",
+ "status": "READY",
+ "progressUpdateIntervalMs": 500
+ }
+ ],
+ "name": "source note for export",
+ "id": "2B82H3RR1",
+ "angularObjects": {},
+ "config": {},
+ "info": {}
+} |
+
+
+
+
+
+
+ | Export notebook |
+ |
+
+
+ | Description |
+ This ```POST``` method imports a notebook from the notebook JSON input
+ |
+
+
+ | URL |
+ ```http://[zeppelin-server]:[zeppelin-port]/api/notebook/import``` |
+
+
+ | Success code |
+ 201 |
+
+
+ | Fail code |
+ 500 |
+
+ sample JSON input |
+ {
+ "paragraphs": [
+ {
+ "text": "%md This is my new paragraph in my new note",
+ "dateUpdated": "Jan 8, 2016 4:49:38 PM",
+ "config": {
+ "enabled": true
+ },
+ "settings": {
+ "params": {},
+ "forms": {}
+ },
+ "jobName": "paragraph_1452300578795_1196072540",
+ "id": "20160108-164938_1685162144",
+ "dateCreated": "Jan 8, 2016 4:49:38 PM",
+ "status": "READY",
+ "progressUpdateIntervalMs": 500
+ }
+ ],
+ "name": "source note for export",
+ "id": "2B82H3RR1",
+ "angularObjects": {},
+ "config": {},
+ "info": {}
+} |
+
+ | sample JSON response |
+ "status": "CREATED","message": "","body": "2AZPHY918"} |
+
+
+
\ No newline at end of file
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 7871da87e74..486e5b122c7 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
@@ -52,7 +52,9 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
-
+import com.google.gson.GsonBuilder;
+import com.google.gson.stream.JsonReader;
+import java.io.StringReader;
/**
* Rest api endpoint for the noteBook.
*/
@@ -146,6 +148,34 @@ public Response getNotebook(@PathParam("notebookId") String notebookId) throws I
return new JsonResponse<>(Status.OK, "", note).build();
}
+ /**
+ * export note REST API
+ *
+ * @param
+ * @return note JSON with status.OK
+ * @throws IOException
+ */
+ @GET
+ @Path("export/{id}")
+ public Response exportNoteBook(@PathParam("id") String noteId) throws IOException {
+ String exportJson = notebook.exportNote(noteId);
+ return new JsonResponse(Status.OK, "", exportJson).build();
+ }
+
+ /**
+ * import new note REST API
+ *
+ * @param req - notebook Json
+ * @return JSON with new note ID
+ * @throws IOException
+ */
+ @POST
+ @Path("import")
+ public Response importNotebook(String req) throws IOException {
+ Note newNote = notebook.importNote(req, null);
+ return new JsonResponse<>(Status.CREATED, "", newNote.getId()).build();
+ }
+
/**
* Create new note REST API
* @param message - JSON with new note name
diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
index 64698fcdfd4..11fa7f1b9fe 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
@@ -494,56 +494,15 @@ private void cloneNote(NotebookSocket conn, Notebook notebook, Message fromMessa
protected Note importNote(NotebookSocket conn, Notebook notebook, Message fromMessage)
throws IOException {
-
- Note note = notebook.createNote();
+ Note note = null;
if (fromMessage != null) {
String noteName = (String) ((Map) fromMessage.get("notebook")).get("name");
- if (noteName == null || noteName.isEmpty()) {
- noteName = "Note " + note.getId();
- }
- note.setName(noteName);
- ArrayList