From a2ff0a94aff77a832db12e26734a03f97b5e809a Mon Sep 17 00:00:00 2001 From: Craig Taverner Date: Wed, 18 Oct 2017 12:48:01 +0200 Subject: [PATCH] Fixed point type conversion for BaseToObjectValueWriter --- .../messaging/BoltResponseMessageWriter.java | 9 ++------ .../neo4j/bolt/v1/messaging/Neo4jPack.java | 8 +------ .../v1/messaging/util/MessageMatchers.java | 9 ++------ .../interpreted/QueryStateHelper.scala | 4 +++- .../javacompat/ValueToObjectSerializer.java | 17 ++++---------- .../cypher/internal/runtime/Geometry.scala | 10 ++++++++ .../impl/util/BaseToObjectValueWriter.java | 9 ++++---- .../builtinprocs/QueryStatusResult.java | 23 ++++++------------- .../auth/ProcedureInteractionTestBase.java | 9 ++------ 9 files changed, 37 insertions(+), 61 deletions(-) diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriter.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriter.java index 3a04a58b9483c..66b8bdd2fc05b 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriter.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/BoltResponseMessageWriter.java @@ -31,6 +31,7 @@ import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.values.AnyValue; import org.neo4j.values.utils.PrettyPrinter; +import org.neo4j.values.virtual.CoordinateReferenceSystem; import org.neo4j.values.virtual.MapValue; import static org.neo4j.bolt.v1.messaging.BoltResponseMessage.FAILURE; @@ -157,13 +158,7 @@ protected Relationship newRelationshipProxyById( long id ) } @Override - protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) - { - throw exception; - } - - @Override - protected Point newCartesianPoint( double x, double y, String name, int code, String href ) + protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate ) { throw exception; } diff --git a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/Neo4jPack.java b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/Neo4jPack.java index 5d7c9d5399245..066dc44129a9a 100644 --- a/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/Neo4jPack.java +++ b/community/bolt/src/main/java/org/neo4j/bolt/v1/messaging/Neo4jPack.java @@ -655,13 +655,7 @@ protected Relationship newRelationshipProxyById( long id ) } @Override - protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) - { - throw new UnsupportedOperationException( "Cannot unpack points" ); - } - - @Override - protected Point newCartesianPoint( double x, double y, String name, int code, String href ) + protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate ) { throw new UnsupportedOperationException( "Cannot unpack points" ); } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/util/MessageMatchers.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/util/MessageMatchers.java index 98c11e6d7a20a..ff8bd7ea6205f 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/util/MessageMatchers.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/messaging/util/MessageMatchers.java @@ -59,6 +59,7 @@ import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.impl.util.HexPrinter; import org.neo4j.values.AnyValue; +import org.neo4j.values.virtual.CoordinateReferenceSystem; import org.neo4j.values.virtual.MapValue; import static org.hamcrest.CoreMatchers.containsString; @@ -103,13 +104,7 @@ protected Relationship newRelationshipProxyById( long id ) } @Override - protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) - { - return null; - } - - @Override - protected Point newCartesianPoint( double x, double y, String name, int code, String href ) + protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate ) { return null; } diff --git a/community/cypher/interpreted-runtime/src/test/scala/org/neo4j/cypher/internal/runtime/interpreted/QueryStateHelper.scala b/community/cypher/interpreted-runtime/src/test/scala/org/neo4j/cypher/internal/runtime/interpreted/QueryStateHelper.scala index ed0205b2245e1..d619229a075bf 100644 --- a/community/cypher/interpreted-runtime/src/test/scala/org/neo4j/cypher/internal/runtime/interpreted/QueryStateHelper.scala +++ b/community/cypher/interpreted-runtime/src/test/scala/org/neo4j/cypher/internal/runtime/interpreted/QueryStateHelper.scala @@ -25,6 +25,7 @@ import org.mockito.{ArgumentMatchers, Mockito} import org.neo4j.cypher.internal.runtime.QueryContext import org.neo4j.cypher.internal.runtime.interpreted.TransactionBoundQueryContext.IndexSearchMonitor import org.neo4j.cypher.internal.runtime.interpreted.pipes.{ExternalCSVResource, NullPipeDecorator, PipeDecorator, QueryState} +import org.neo4j.graphdb.spatial.Point import org.neo4j.graphdb.{Node, Relationship} import org.neo4j.kernel.GraphDatabaseQueryService import org.neo4j.kernel.impl.coreapi.{InternalTransaction, PropertyContainerLocker} @@ -33,8 +34,8 @@ import org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo import org.neo4j.kernel.impl.util.BaseToObjectValueWriter import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors} import org.neo4j.values.AnyValue -import org.neo4j.values.virtual.MapValue import org.neo4j.values.virtual.VirtualValues.EMPTY_MAP +import org.neo4j.values.virtual.{CoordinateReferenceSystem, MapValue} import scala.collection.mutable @@ -87,6 +88,7 @@ object QueryStateHelper { val writer = new BaseToObjectValueWriter[RuntimeException] { override protected def newNodeProxyById(id: Long): Node = ??? override protected def newRelationshipProxyById(id: Long): Relationship = ??? + override protected def newPoint(crs: CoordinateReferenceSystem, coordinate: Array[Double]): Point = ??? } any.writeTo(writer) writer.value() diff --git a/community/cypher/runtime-util/src/main/java/org/neo4j/cypher/internal/javacompat/ValueToObjectSerializer.java b/community/cypher/runtime-util/src/main/java/org/neo4j/cypher/internal/javacompat/ValueToObjectSerializer.java index 85d5808c0bde5..d84ac38880b91 100644 --- a/community/cypher/runtime-util/src/main/java/org/neo4j/cypher/internal/javacompat/ValueToObjectSerializer.java +++ b/community/cypher/runtime-util/src/main/java/org/neo4j/cypher/internal/javacompat/ValueToObjectSerializer.java @@ -19,13 +19,13 @@ */ package org.neo4j.cypher.internal.javacompat; -import org.neo4j.cypher.internal.runtime.CartesianPoint; -import org.neo4j.cypher.internal.runtime.GeographicPoint; +import org.neo4j.cypher.internal.runtime.Points; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.spatial.Point; import org.neo4j.kernel.impl.core.NodeManager; import org.neo4j.kernel.impl.util.BaseToObjectValueWriter; +import org.neo4j.values.virtual.CoordinateReferenceSystem; public class ValueToObjectSerializer extends BaseToObjectValueWriter { @@ -49,16 +49,9 @@ protected Relationship newRelationshipProxyById( long id ) } @Override - protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) + protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate ) { - return new GeographicPoint( longitude, latitude, - new org.neo4j.cypher.internal.runtime.CRS( name, code, href ) ); - } - - @Override - protected Point newCartesianPoint( double x, double y, String name, int code, String href ) - { - return new CartesianPoint( x, y, - new org.neo4j.cypher.internal.runtime.CRS( name, code, href ) ); + // TODO: Is this necessary, perhaps PointValue is sufficient for use in Cypher-land + return Points.fromValue( crs, coordinate ); } } diff --git a/community/cypher/runtime-util/src/main/scala/org/neo4j/cypher/internal/runtime/Geometry.scala b/community/cypher/runtime-util/src/main/scala/org/neo4j/cypher/internal/runtime/Geometry.scala index 14a7fc759a476..7e1ca738e4539 100644 --- a/community/cypher/runtime-util/src/main/scala/org/neo4j/cypher/internal/runtime/Geometry.scala +++ b/community/cypher/runtime-util/src/main/scala/org/neo4j/cypher/internal/runtime/Geometry.scala @@ -24,6 +24,7 @@ import java.util.Collections import org.neo4j.cypher.internal.util.v3_4.{CypherTypeException, InvalidArgumentException} import org.neo4j.graphdb.spatial import org.neo4j.graphdb.spatial.{Coordinate, Point} +import org.neo4j.values.virtual.CoordinateReferenceSystem import scala.beans.BeanProperty @@ -82,6 +83,15 @@ object CRS { } object Points { + // TODO: Is this necessary, perhaps PointValue is sufficient for use in Cypher-land + def fromValue(crsValue: CoordinateReferenceSystem, coordinate: Array[Double]) = { + val crs = CRS.fromName(crsValue.name) + if (crs == CRS.WGS84) { + new GeographicPoint(coordinate(0), coordinate(1), crs) + } else { + new CartesianPoint(coordinate(0), coordinate(1), crs) + } + } private def safeToDouble(value: Any) = value match { case n: Number => n.doubleValue() case other => throw new CypherTypeException(other.getClass.getSimpleName + " is not a valid coordinate type.") diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/BaseToObjectValueWriter.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/BaseToObjectValueWriter.java index 0a368fe59e42f..2917c78e94a8a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/BaseToObjectValueWriter.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/BaseToObjectValueWriter.java @@ -69,6 +69,8 @@ public BaseToObjectValueWriter() protected abstract Relationship newRelationshipProxyById( long id ); + protected abstract Point newPoint( CoordinateReferenceSystem crs, double[] coordinate ); + public Object value() { assert stack.size() == 1; @@ -313,12 +315,11 @@ public String toString() } ); } - // TODO undefault and implement in subclasses? @Override - public void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) throws E + public final void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) throws E { - throw new UnsupportedOperationException(); - }; + writeValue( newPoint( crs, coordinate ) ); + } @Override public void writeNull() throws RuntimeException diff --git a/enterprise/kernel/src/main/java/org/neo4j/kernel/enterprise/builtinprocs/QueryStatusResult.java b/enterprise/kernel/src/main/java/org/neo4j/kernel/enterprise/builtinprocs/QueryStatusResult.java index c93f95fb671ab..baad2f0da5166 100644 --- a/enterprise/kernel/src/main/java/org/neo4j/kernel/enterprise/builtinprocs/QueryStatusResult.java +++ b/enterprise/kernel/src/main/java/org/neo4j/kernel/enterprise/builtinprocs/QueryStatusResult.java @@ -33,6 +33,7 @@ import org.neo4j.kernel.api.query.QuerySnapshot; import org.neo4j.kernel.impl.core.NodeManager; import org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo; +import org.neo4j.values.virtual.CoordinateReferenceSystem; import org.neo4j.kernel.impl.util.BaseToObjectValueWriter; import org.neo4j.values.virtual.MapValue; @@ -153,19 +154,9 @@ protected Relationship newRelationshipProxyById( long id ) } @Override - protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) - { - return point( longitude, latitude, name, code, href ); - } - - @Override - protected Point newCartesianPoint( double x, double y, String name, int code, String href ) - { - return point( x, y, name, code, href ); - } - - private Point point( double x, double y, String name, int code, String href ) + protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate ) { + //TODO: Is this required perhaps PointValue is sufficient without mapping to public? return new Point() { @Override @@ -177,7 +168,7 @@ public String getGeometryType() @Override public List getCoordinates() { - return singletonList( new Coordinate( x, y ) ); + return singletonList( new Coordinate( coordinate ) ); } @Override @@ -188,19 +179,19 @@ public CRS getCRS() @Override public int getCode() { - return code; + return crs.code; } @Override public String getType() { - return name; + return crs.name; } @Override public String getHref() { - return href; + return crs.href; } }; } diff --git a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/ProcedureInteractionTestBase.java b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/ProcedureInteractionTestBase.java index 0fd840f225b9f..732176b3e03c6 100644 --- a/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/ProcedureInteractionTestBase.java +++ b/enterprise/security/src/test/java/org/neo4j/server/security/enterprise/auth/ProcedureInteractionTestBase.java @@ -74,6 +74,7 @@ import org.neo4j.test.rule.concurrent.ThreadingRule; import org.neo4j.values.AnyValue; import org.neo4j.values.storable.TextValue; +import org.neo4j.values.virtual.CoordinateReferenceSystem; import org.neo4j.values.virtual.ListValue; import org.neo4j.values.virtual.MapValue; @@ -938,13 +939,7 @@ protected Relationship newRelationshipProxyById( long id ) } @Override - protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) - { - return null; - } - - @Override - protected Point newCartesianPoint( double x, double y, String name, int code, String href ) + protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate ) { return null; }