Repository: zeppelin Updated Branches: refs/heads/master b9d6056b7 -> 1d3e94a43
ZEPPELIN-3162. Fixed Checkstyle issues in neo4j module ### What is this PR for? Fixed the Checkstyle errors and warnings in the neo4j module. ### What type of PR is it? Improvement ### Todos * [ ] - Task ### What is the Jira issue? * https://issues.apache.org/jira/browse/ZEPPELIN-3162 ### How should this be tested? * CI pass ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: Jan Hentschel <jan.hentsc...@ultratendency.com> Closes #2892 from HorizonNet/ZEPPELIN-3162 and squashes the following commits: d8c2f49 [Jan Hentschel] ZEPPELIN-3162. Reverted package-lock.json 2d628c9 [Jan Hentschel] Merge branch 'master' into ZEPPELIN-3162 cf95110 [Jan Hentschel] ZEPPELIN-3162. Incorporated review feedback 819a1a2 [Jan Hentschel] ZEPPELIN-3162. Fixed Checkstyle issues in neo4j module Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/1d3e94a4 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/1d3e94a4 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/1d3e94a4 Branch: refs/heads/master Commit: 1d3e94a43eb1930fe2e9816debe23fe9e721ba07 Parents: b9d6056 Author: Jan Hentschel <jan.hentsc...@ultratendency.com> Authored: Tue Mar 27 12:24:44 2018 +0200 Committer: Felix Cheung <felixche...@apache.org> Committed: Thu Mar 29 23:27:23 2018 -0700 ---------------------------------------------------------------------- neo4j/pom.xml | 7 ++ .../graph/neo4j/Neo4jConnectionManager.java | 26 +++-- .../graph/neo4j/Neo4jCypherInterpreter.java | 30 +++--- .../graph/neo4j/utils/Neo4jConversionUtils.java | 12 +-- .../graph/neo4j/Neo4jCypherInterpreterTest.java | 101 +++++++++++-------- 5 files changed, 99 insertions(+), 77 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1d3e94a4/neo4j/pom.xml ---------------------------------------------------------------------- diff --git a/neo4j/pom.xml b/neo4j/pom.xml index 2bf9e9a..906939c 100644 --- a/neo4j/pom.xml +++ b/neo4j/pom.xml @@ -138,6 +138,13 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <configuration> + <skip>false</skip> + </configuration> + </plugin> </plugins> </build> http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1d3e94a4/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jConnectionManager.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jConnectionManager.java b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jConnectionManager.java index 7cd504e..208d142 100644 --- a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jConnectionManager.java +++ b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jConnectionManager.java @@ -17,6 +17,17 @@ package org.apache.zeppelin.graph.neo4j; +import org.apache.commons.lang.StringUtils; +import org.neo4j.driver.v1.AuthToken; +import org.neo4j.driver.v1.AuthTokens; +import org.neo4j.driver.v1.Config; +import org.neo4j.driver.v1.Driver; +import org.neo4j.driver.v1.GraphDatabase; +import org.neo4j.driver.v1.Session; +import org.neo4j.driver.v1.StatementResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -25,19 +36,9 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.lang.StringUtils; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.resource.Resource; import org.apache.zeppelin.resource.ResourcePool; -import org.neo4j.driver.v1.AuthToken; -import org.neo4j.driver.v1.AuthTokens; -import org.neo4j.driver.v1.Config; -import org.neo4j.driver.v1.Driver; -import org.neo4j.driver.v1.GraphDatabase; -import org.neo4j.driver.v1.Session; -import org.neo4j.driver.v1.StatementResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Neo4j connection manager for Zeppelin. @@ -66,9 +67,7 @@ public class Neo4jConnectionManager { private final AuthToken authToken; /** - * - * Enum type for the AuthToken - * + * Enum type for the AuthToken. */ public enum Neo4jAuthType {NONE, BASIC} @@ -147,5 +146,4 @@ public class Neo4jConnectionManager { } return keys; } - } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1d3e94a4/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreter.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreter.java b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreter.java index a625522..bcb9d7b 100644 --- a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreter.java +++ b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreter.java @@ -17,6 +17,17 @@ package org.apache.zeppelin.graph.neo4j; +import org.apache.commons.lang.StringUtils; +import org.neo4j.driver.internal.types.InternalTypeSystem; +import org.neo4j.driver.internal.util.Iterables; +import org.neo4j.driver.v1.Record; +import org.neo4j.driver.v1.StatementResult; +import org.neo4j.driver.v1.Value; +import org.neo4j.driver.v1.types.Node; +import org.neo4j.driver.v1.types.Relationship; +import org.neo4j.driver.v1.types.TypeSystem; +import org.neo4j.driver.v1.util.Pair; + import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -27,7 +38,8 @@ import java.util.Map.Entry; import java.util.Properties; import java.util.Set; -import org.apache.commons.lang.StringUtils; +import com.fasterxml.jackson.databind.ObjectMapper; + import org.apache.zeppelin.graph.neo4j.utils.Neo4jConversionUtils; import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; @@ -36,17 +48,6 @@ import org.apache.zeppelin.interpreter.InterpreterResult.Code; import org.apache.zeppelin.interpreter.graph.GraphResult; import org.apache.zeppelin.scheduler.Scheduler; import org.apache.zeppelin.scheduler.SchedulerFactory; -import org.neo4j.driver.internal.types.InternalTypeSystem; -import org.neo4j.driver.internal.util.Iterables; -import org.neo4j.driver.v1.Record; -import org.neo4j.driver.v1.StatementResult; -import org.neo4j.driver.v1.Value; -import org.neo4j.driver.v1.types.Node; -import org.neo4j.driver.v1.types.Relationship; -import org.neo4j.driver.v1.types.TypeSystem; -import org.neo4j.driver.v1.util.Pair; - -import com.fasterxml.jackson.databind.ObjectMapper; /** * Neo4j interpreter for Zeppelin. @@ -205,7 +206,9 @@ public class Neo4jCypherInterpreter extends Interpreter { if (value instanceof Collection) { try { value = jsonMapper.writer().writeValueAsString(value); - } catch (Exception ignored) {} + } catch (Exception e) { + logger.debug("ignored exception: " + e.getMessage()); + } } } line.set(position, value == null ? null : value.toString()); @@ -270,5 +273,4 @@ public class Neo4jCypherInterpreter extends Interpreter { @Override public void cancel(InterpreterContext context) { } - } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1d3e94a4/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/utils/Neo4jConversionUtils.java ---------------------------------------------------------------------- diff --git a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/utils/Neo4jConversionUtils.java b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/utils/Neo4jConversionUtils.java index 4849401..571afa9 100644 --- a/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/utils/Neo4jConversionUtils.java +++ b/neo4j/src/main/java/org/apache/zeppelin/graph/neo4j/utils/Neo4jConversionUtils.java @@ -17,15 +17,15 @@ package org.apache.zeppelin.graph.neo4j.utils; +import org.neo4j.driver.v1.types.Node; +import org.neo4j.driver.v1.types.Relationship; + import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; -import org.neo4j.driver.v1.types.Node; -import org.neo4j.driver.v1.types.Relationship; - /** - * Neo4jConversionUtils + * Neo4jConversionUtils. */ public class Neo4jConversionUtils { private Neo4jConversionUtils() {} @@ -48,8 +48,7 @@ public class Neo4jConversionUtils { labels); } - public static org.apache.zeppelin.tabledata.Relationship - toZeppelinRelationship(Relationship r) { + public static org.apache.zeppelin.tabledata.Relationship toZeppelinRelationship(Relationship r) { return new org.apache.zeppelin.tabledata.Relationship(r.id(), r.asMap(), r.startNodeId(), r.endNodeId(), r.type()); } @@ -62,5 +61,4 @@ public class Neo4jConversionUtils { } return new String(color); } - } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1d3e94a4/neo4j/src/test/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreterTest.java ---------------------------------------------------------------------- diff --git a/neo4j/src/test/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreterTest.java b/neo4j/src/test/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreterTest.java index 9781504..d7c8b37 100644 --- a/neo4j/src/test/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreterTest.java +++ b/neo4j/src/test/java/org/apache/zeppelin/graph/neo4j/Neo4jCypherInterpreterTest.java @@ -18,13 +18,25 @@ package org.apache.zeppelin.graph.neo4j; import static org.junit.Assert.assertEquals; +import com.google.gson.Gson; + +import org.apache.commons.lang3.StringUtils; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.neo4j.harness.ServerControls; +import org.neo4j.harness.TestServerBuilders; + import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Properties; -import org.apache.commons.lang3.StringUtils; import org.apache.zeppelin.display.AngularObjectRegistry; import org.apache.zeppelin.display.GUI; import org.apache.zeppelin.graph.neo4j.Neo4jConnectionManager.Neo4jAuthType; @@ -37,17 +49,6 @@ import org.apache.zeppelin.interpreter.InterpreterResult.Code; import org.apache.zeppelin.interpreter.graph.GraphResult; import org.apache.zeppelin.resource.LocalResourcePool; import org.apache.zeppelin.user.AuthenticationInfo; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; -import org.neo4j.harness.ServerControls; -import org.neo4j.harness.TestServerBuilders; - -import com.google.gson.Gson; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class Neo4jCypherInterpreterTest { @@ -63,7 +64,8 @@ public class Neo4jCypherInterpreterTest { private static final String LABEL_PERSON = "Person"; private static final String REL_KNOWS = "KNOWS"; - private static final String CYPHER_FOREACH = "FOREACH (x in range(1,1000) | CREATE (:%s{name: \"name\" + x, age: %s}))"; + private static final String CYPHER_FOREACH = + "FOREACH (x in range(1,1000) | CREATE (:%s{name: \"name\" + x, age: %s}))"; private static final String CHPHER_UNWIND = "UNWIND range(1,1000) as x " + "MATCH (n), (m) WHERE id(n) = x AND id(m) = toInt(rand() * 1000) " + "CREATE (n)-[:%s]->(m)"; @@ -71,7 +73,7 @@ public class Neo4jCypherInterpreterTest { @BeforeClass public static void setUpNeo4jServer() throws Exception { server = TestServerBuilders.newInProcessBuilder() - .withConfig("dbms.security.auth_enabled","false") + .withConfig("dbms.security.auth_enabled", "false") .withFixture(String.format(CYPHER_FOREACH, LABEL_PERSON, "x % 10")) .withFixture(String.format(CHPHER_UNWIND, REL_KNOWS)) .newServer(); @@ -108,14 +110,17 @@ public class Neo4jCypherInterpreterTest { @Test public void testTableWithArray() { interpreter.open(); - InterpreterResult result = interpreter.interpret("return 'a' as colA, 'b' as colB, [1, 2, 3] as colC", context); + InterpreterResult result = interpreter.interpret( + "return 'a' as colA, 'b' as colB, [1, 2, 3] as colC", context); assertEquals(Code.SUCCESS, result.code()); final String tableResult = "colA\tcolB\tcolC\n\"a\"\t\"b\"\t[1,2,3]\n"; assertEquals(tableResult, result.toString().replace("%table ", StringUtils.EMPTY)); - result = interpreter.interpret("return 'a' as colA, 'b' as colB, [{key: \"value\"}, {key: 1}] as colC", context); + result = interpreter.interpret( + "return 'a' as colA, 'b' as colB, [{key: \"value\"}, {key: 1}] as colC", context); assertEquals(Code.SUCCESS, result.code()); - final String tableResultWithMap = "colA\tcolB\tcolC\n\"a\"\t\"b\"\t[{\"key\":\"value\"},{\"key\":1}]\n"; + final String tableResultWithMap = + "colA\tcolB\tcolC\n\"a\"\t\"b\"\t[{\"key\":\"value\"},{\"key\":1}]\n"; assertEquals(tableResultWithMap, result.toString().replace("%table ", StringUtils.EMPTY)); } @@ -131,8 +136,8 @@ public class Neo4jCypherInterpreterTest { public void testRenderTable() { interpreter.open(); InterpreterResult result = interpreter.interpret("MATCH (n:Person) " - + "WHERE n.name IN ['name1', 'name2', 'name3'] " - + "RETURN n.name AS name, n.age AS age", context); + + "WHERE n.name IN ['name1', 'name2', 'name3'] " + + "RETURN n.name AS name, n.age AS age", context); assertEquals(Code.SUCCESS, result.code()); final String tableResult = "name\tage\n\"name1\"\t1\n\"name2\"\t2\n\"name3\"\t3\n"; assertEquals(tableResult, result.toString().replace("%table ", StringUtils.EMPTY)); @@ -141,12 +146,14 @@ public class Neo4jCypherInterpreterTest { @Test public void testRenderMap() { interpreter.open(); - final String jsonQuery = "RETURN {key: \"value\", listKey: [{inner: \"Map1\"}, {inner: \"Map2\"}]} as object"; + final String jsonQuery = + "RETURN {key: \"value\", listKey: [{inner: \"Map1\"}, {inner: \"Map2\"}]} as object"; final String objectKey = "object.key"; final String objectListKey = "object.listKey"; InterpreterResult result = interpreter.interpret(jsonQuery, context); assertEquals(Code.SUCCESS, result.code()); - String[] rows = result.toString().replace("%table ", StringUtils.EMPTY).split(Neo4jCypherInterpreter.NEW_LINE); + String[] rows = result.toString().replace("%table ", StringUtils.EMPTY) + .split(Neo4jCypherInterpreter.NEW_LINE); assertEquals(rows.length, 2); List<String> header = Arrays.asList(rows[0].split(Neo4jCypherInterpreter.TAB)); assertEquals(header.contains(objectKey), true); @@ -154,14 +161,16 @@ public class Neo4jCypherInterpreterTest { List<String> row = Arrays.asList(rows[1].split(Neo4jCypherInterpreter.TAB)); assertEquals(row.size(), header.size()); assertEquals(row.get(header.indexOf(objectKey)), "value"); - assertEquals(row.get(header.indexOf(objectListKey)), "[{\"inner\":\"Map1\"},{\"inner\":\"Map2\"}]"); + assertEquals(row.get(header.indexOf(objectListKey)), + "[{\"inner\":\"Map1\"},{\"inner\":\"Map2\"}]"); final String query = "WITH [{key: \"value\", listKey: [{inner: \"Map1\"}, {inner: \"Map2\"}]}," - + "{key: \"value2\", listKey: [{inner: \"Map12\"}, {inner: \"Map22\"}]}] " - + "AS array UNWIND array AS object RETURN object"; + + "{key: \"value2\", listKey: [{inner: \"Map12\"}, {inner: \"Map22\"}]}] " + + "AS array UNWIND array AS object RETURN object"; result = interpreter.interpret(query, context); assertEquals(Code.SUCCESS, result.code()); - rows = result.toString().replace("%table ", StringUtils.EMPTY).split(Neo4jCypherInterpreter.NEW_LINE); + rows = result.toString().replace("%table ", StringUtils.EMPTY) + .split(Neo4jCypherInterpreter.NEW_LINE); assertEquals(rows.length, 3); header = Arrays.asList(rows[0].split(Neo4jCypherInterpreter.TAB)); assertEquals(header.contains(objectKey), true); @@ -169,18 +178,21 @@ public class Neo4jCypherInterpreterTest { row = Arrays.asList(rows[1].split(Neo4jCypherInterpreter.TAB)); assertEquals(row.size(), header.size()); assertEquals(row.get(header.indexOf(objectKey)), "value"); - assertEquals(row.get(header.indexOf(objectListKey)), "[{\"inner\":\"Map1\"},{\"inner\":\"Map2\"}]"); + assertEquals(row.get(header.indexOf(objectListKey)), + "[{\"inner\":\"Map1\"},{\"inner\":\"Map2\"}]"); row = Arrays.asList(rows[2].split(Neo4jCypherInterpreter.TAB)); assertEquals(row.size(), header.size()); assertEquals(row.get(header.indexOf(objectKey)), "value2"); - assertEquals(row.get(header.indexOf(objectListKey)), "[{\"inner\":\"Map12\"},{\"inner\":\"Map22\"}]"); + assertEquals(row.get(header.indexOf(objectListKey)), + "[{\"inner\":\"Map12\"},{\"inner\":\"Map22\"}]"); final String jsonListWithNullQuery = "WITH [{key: \"value\", listKey: null}," - + "{key: \"value2\", listKey: [{inner: \"Map1\"}, {inner: \"Map2\"}]}] " - + "AS array UNWIND array AS object RETURN object"; + + "{key: \"value2\", listKey: [{inner: \"Map1\"}, {inner: \"Map2\"}]}] " + + "AS array UNWIND array AS object RETURN object"; result = interpreter.interpret(jsonListWithNullQuery, context); assertEquals(Code.SUCCESS, result.code()); - rows = result.toString().replace("%table ", StringUtils.EMPTY).split(Neo4jCypherInterpreter.NEW_LINE); + rows = result.toString().replace("%table ", StringUtils.EMPTY) + .split(Neo4jCypherInterpreter.NEW_LINE); assertEquals(rows.length, 3); header = Arrays.asList(rows[0].split(Neo4jCypherInterpreter.TAB, -1)); assertEquals(header.contains(objectKey), true); @@ -193,14 +205,16 @@ public class Neo4jCypherInterpreterTest { row = Arrays.asList(rows[2].split(Neo4jCypherInterpreter.TAB, -1)); assertEquals(row.size(), header.size()); assertEquals(row.get(header.indexOf(objectKey)), "value2"); - assertEquals(row.get(header.indexOf(objectListKey)), "[{\"inner\":\"Map1\"},{\"inner\":\"Map2\"}]"); + assertEquals(row.get(header.indexOf(objectListKey)), + "[{\"inner\":\"Map1\"},{\"inner\":\"Map2\"}]"); final String jsonListWithoutListKeyQuery = "WITH [{key: \"value\"}," - + "{key: \"value2\", listKey: [{inner: \"Map1\"}, {inner: \"Map2\"}]}] " - + "AS array UNWIND array AS object RETURN object"; + + "{key: \"value2\", listKey: [{inner: \"Map1\"}, {inner: \"Map2\"}]}] " + + "AS array UNWIND array AS object RETURN object"; result = interpreter.interpret(jsonListWithoutListKeyQuery, context); assertEquals(Code.SUCCESS, result.code()); - rows = result.toString().replace("%table ", StringUtils.EMPTY).split(Neo4jCypherInterpreter.NEW_LINE); + rows = result.toString().replace("%table ", StringUtils.EMPTY) + .split(Neo4jCypherInterpreter.NEW_LINE); assertEquals(rows.length, 3); header = Arrays.asList(rows[0].split(Neo4jCypherInterpreter.TAB, -1)); assertEquals(header.contains(objectKey), true); @@ -212,14 +226,17 @@ public class Neo4jCypherInterpreterTest { row = Arrays.asList(rows[2].split(Neo4jCypherInterpreter.TAB, -1)); assertEquals(row.size(), header.size()); assertEquals(row.get(header.indexOf(objectKey)), "value2"); - assertEquals(row.get(header.indexOf(objectListKey)), "[{\"inner\":\"Map1\"},{\"inner\":\"Map2\"}]"); + assertEquals(row.get(header.indexOf(objectListKey)), + "[{\"inner\":\"Map1\"},{\"inner\":\"Map2\"}]"); } @Test public void testRenderNetwork() { interpreter.open(); - InterpreterResult result = interpreter.interpret("MATCH (n)-[r:KNOWS]-(m) RETURN n, r, m LIMIT 1", context); - GraphResult.Graph graph = gson.fromJson(result.toString().replace("%network ", StringUtils.EMPTY), GraphResult.Graph.class); + InterpreterResult result = interpreter.interpret( + "MATCH (n)-[r:KNOWS]-(m) RETURN n, r, m LIMIT 1", context); + GraphResult.Graph graph = gson.fromJson(result.toString().replace("%network ", + StringUtils.EMPTY), GraphResult.Graph.class); assertEquals(2, graph.getNodes().size()); assertEquals(true, graph.getNodes().iterator().next().getLabel().equals(LABEL_PERSON)); assertEquals(1, graph.getEdges().size()); @@ -234,17 +251,17 @@ public class Neo4jCypherInterpreterTest { @Test public void testFallingQuery() { interpreter.open(); - final String ERROR_MSG_EMPTY = ""; + final String errorMsgEmpty = ""; InterpreterResult result = interpreter.interpret(StringUtils.EMPTY, context); assertEquals(Code.SUCCESS, result.code()); - assertEquals(ERROR_MSG_EMPTY, result.toString()); + assertEquals(errorMsgEmpty, result.toString()); result = interpreter.interpret(null, context); assertEquals(Code.SUCCESS, result.code()); - assertEquals(ERROR_MSG_EMPTY, result.toString()); + assertEquals(errorMsgEmpty, result.toString()); - result = interpreter.interpret("MATCH (n:Person{name: }) RETURN n.name AS name, n.age AS age", context); + result = interpreter.interpret("MATCH (n:Person{name: }) RETURN n.name AS name, n.age AS age", + context); assertEquals(Code.ERROR, result.code()); } - }