use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class LuceneSearchTest method canIndexAndReIndex.
@Test
public void canIndexAndReIndex() throws IOException {
//given
Note note1 = newNoteWithParagraph("Notebook1", "test");
Note note2 = newNoteWithParagraphs("Notebook2", "not test", "not test at all");
noteSearchService.addIndexDocs(Arrays.asList(note1, note2));
//when
Paragraph p2 = note2.getLastParagraph();
p2.setText("test indeed");
noteSearchService.updateIndexDoc(note2);
//then
List<Map<String, String>> results = noteSearchService.query("all");
assertThat(results).isEmpty();
results = noteSearchService.query("indeed");
assertThat(results).isNotEmpty();
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class LuceneSearchTest method addParagraphWithTextAndTitle.
private Paragraph addParagraphWithTextAndTitle(Note note, String text, String title) {
Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
p.setText(text);
p.setTitle(title);
return p;
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class HeliumRestApi method suggest.
@POST
@Path("load/{noteId}/{paragraphId}")
public Response suggest(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId, String heliumPackage) {
Note note = notebook.getNote(noteId);
if (note == null) {
return new JsonResponse(Response.Status.NOT_FOUND, "Note " + noteId + " not found").build();
}
Paragraph paragraph = note.getParagraph(paragraphId);
if (paragraph == null) {
return new JsonResponse(Response.Status.NOT_FOUND, "Paragraph " + paragraphId + " not found").build();
}
HeliumPackage pkg = gson.fromJson(heliumPackage, HeliumPackage.class);
String appId = helium.getApplicationFactory().loadAndRun(pkg, paragraph);
return new JsonResponse(Response.Status.OK, "", appId).build();
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookRestApi method stopParagraph.
/**
* Stop(delete) paragraph job REST API
*
* @param noteId ID of Note
* @param paragraphId ID of Paragraph
* @return JSON with status.OK
* @throws IOException, IllegalArgumentException
*/
@DELETE
@Path("job/{noteId}/{paragraphId}")
@ZeppelinApi
public Response stopParagraph(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId) throws IOException, IllegalArgumentException {
LOG.info("stop paragraph job {} ", noteId);
Note note = notebook.getNote(noteId);
checkIfNoteIsNotNull(note);
checkIfUserCanWrite(noteId, "Insufficient privileges you cannot stop paragraph");
Paragraph p = note.getParagraph(paragraphId);
checkIfParagraphIsNotNull(p);
p.abort();
return new JsonResponse<>(Status.OK).build();
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookServer method removeParagraph.
private void removeParagraph(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
final String paragraphId = (String) fromMessage.get("id");
if (paragraphId == null) {
return;
}
String noteId = getOpenNoteId(conn);
if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "write")) {
return;
}
/** We dont want to remove the last paragraph */
final Note note = notebook.getNote(noteId);
if (!note.isLastParagraph(paragraphId)) {
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
Paragraph para = note.removeParagraph(subject.getUser(), paragraphId);
note.persist(subject);
if (para != null) {
broadcast(note.getId(), new Message(OP.PARAGRAPH_REMOVED).put("id", para.getId()));
}
}
}
Aggregations