1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.neo4j.server.rest.repr;
21
22 import org.neo4j.graphdb.Node;
23 import org.neo4j.graphdb.Path;
24 import org.neo4j.graphdb.Relationship;
25 import org.neo4j.helpers.collection.IterableWrapper;
26
27 public class PathRepresentation<P extends Path> extends ObjectRepresentation
28 {
29 private final P path;
30
31 public PathRepresentation( P path )
32 {
33 super( RepresentationType.PATH );
34 this.path = path;
35 }
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 protected P getPath()
54 {
55 return path;
56 }
57
58 @Mapping( "start" )
59 public ValueRepresentation startNode()
60 {
61 return ValueRepresentation.uri( NodeRepresentation.path( path.startNode() ) );
62 }
63
64 @Mapping( "end" )
65 public ValueRepresentation endNode()
66 {
67 return ValueRepresentation.uri( NodeRepresentation.path( path.endNode() ) );
68 }
69
70 @Mapping( "length" )
71 public ValueRepresentation length()
72 {
73 return ValueRepresentation.number( path.length() );
74 }
75
76 @Mapping( "nodes" )
77 public ListRepresentation nodes()
78 {
79 return new ListRepresentation( RepresentationType.NODE, new IterableWrapper<Representation, Node>(
80 path.nodes() )
81 {
82 @Override
83 protected Representation underlyingObjectToObject( Node node )
84 {
85 return ValueRepresentation.uri( NodeRepresentation.path( node ) );
86 }
87 } );
88 }
89
90 @Mapping( "relationships" )
91 public ListRepresentation relationships()
92 {
93 return new ListRepresentation( RepresentationType.RELATIONSHIP,
94 new IterableWrapper<Representation, Relationship>( path.relationships() )
95 {
96 @Override
97 protected Representation underlyingObjectToObject( Relationship node )
98 {
99 return ValueRepresentation.uri( RelationshipRepresentation.path( node ) );
100 }
101 } );
102 }
103 }