Yes a more robust solution would be to cast to a Number:

    return ((Number)relationship.getProperty( costpropertyName
)).doubleValue();

I'm assuming that's what you meant in the first place, no?

2011/6/18 Jim Webber <[email protected]>

> Hi Josh,
>
> I'm just wiring up a bunch of code that implements REST paging, and then
> I'll codify these tests and sort it out.
>
> Jim
>
> On 18 Jun 2011, at 01:17, Josh Adell wrote:
>
> > Jim,
> > The best I can do as far as a failing test is this series of curl
> > calls.  I create 2 nodes, then connect them with a relationship that
> > has a property called "distance".  When I ask for paths without
> > specifying the algorithm, I get back the path with the relationship.
> > When I specify the algorithm as "dijkstra" with a cost property of
> > "distance", I get back a 400 Bad Request with a stack trace.
> >
> > Now interestingly, if I create the relationship with a distance of
> > 2.0, it works.  Unfortunately, PHP's json_encode method turns a double
> > 2.0 into an integer 2.
> >
> > My original thought was to make the DoubleEvaluator class cast the
> > Integer cost property value to a basic double before wrapping it in a
> > Double object.
> >
> > Here is the series of commands:
> >
> > ===== SHELL
> >
> > $ curl -i -HAccept:application/json -HContent-Type:application/json -X
> > POST -d '{"name":"A"}' http://localhost:7474/db/data/node
> > HTTP/1.1 201 Created
> > Content-Length: 996
> > Location: http://localhost:7474/db/data/node/73
> > Content-Encoding: UTF-8
> > Content-Type: application/json
> > Access-Control-Allow-Origin: *
> > Server: Jetty(6.1.25)
> >
> > {
> >  "outgoing_relationships" :
> > "http://localhost:7474/db/data/node/73/relationships/out";,
> >  "data" : {
> >    "name" : "A"
> >  },
> >  "traverse" : "
> http://localhost:7474/db/data/node/73/traverse/{returnType}";,
> >  "all_typed_relationships" :
> > "http://localhost:7474/db/data/node/73/relationships/all/{-list|&|types}
> ",
> >  "property" : "http://localhost:7474/db/data/node/73/properties/{key}";,
> >  "self" : "http://localhost:7474/db/data/node/73";,
> >  "properties" : "http://localhost:7474/db/data/node/73/properties";,
> >  "outgoing_typed_relationships" :
> > "http://localhost:7474/db/data/node/73/relationships/out/{-list|&|types}
> ",
> >  "incoming_relationships" :
> > "http://localhost:7474/db/data/node/73/relationships/in";,
> >  "extensions" : {
> >  },
> >  "create_relationship" : "
> http://localhost:7474/db/data/node/73/relationships";,
> >  "all_relationships" :
> > "http://localhost:7474/db/data/node/73/relationships/all";,
> >  "incoming_typed_relationships" :
> > "http://localhost:7474/db/data/node/73/relationships/in/{-list|&|types}"
> > }
> >
> > $ curl -i -HAccept:application/json -HContent-Type:application/json -X
> > POST -d '{"name":"B"}' http://localhost:7474/db/data/node
> > HTTP/1.1 201 Created
> > Content-Length: 996
> > Location: http://localhost:7474/db/data/node/74
> > Content-Encoding: UTF-8
> > Content-Type: application/json
> > Access-Control-Allow-Origin: *
> > Server: Jetty(6.1.25)
> >
> > {
> >  "outgoing_relationships" :
> > "http://localhost:7474/db/data/node/74/relationships/out";,
> >  "data" : {
> >    "name" : "B"
> >  },
> >  "traverse" : "
> http://localhost:7474/db/data/node/74/traverse/{returnType}";,
> >  "all_typed_relationships" :
> > "http://localhost:7474/db/data/node/74/relationships/all/{-list|&|types}
> ",
> >  "property" : "http://localhost:7474/db/data/node/74/properties/{key}";,
> >  "self" : "http://localhost:7474/db/data/node/74";,
> >  "properties" : "http://localhost:7474/db/data/node/74/properties";,
> >  "outgoing_typed_relationships" :
> > "http://localhost:7474/db/data/node/74/relationships/out/{-list|&|types}
> ",
> >  "incoming_relationships" :
> > "http://localhost:7474/db/data/node/74/relationships/in";,
> >  "extensions" : {
> >  },
> >  "create_relationship" : "
> http://localhost:7474/db/data/node/74/relationships";,
> >  "all_relationships" :
> > "http://localhost:7474/db/data/node/74/relationships/all";,
> >  "incoming_typed_relationships" :
> > "http://localhost:7474/db/data/node/74/relationships/in/{-list|&|types}"
> > }
> >
> > $ curl -i -HAccept:application/json -HContent-Type:application/json -X
> > POST -d '{"to":"http://localhost:7474/db/data/node/74
> ","type":"GO","data":{"name":"AB","distance":2}}'
> > http://localhost:7474/db/data/node/73/relationships
> > HTTP/1.1 201 Created
> > Content-Length: 421
> > Location: http://localhost:7474/db/data/relationship/64
> > Content-Encoding: UTF-8
> > Content-Type: application/json
> > Access-Control-Allow-Origin: *
> > Server: Jetty(6.1.25)
> >
> > {
> >  "start" : "http://localhost:7474/db/data/node/73";,
> >  "data" : {
> >    "distance" : 2,
> >    "name" : "AB"
> >  },
> >  "self" : "http://localhost:7474/db/data/relationship/64";,
> >  "property" : "
> http://localhost:7474/db/data/relationship/64/properties/{key}";,
> >  "properties" : "
> http://localhost:7474/db/data/relationship/64/properties";,
> >  "type" : "GO",
> >  "extensions" : {
> >  },
> >  "end" : "http://localhost:7474/db/data/node/74";
> > }
> >
> > #####  This succeeds
> > $ curl -i -HAccept:application/json -HContent-Type:application/json -X
> > POST -d '{"to":"http://localhost:7474/db/data/node/74","type":"GO"}'
> > http://localhost:7474/db/data/node/73/paths
> > HTTP/1.1 200 OK
> > Content-Length: 297
> > Content-Encoding: UTF-8
> > Content-Type: application/json
> > Access-Control-Allow-Origin: *
> > Server: Jetty(6.1.25)
> >
> > [ {
> >  "start" : "http://localhost:7474/db/data/node/73";,
> >  "nodes" : [ "http://localhost:7474/db/data/node/73";,
> > "http://localhost:7474/db/data/node/74"; ],
> >  "length" : 1,
> >  "relationships" : [ "http://localhost:7474/db/data/relationship/64"; ],
> >  "end" : "http://localhost:7474/db/data/node/74";
> > } ]
> >
> >
> > ##### This fails
> > $ curl -i -HAccept:application/json -HContent-Type:application/json -X
> > POST -d '{"to":"http://localhost:7474/db/data/node/74
> ","type":"GO","algorithm":"dijkstra","cost
> > property":"distance"}' http://localhost:7474/db/data/node/73/paths
> > HTTP/1.1 400 Bad Request
> > Content-Length: 4579
> > Content-Encoding: UTF-8
> > Content-Type: application/json
> > Access-Control-Allow-Origin: *
> > Server: Jetty(6.1.25)
> >
> > {
> >  "message" : "java.lang.Integer cannot be cast to java.lang.Double",
> >  "exception" : "java.lang.ClassCastException: java.lang.Integer
> > cannot be cast to java.lang.Double",
> >  "stacktrace" : [
> >
> "org.neo4j.graphalgo.impl.util.DoubleEvaluator.getCost(DoubleEvaluator.java:38)",
> >
> "org.neo4j.graphalgo.impl.util.DoubleEvaluator.getCost(DoubleEvaluator.java:26)",
> >
> "org.neo4j.graphalgo.impl.path.Dijkstra$SelectorFactory.calculateValue(Dijkstra.java:100)",
> >
> "org.neo4j.graphalgo.impl.path.Dijkstra$SelectorFactory.calculateValue(Dijkstra.java:88)",
> >
> "org.neo4j.graphalgo.impl.util.BestFirstSelectorFactory$BestFirstSelector.next(BestFirstSelectorFactory.java:66)",
> >
> "org.neo4j.kernel.impl.traversal.TraverserImpl$TraverserIterator.fetchNextOrNull(TraverserImpl.java:127)",
> >
> "org.neo4j.kernel.impl.traversal.TraverserImpl$TraverserIterator.fetchNextOrNull(TraverserImpl.java:94)",
> >
> "org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:55)",
> >
> "org.neo4j.graphalgo.impl.util.StopAfterWeightIterator.fetchNextOrNull(StopAfterWeightIterator.java:45)",
> >
> "org.neo4j.graphalgo.impl.util.StopAfterWeightIterator.fetchNextOrNull(StopAfterWeightIterator.java:29)",
> >
> "org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:55)",
> >
> "org.neo4j.helpers.collection.IteratorWrapper.hasNext(IteratorWrapper.java:42)",
> >
> "org.neo4j.server.rest.repr.ListRepresentation.serialize(ListRepresentation.java:58)",
> >
> "org.neo4j.server.rest.repr.ListRepresentation.serialize(ListRepresentation.java:51)",
> > "org.neo4j.server.rest.repr.OutputFormat.format(OutputFormat.java:118)",
> > "org.neo4j.server.rest.repr.OutputFormat.response(OutputFormat.java:95)",
> > "org.neo4j.server.rest.repr.OutputFormat.ok(OutputFormat.java:48)",
> >
> "org.neo4j.server.rest.web.RestfulGraphDatabase.allPaths(RestfulGraphDatabase.java:987)",
> > "sun.reflect.GeneratedMethodAccessor153.invoke(Unknown Source)",
> >
> "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)",
> > "java.lang.reflect.Method.invoke(Method.java:597)",
> >
> "com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:184)",
> >
> "com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)",
> >
> "com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:276)",
> >
> "com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)",
> >
> "com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)",
> >
> "com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)",
> >
> "com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:71)",
> >
> "com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1171)",
> >
> "com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1103)",
> >
> "com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1053)",
> >
> "com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1043)",
> >
> "com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:406)",
> >
> "com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:477)",
> >
> "com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:662)",
> > "javax.servlet.http.HttpServlet.service(HttpServlet.java:820)",
> > "org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)",
> >
> "org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)",
> >
> "org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)",
> >
> "org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)",
> >
> "org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)",
> >
> "org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)",
> > "org.mortbay.jetty.Server.handle(Server.java:326)",
> >
> "org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)",
> >
> "org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)",
> > "org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)",
> > "org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)",
> > "org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)",
> >
> "org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)",
> >
> "org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)"
> > ]
> > }
> >
> > ===== END SHELL
> >
> > Thanks for any help you can provide.
> >
> > -- Josh
> > _______________________________________________
> > Neo4j mailing list
> > [email protected]
> > https://lists.neo4j.org/mailman/listinfo/user
>
> _______________________________________________
> Neo4j mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Mattias Persson, [[email protected]]
Hacker, Neo Technology
www.neotechnology.com
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to