Skip to content

Commit c7ae983

Browse files
committed
Merge branch 'master' into notebook-search
Conflicts: zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
2 parents ded9c3b + d69a30e commit c7ae983

File tree

8 files changed

+129
-5
lines changed

8 files changed

+129
-5
lines changed

docs/manual/dynamicform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
layout: page
33
title: "Dynamic Form"
44
description: ""

docs/rest-api/rest-notebook.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,26 @@ limitations under the License.
9292
<td> 500 </td>
9393
</tr>
9494
<tr>
95-
<td> sample JSON input </td>
96-
<td><pre>{"name": "name of new notebook"}</pre></td>
95+
<td> sample JSON input (without paragraphs) </td>
96+
<td><pre>{ "name": "name of new notebook" }</pre></td>
97+
</tr>
98+
<tr>
99+
<td> sample JSON input (with initial paragraphs) </td>
100+
<td><pre>
101+
{
102+
"name": "name of new notebook",
103+
"paragraphs": [
104+
{
105+
"title": "paragraph title1",
106+
"text": "paragraph text1"
107+
},
108+
{
109+
"title": "paragraph title2",
110+
"text": "paragraph text2"
111+
}
112+
]
113+
}
114+
</pre></td>
97115
</tr>
98116
<tr>
99117
<td> sample JSON response </td>

zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.zeppelin.rest.message.CronRequest;
4141
import org.apache.zeppelin.rest.message.InterpreterSettingListForNoteBind;
4242
import org.apache.zeppelin.rest.message.NewNotebookRequest;
43+
import org.apache.zeppelin.rest.message.NewParagraphRequest;
4344
import org.apache.zeppelin.search.SearchService;
4445
import org.apache.zeppelin.server.JsonResponse;
4546
import org.apache.zeppelin.socket.NotebookServer;
@@ -145,7 +146,15 @@ public Response createNote(String message) throws IOException {
145146
NewNotebookRequest request = gson.fromJson(message,
146147
NewNotebookRequest.class);
147148
Note note = notebook.createNote();
148-
note.addParagraph(); // it's an empty note. so add one paragraph
149+
List<NewParagraphRequest> initialParagraphs = request.getParagraphs();
150+
if (initialParagraphs != null) {
151+
for (NewParagraphRequest paragraphRequest : initialParagraphs) {
152+
Paragraph p = note.addParagraph();
153+
p.setTitle(paragraphRequest.getTitle());
154+
p.setText(paragraphRequest.getText());
155+
}
156+
}
157+
note.addParagraph(); // add one paragraph to the last
149158
String noteName = request.getName();
150159
if (noteName.isEmpty()) {
151160
noteName = "Note " + note.getId();

zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/NewNotebookRequest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.zeppelin.rest.message;
1919

20+
import java.util.List;
2021
import java.util.Map;
2122

2223
import org.apache.zeppelin.interpreter.InterpreterOption;
@@ -27,6 +28,7 @@
2728
*/
2829
public class NewNotebookRequest {
2930
String name;
31+
List<NewParagraphRequest> paragraphs;
3032

3133
public NewNotebookRequest (){
3234

@@ -35,4 +37,8 @@ public NewNotebookRequest (){
3537
public String getName() {
3638
return name;
3739
}
40+
41+
public List<NewParagraphRequest> getParagraphs() {
42+
return paragraphs;
43+
}
3844
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.zeppelin.rest.message;
19+
20+
/**
21+
* NewParagraphRequest rest api request message
22+
*
23+
* It is used for NewNotebookRequest with initial paragraphs
24+
*
25+
*/
26+
public class NewParagraphRequest {
27+
String title;
28+
String text;
29+
30+
public NewParagraphRequest() {
31+
32+
}
33+
34+
public String getTitle() {
35+
return title;
36+
}
37+
38+
public String getText() {
39+
return text;
40+
}
41+
}

zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.zeppelin.rest;
1919

2020
import java.io.IOException;
21+
import java.util.ArrayList;
2122
import java.util.HashMap;
2223
import java.util.List;
2324
import java.util.Map;
@@ -26,10 +27,12 @@
2627
import org.apache.commons.httpclient.methods.GetMethod;
2728
import org.apache.commons.httpclient.methods.PostMethod;
2829
import org.apache.commons.httpclient.methods.PutMethod;
30+
import org.apache.commons.lang3.StringUtils;
2931
import org.apache.zeppelin.conf.ZeppelinConfiguration;
3032
import org.apache.zeppelin.interpreter.InterpreterSetting;
3133
import org.apache.zeppelin.notebook.Note;
3234
import org.apache.zeppelin.notebook.Paragraph;
35+
import org.apache.zeppelin.rest.message.NewParagraphRequest;
3336
import org.apache.zeppelin.scheduler.Job.Status;
3437
import org.apache.zeppelin.server.ZeppelinServer;
3538
import org.junit.AfterClass;
@@ -201,6 +204,46 @@ public void testNotebookCreateNoName() throws IOException {
201204
testNotebookCreate("");
202205
}
203206

207+
@Test
208+
public void testNotebookCreateWithParagraphs() throws IOException {
209+
// Call Create Notebook REST API
210+
String noteName = "test";
211+
String jsonRequest = "{\"name\":\"" + noteName + "\", \"paragraphs\": [" +
212+
"{\"title\": \"title1\", \"text\": \"text1\"}," +
213+
"{\"title\": \"title2\", \"text\": \"text2\"}" +
214+
"]}";
215+
PostMethod post = httpPost("/notebook/", jsonRequest);
216+
LOG.info("testNotebookCreate \n" + post.getResponseBodyAsString());
217+
assertThat("test notebook create method:", post, isCreated());
218+
219+
Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
220+
}.getType());
221+
222+
String newNotebookId = (String) resp.get("body");
223+
LOG.info("newNotebookId:=" + newNotebookId);
224+
Note newNote = ZeppelinServer.notebook.getNote(newNotebookId);
225+
assertNotNull("Can not find new note by id", newNote);
226+
// This is partial test as newNote is in memory but is not persistent
227+
String newNoteName = newNote.getName();
228+
LOG.info("new note name is: " + newNoteName);
229+
String expectedNoteName = noteName;
230+
if (noteName.isEmpty()) {
231+
expectedNoteName = "Note " + newNotebookId;
232+
}
233+
assertEquals("compare note name", expectedNoteName, newNoteName);
234+
assertEquals("initial paragraph check failed", 3, newNote.getParagraphs().size());
235+
for (Paragraph p : newNote.getParagraphs()) {
236+
if (StringUtils.isEmpty(p.getText())) {
237+
continue;
238+
}
239+
assertTrue("paragraph title check failed", p.getTitle().startsWith("title"));
240+
assertTrue("paragraph text check failed", p.getText().startsWith("text"));
241+
}
242+
// cleanup
243+
ZeppelinServer.notebook.removeNote(newNotebookId);
244+
post.releaseConnection();
245+
}
246+
204247
private void testNotebookCreate(String noteName) throws IOException {
205248
// Call Create Notebook REST API
206249
String jsonRequest = "{\"name\":\"" + noteName + "\"}";

zeppelin-web/src/app/home/home.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,14 @@ This part should be removed when new version of bootstrap handles this issue.
318318
float: left;
319319
}
320320

321+
.modal-backdrop {
322+
z-index: 10002 !important;
323+
}
324+
325+
.modal-dialog, .modal {
326+
z-index: 10003 !important;
327+
}
328+
321329
#noteImportModal .modal-body {
322330
min-height: 420px;
323331
overflow: hidden;

zeppelin-web/src/app/notebook/paragraph/paragraph.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
*/
3333

3434
.paragraph .text {
35-
white-space: pre;
3635
display: block;
3736
unicode-bidi: embed;
3837
display: block !important;

0 commit comments

Comments
 (0)