Repository: zeppelin
Updated Branches:
  refs/heads/master 1a79b51d5 -> 30f60248c


[FIX] fix converter forms to json

### What is this PR for?
Fix converter for forms

### What type of PR is it?
[Bug Fix]

### How should this be tested?
jdbc
1. `select '${checkbox:name=1|2,first|second}'`

### Screenshots (if appropriate)
before
![before](https://user-images.githubusercontent.com/25951039/31577235-44433782-b124-11e7-8479-85ec5395c3a0.png)

after
![after](https://user-images.githubusercontent.com/25951039/31577234-441a8a58-b124-11e7-81fc-902ca4847fcb.png)

### Questions:
* Does the licenses files need update? no
* Is there breaking changes for older versions? no
* Does this needs documentation? no

Author: tinkoff-dwh <[email protected]>

Closes #2623 from tinkoff-dwh/forms-fix and squashes the following commits:

fdb6cfe8 [tinkoff-dwh] [FIX] checkstyle
08cf9213 [tinkoff-dwh] [FIX] checkstyle
b8415507 [tinkoff-dwh] [FIX] refactoring of context converter. add test to 
check converter of contexts.
17ec2dbc [tinkoff-dwh] [FIX] fix converter forms to json


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/30f60248
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/30f60248
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/30f60248

Branch: refs/heads/master
Commit: 30f60248cf634d3eb044512450a72f1784d17a9b
Parents: 1a79b51
Author: tinkoff-dwh <[email protected]>
Authored: Sun Oct 15 14:13:28 2017 +0500
Committer: Jongyoul Lee <[email protected]>
Committed: Fri Oct 27 00:11:22 2017 +0900

----------------------------------------------------------------------
 .../java/org/apache/zeppelin/display/Input.java |  8 +++++-
 .../interpreter/remote/RemoteInterpreter.java   |  2 +-
 .../remote/RemoteInterpreterTest.java           | 29 ++++++++++++++++++--
 3 files changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/30f60248/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/Input.java
----------------------------------------------------------------------
diff --git 
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/Input.java 
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/Input.java
index f713f4a..8a2cd93 100644
--- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/Input.java
+++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/Input.java
@@ -107,7 +107,13 @@ public class Input<T> implements Serializable {
     if (displayName != null ? !displayName.equals(input.displayName) : 
input.displayName != null) {
       return false;
     }
-    if (defaultValue != null ?
+    if (defaultValue instanceof Object[]) {
+      if (defaultValue != null ?
+          !Arrays.equals((Object[]) defaultValue, (Object[]) 
input.defaultValue)
+          : input.defaultValue != null) {
+        return false;
+      }
+    } else if (defaultValue != null ?
         !defaultValue.equals(input.defaultValue) : input.defaultValue != null) 
{
       return false;
     }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/30f60248/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java
----------------------------------------------------------------------
diff --git 
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java
 
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java
index b479799..338210d 100644
--- 
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java
+++ 
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java
@@ -391,7 +391,7 @@ public class RemoteInterpreter extends Interpreter {
   private RemoteInterpreterContext convert(InterpreterContext ic) {
     return new RemoteInterpreterContext(ic.getNoteId(), ic.getParagraphId(), 
ic.getReplName(),
         ic.getParagraphTitle(), ic.getParagraphText(), 
gson.toJson(ic.getAuthenticationInfo()),
-        gson.toJson(ic.getConfig()), gson.toJson(ic.getGui()), 
gson.toJson(ic.getRunners()));
+        gson.toJson(ic.getConfig()), ic.getGui().toJson(), 
gson.toJson(ic.getRunners()));
   }
 
   private InterpreterResult convert(RemoteInterpreterResult result) {

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/30f60248/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
----------------------------------------------------------------------
diff --git 
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
 
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
index 74bde89..c268c81 100644
--- 
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
+++ 
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
@@ -20,6 +20,8 @@ package org.apache.zeppelin.interpreter.remote;
 import org.apache.thrift.transport.TTransportException;
 import org.apache.zeppelin.display.AngularObjectRegistry;
 import org.apache.zeppelin.display.GUI;
+import org.apache.zeppelin.display.Input;
+import org.apache.zeppelin.display.ui.OptionInput;
 import org.apache.zeppelin.interpreter.*;
 import org.apache.zeppelin.interpreter.InterpreterResult.Code;
 import 
org.apache.zeppelin.interpreter.remote.mock.GetAngularObjectSizeInterpreter;
@@ -32,11 +34,11 @@ import org.junit.Test;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Properties;
+import java.util.Map;
 
 import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
 
 public class RemoteInterpreterTest {
 
@@ -413,4 +415,27 @@ public class RemoteInterpreterTest {
     assertEquals("null", interpreter1.interpret("getProperty property_2", 
context1).message().get(0).getData());
   }
 
+  @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", defaultValues, paramOptions);
+    gui.select("select_id", "default", paramOptions);
+    gui.textbox("textbox_id");
+    Map<String, Input> expected = new LinkedHashMap<>(gui.getForms());
+    Interpreter interpreter = 
interpreterSetting.getDefaultInterpreter("user1", "note1");
+    InterpreterContext context = new InterpreterContext("noteId", 
"paragraphId", "repl", null,
+        null, AuthenticationInfo.ANONYMOUS, new HashMap<String, Object>(), gui,
+        null, null, new ArrayList<InterpreterContextRunner>(), null);
+
+    interpreter.interpret("text", context);
+    assertArrayEquals(expected.values().toArray(), 
gui.getForms().values().toArray());
+  }
+
 }

Reply via email to