Search in sources :

Example 31 with Paragraph

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();
}
Also used : Note(org.apache.zeppelin.notebook.Note) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 32 with Paragraph

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;
}
Also used : Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 33 with Paragraph

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();
}
Also used : Note(org.apache.zeppelin.notebook.Note) HeliumPackage(org.apache.zeppelin.helium.HeliumPackage) JsonResponse(org.apache.zeppelin.server.JsonResponse) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 34 with Paragraph

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();
}
Also used : Note(org.apache.zeppelin.notebook.Note) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi)

Example 35 with Paragraph

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()));
        }
    }
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Aggregations

Paragraph (org.apache.zeppelin.notebook.Paragraph)75 Note (org.apache.zeppelin.notebook.Note)69 Test (org.junit.Test)40 Map (java.util.Map)30 TypeToken (com.google.gson.reflect.TypeToken)12 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)12 Path (javax.ws.rs.Path)11 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)11 PostMethod (org.apache.commons.httpclient.methods.PostMethod)9 Message (org.apache.zeppelin.notebook.socket.Message)9 Notebook (org.apache.zeppelin.notebook.Notebook)7 GetMethod (org.apache.commons.httpclient.methods.GetMethod)6 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)6 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)5 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 JsonObject (com.google.gson.JsonObject)4 IOException (java.io.IOException)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4