mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Add rename method to rest api
This commit is contained in:
parent
eb88b0b9e7
commit
ad880ed31d
3 changed files with 107 additions and 4 deletions
|
|
@ -339,6 +339,42 @@ Notebooks REST API supports the following operations: List, Create, Get, Delete,
|
|||
</tr>
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
### Rename a note
|
||||
<table class="table-configuration">
|
||||
<col width="200">
|
||||
<tr>
|
||||
<td>Description</td>
|
||||
<td>This ```PUT``` method renames a note by the given id using the given name.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>URL</td>
|
||||
<td>```http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/rename```</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Success code</td>
|
||||
<td>200</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Bad Request code</td>
|
||||
<td>400</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> Fail code</td>
|
||||
<td> 500 </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> sample JSON input </td>
|
||||
<td><pre>{"name": "new name of a note"}</pre></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> sample JSON response </td>
|
||||
<td><pre>{"status":"OK"}</pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<br />
|
||||
### Export a note
|
||||
<table class="table-configuration">
|
||||
|
|
|
|||
|
|
@ -45,10 +45,7 @@ import org.apache.zeppelin.notebook.Paragraph;
|
|||
import org.apache.zeppelin.rest.exception.BadRequestException;
|
||||
import org.apache.zeppelin.rest.exception.NotFoundException;
|
||||
import org.apache.zeppelin.rest.exception.ForbiddenException;
|
||||
import org.apache.zeppelin.rest.message.CronRequest;
|
||||
import org.apache.zeppelin.rest.message.NewNoteRequest;
|
||||
import org.apache.zeppelin.rest.message.NewParagraphRequest;
|
||||
import org.apache.zeppelin.rest.message.RunParagraphWithParametersRequest;
|
||||
import org.apache.zeppelin.rest.message.*;
|
||||
import org.apache.zeppelin.search.SearchService;
|
||||
import org.apache.zeppelin.server.JsonResponse;
|
||||
import org.apache.zeppelin.socket.NotebookServer;
|
||||
|
|
@ -413,6 +410,37 @@ public class NotebookRestApi {
|
|||
return new JsonResponse<>(Status.OK, "", newNote.getId()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename note REST API
|
||||
*
|
||||
* @param message - JSON containing new name
|
||||
* @return JSON with status.OK
|
||||
* @throws IOException
|
||||
*/
|
||||
@PUT
|
||||
@Path("{noteId}/rename")
|
||||
@ZeppelinApi
|
||||
public Response renameNote(@PathParam("noteId") String noteId, String message) throws IOException {
|
||||
LOG.info("rename note by JSON {}", message);
|
||||
RenameNoteRequest request = gson.fromJson(message, RenameNoteRequest.class);
|
||||
AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
|
||||
|
||||
checkIfUserCanWrite(noteId, "Insufficient privileges you cannot rename this note");
|
||||
Note note = notebook.getNote(noteId);
|
||||
checkIfNoteIsNotNull(note);
|
||||
|
||||
String newName = request.getName();
|
||||
if (newName.isEmpty()) {
|
||||
LOG.warn("Trying to rename notebook {} with empty name parameter", noteId);
|
||||
throw new BadRequestException("name can not be empty");
|
||||
}
|
||||
note.setName(newName);
|
||||
|
||||
notebookServer.broadcastNote(note);
|
||||
notebookServer.broadcastNoteList(subject, SecurityUtils.getRoles());
|
||||
return new JsonResponse(Status.OK, "").build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert paragraph REST API
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.zeppelin.interpreter.InterpreterOption;
|
||||
|
||||
/**
|
||||
* RenameNoteRequest rest api request message
|
||||
*
|
||||
*/
|
||||
public class RenameNoteRequest {
|
||||
String name;
|
||||
|
||||
public RenameNoteRequest (){
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue