use of org.apache.zeppelin.display.Input in project SSM by Intel-bigdata.
the class Note method addCloneParagraph.
/**
* Clone paragraph and add it to note.
*
* @param srcParagraph source paragraph
*/
void addCloneParagraph(Paragraph srcParagraph) {
// Keep paragraph original ID
final Paragraph newParagraph = new Paragraph(srcParagraph.getId(), this, this, factory, interpreterSettingManager);
Map<String, Object> config = new HashMap<>(srcParagraph.getConfig());
Map<String, Object> param = srcParagraph.settings.getParams();
LinkedHashMap<String, Input> form = srcParagraph.settings.getForms();
newParagraph.setConfig(config);
newParagraph.settings.setParams(param);
newParagraph.settings.setForms(form);
newParagraph.setText(srcParagraph.getText());
newParagraph.setTitle(srcParagraph.getTitle());
try {
Gson gson = new Gson();
String resultJson = gson.toJson(srcParagraph.getReturn());
InterpreterResult result = gson.fromJson(resultJson, InterpreterResult.class);
newParagraph.setReturn(result, null);
} catch (Exception e) {
// 'result' part of Note consists of exception, instead of actual interpreter results
logger.warn("Paragraph " + srcParagraph.getId() + " has a result with exception. " + e.getMessage());
}
synchronized (paragraphs) {
paragraphs.add(newParagraph);
}
if (noteEventListener != null) {
noteEventListener.onParagraphCreate(newParagraph);
}
}
use of org.apache.zeppelin.display.Input in project zeppelin by apache.
the class Note method addCloneParagraph.
/**
* Clone paragraph and add it to note.
*
* @param srcParagraph source paragraph
*/
void addCloneParagraph(Paragraph srcParagraph, AuthenticationInfo subject) {
// Keep paragraph original ID
Paragraph newParagraph = new Paragraph(srcParagraph.getId(), this, paragraphJobListener);
Map<String, Object> config = new HashMap<>(srcParagraph.getConfig());
Map<String, Object> param = srcParagraph.settings.getParams();
Map<String, Input> form = srcParagraph.settings.getForms();
LOGGER.debug("srcParagraph user: {}", srcParagraph.getUser());
newParagraph.setAuthenticationInfo(subject);
newParagraph.setConfig(config);
newParagraph.settings.setParams(param);
newParagraph.settings.setForms(form);
newParagraph.setText(srcParagraph.getText());
newParagraph.setTitle(srcParagraph.getTitle());
LOGGER.debug("newParagraph user: {}", newParagraph.getUser());
try {
String resultJson = GSON.toJson(srcParagraph.getReturn());
InterpreterResult result = InterpreterResult.fromJson(resultJson);
newParagraph.setReturn(result, null);
} catch (Exception e) {
// 'result' part of Note consists of exception, instead of actual interpreter results
LOGGER.warn("Paragraph {} has a result with exception. {}", srcParagraph.getId(), e.getMessage());
}
paragraphs.add(newParagraph);
fireParagraphCreateEvent(newParagraph);
}
use of org.apache.zeppelin.display.Input in project zeppelin by apache.
the class ZeppelinSparkClusterTest method testRNoteDynamicForms.
@Test
public void testRNoteDynamicForms() throws IOException {
assumeTrue("Hadoop version mismatch, skip test", isHadoopVersionMatch());
String noteId = null;
try {
noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous);
TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
Paragraph p1 = note.addNewParagraph(anonymous);
// create TextBox
p1.setText("%spark.r z.noteTextbox(\"name\", \"world\")");
note.run(p1.getId(), true);
assertEquals(Status.FINISHED, p1.getStatus());
Input input = p1.getNote().getNoteForms().get("name");
assertTrue(input instanceof TextBox);
TextBox inputTextBox = (TextBox) input;
assertEquals("name", inputTextBox.getDisplayName());
assertEquals("world", inputTextBox.getDefaultValue());
assertEquals("world", p1.getNote().getNoteParams().get("name"));
Paragraph p2 = note.addNewParagraph(anonymous);
p2.setText("%md hello $${name}");
note.run(p2.getId(), true);
assertEquals(Status.FINISHED, p2.getStatus());
assertTrue(p2.getReturn().toString(), p2.getReturn().toString().contains("hello world"));
return null;
});
} finally {
if (null != noteId) {
TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous);
}
}
}
use of org.apache.zeppelin.display.Input in project zeppelin by apache.
the class RemoteInterpreterTest method testConvertDynamicForms.
@Test
public void testConvertDynamicForms() throws InterpreterException {
GUI gui = new GUI();
OptionInput.ParamOption[] paramOptions = { new OptionInput.ParamOption("value1", "param1"), new OptionInput.ParamOption("value2", "param2") };
List<Object> defaultValues = new ArrayList<>();
defaultValues.add("default1");
defaultValues.add("default2");
gui.checkbox("checkbox_id", paramOptions, defaultValues);
gui.select("select_id", paramOptions, "default");
gui.textbox("textbox_id");
Map<String, Input> expected = new LinkedHashMap<>(gui.getForms());
Interpreter interpreter = interpreterSetting.getDefaultInterpreter("user1", note1Id);
InterpreterContext context = createDummyInterpreterContext();
interpreter.interpret("text", context);
assertArrayEquals(expected.values().toArray(), gui.getForms().values().toArray());
}
use of org.apache.zeppelin.display.Input in project SSM by Intel-bigdata.
the class ParagraphTest method should_extract_variable_from_angular_object_registry.
@Test
public void should_extract_variable_from_angular_object_registry() throws Exception {
// Given
final String noteId = "noteId";
final AngularObjectRegistry registry = mock(AngularObjectRegistry.class);
final Note note = mock(Note.class);
final Map<String, Input> inputs = new HashMap<>();
inputs.put("name", null);
inputs.put("age", null);
inputs.put("job", null);
final String scriptBody = "My name is ${name} and I am ${age=20} years old. " + "My occupation is ${ job = engineer | developer | artists}";
final Paragraph paragraph = new Paragraph(note, null, null, null);
final String paragraphId = paragraph.getId();
final AngularObject nameAO = AngularObjectBuilder.build("name", "DuyHai DOAN", noteId, paragraphId);
final AngularObject ageAO = AngularObjectBuilder.build("age", 34, noteId, null);
when(note.getId()).thenReturn(noteId);
when(registry.get("name", noteId, paragraphId)).thenReturn(nameAO);
when(registry.get("age", noteId, null)).thenReturn(ageAO);
final String expected = "My name is DuyHai DOAN and I am 34 years old. " + "My occupation is ${ job = engineer | developer | artists}";
// When
final String actual = paragraph.extractVariablesFromAngularRegistry(scriptBody, inputs, registry);
// Then
verify(registry).get("name", noteId, paragraphId);
verify(registry).get("age", noteId, null);
assertEquals(actual, expected);
}
Aggregations