mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Merge branch 'master' into notebook-search
Conflicts: zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
This commit is contained in:
commit
c7ae983c3d
8 changed files with 129 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
|||
---
|
||||
---
|
||||
layout: page
|
||||
title: "Dynamic Form"
|
||||
description: ""
|
||||
|
|
|
|||
|
|
@ -92,8 +92,26 @@ limitations under the License.
|
|||
<td> 500 </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> sample JSON input </td>
|
||||
<td><pre>{"name": "name of new notebook"}</pre></td>
|
||||
<td> sample JSON input (without paragraphs) </td>
|
||||
<td><pre>{ "name": "name of new notebook" }</pre></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> sample JSON input (with initial paragraphs) </td>
|
||||
<td><pre>
|
||||
{
|
||||
"name": "name of new notebook",
|
||||
"paragraphs": [
|
||||
{
|
||||
"title": "paragraph title1",
|
||||
"text": "paragraph text1"
|
||||
},
|
||||
{
|
||||
"title": "paragraph title2",
|
||||
"text": "paragraph text2"
|
||||
}
|
||||
]
|
||||
}
|
||||
</pre></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> sample JSON response </td>
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import org.apache.zeppelin.notebook.Paragraph;
|
|||
import org.apache.zeppelin.rest.message.CronRequest;
|
||||
import org.apache.zeppelin.rest.message.InterpreterSettingListForNoteBind;
|
||||
import org.apache.zeppelin.rest.message.NewNotebookRequest;
|
||||
import org.apache.zeppelin.rest.message.NewParagraphRequest;
|
||||
import org.apache.zeppelin.search.SearchService;
|
||||
import org.apache.zeppelin.server.JsonResponse;
|
||||
import org.apache.zeppelin.socket.NotebookServer;
|
||||
|
|
@ -145,7 +146,15 @@ public class NotebookRestApi {
|
|||
NewNotebookRequest request = gson.fromJson(message,
|
||||
NewNotebookRequest.class);
|
||||
Note note = notebook.createNote();
|
||||
note.addParagraph(); // it's an empty note. so add one paragraph
|
||||
List<NewParagraphRequest> initialParagraphs = request.getParagraphs();
|
||||
if (initialParagraphs != null) {
|
||||
for (NewParagraphRequest paragraphRequest : initialParagraphs) {
|
||||
Paragraph p = note.addParagraph();
|
||||
p.setTitle(paragraphRequest.getTitle());
|
||||
p.setText(paragraphRequest.getText());
|
||||
}
|
||||
}
|
||||
note.addParagraph(); // add one paragraph to the last
|
||||
String noteName = request.getName();
|
||||
if (noteName.isEmpty()) {
|
||||
noteName = "Note " + note.getId();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.apache.zeppelin.rest.message;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.zeppelin.interpreter.InterpreterOption;
|
||||
|
|
@ -27,6 +28,7 @@ import org.apache.zeppelin.interpreter.InterpreterOption;
|
|||
*/
|
||||
public class NewNotebookRequest {
|
||||
String name;
|
||||
List<NewParagraphRequest> paragraphs;
|
||||
|
||||
public NewNotebookRequest (){
|
||||
|
||||
|
|
@ -35,4 +37,8 @@ public class NewNotebookRequest {
|
|||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<NewParagraphRequest> getParagraphs() {
|
||||
return paragraphs;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.zeppelin.rest.message;
|
||||
|
||||
/**
|
||||
* NewParagraphRequest rest api request message
|
||||
*
|
||||
* It is used for NewNotebookRequest with initial paragraphs
|
||||
*
|
||||
*/
|
||||
public class NewParagraphRequest {
|
||||
String title;
|
||||
String text;
|
||||
|
||||
public NewParagraphRequest() {
|
||||
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.zeppelin.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -26,10 +27,12 @@ import org.apache.commons.httpclient.methods.DeleteMethod;
|
|||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.PutMethod;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.zeppelin.conf.ZeppelinConfiguration;
|
||||
import org.apache.zeppelin.interpreter.InterpreterSetting;
|
||||
import org.apache.zeppelin.notebook.Note;
|
||||
import org.apache.zeppelin.notebook.Paragraph;
|
||||
import org.apache.zeppelin.rest.message.NewParagraphRequest;
|
||||
import org.apache.zeppelin.scheduler.Job.Status;
|
||||
import org.apache.zeppelin.server.ZeppelinServer;
|
||||
import org.junit.AfterClass;
|
||||
|
|
@ -201,6 +204,46 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
testNotebookCreate("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotebookCreateWithParagraphs() throws IOException {
|
||||
// Call Create Notebook REST API
|
||||
String noteName = "test";
|
||||
String jsonRequest = "{\"name\":\"" + noteName + "\", \"paragraphs\": [" +
|
||||
"{\"title\": \"title1\", \"text\": \"text1\"}," +
|
||||
"{\"title\": \"title2\", \"text\": \"text2\"}" +
|
||||
"]}";
|
||||
PostMethod post = httpPost("/notebook/", jsonRequest);
|
||||
LOG.info("testNotebookCreate \n" + post.getResponseBodyAsString());
|
||||
assertThat("test notebook create method:", post, isCreated());
|
||||
|
||||
Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
|
||||
}.getType());
|
||||
|
||||
String newNotebookId = (String) resp.get("body");
|
||||
LOG.info("newNotebookId:=" + newNotebookId);
|
||||
Note newNote = ZeppelinServer.notebook.getNote(newNotebookId);
|
||||
assertNotNull("Can not find new note by id", newNote);
|
||||
// This is partial test as newNote is in memory but is not persistent
|
||||
String newNoteName = newNote.getName();
|
||||
LOG.info("new note name is: " + newNoteName);
|
||||
String expectedNoteName = noteName;
|
||||
if (noteName.isEmpty()) {
|
||||
expectedNoteName = "Note " + newNotebookId;
|
||||
}
|
||||
assertEquals("compare note name", expectedNoteName, newNoteName);
|
||||
assertEquals("initial paragraph check failed", 3, newNote.getParagraphs().size());
|
||||
for (Paragraph p : newNote.getParagraphs()) {
|
||||
if (StringUtils.isEmpty(p.getText())) {
|
||||
continue;
|
||||
}
|
||||
assertTrue("paragraph title check failed", p.getTitle().startsWith("title"));
|
||||
assertTrue("paragraph text check failed", p.getText().startsWith("text"));
|
||||
}
|
||||
// cleanup
|
||||
ZeppelinServer.notebook.removeNote(newNotebookId);
|
||||
post.releaseConnection();
|
||||
}
|
||||
|
||||
private void testNotebookCreate(String noteName) throws IOException {
|
||||
// Call Create Notebook REST API
|
||||
String jsonRequest = "{\"name\":\"" + noteName + "\"}";
|
||||
|
|
|
|||
|
|
@ -318,6 +318,14 @@ This part should be removed when new version of bootstrap handles this issue.
|
|||
float: left;
|
||||
}
|
||||
|
||||
.modal-backdrop {
|
||||
z-index: 10002 !important;
|
||||
}
|
||||
|
||||
.modal-dialog, .modal {
|
||||
z-index: 10003 !important;
|
||||
}
|
||||
|
||||
#noteImportModal .modal-body {
|
||||
min-height: 420px;
|
||||
overflow: hidden;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@
|
|||
*/
|
||||
|
||||
.paragraph .text {
|
||||
white-space: pre;
|
||||
display: block;
|
||||
unicode-bidi: embed;
|
||||
display: block !important;
|
||||
|
|
|
|||
Loading…
Reference in a new issue