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.Relationship;
24
25 public final class IndexedEntityRepresentation extends MappingRepresentation implements
26 ExtensibleRepresentation, EntityRepresentation
27 {
28 private final MappingRepresentation entity;
29 private final ValueRepresentation selfUri;
30
31 @SuppressWarnings("boxing")
32 public IndexedEntityRepresentation( Node node, String key, String value, IndexRepresentation indexRepresentation )
33 {
34 this( new NodeRepresentation( node ), node.getId(), key, value, indexRepresentation );
35 }
36
37 @SuppressWarnings("boxing")
38 public IndexedEntityRepresentation( Relationship rel, String key, String value, IndexRepresentation indexRepresentation )
39 {
40 this( new RelationshipRepresentation( rel ), rel.getId(), key, value, indexRepresentation );
41 }
42
43 private IndexedEntityRepresentation( MappingRepresentation entity, long entityId, String key, String value, IndexRepresentation indexRepresentation )
44 {
45 super( entity.type );
46 this.entity = entity;
47 selfUri = ValueRepresentation.uri( indexRepresentation.relativeUriFor( key, value, entityId ) );
48 }
49
50 @Override
51 public String getIdentity()
52 {
53 return ((ExtensibleRepresentation) entity).getIdentity();
54 }
55
56 public ValueRepresentation selfUri()
57 {
58 return selfUri;
59 }
60
61 @Override
62 protected void serialize( MappingSerializer serializer )
63 {
64 entity.serialize( serializer );
65 selfUri().putTo( serializer, "indexed" );
66 }
67 }