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.web;
21
22 import org.neo4j.server.rest.domain.JsonHelper;
23
24 import java.net.URI;
25 import java.util.HashMap;
26 import java.util.Map;
27
28
29
30
31
32 public class RestfulModelHelper
33 {
34 public static DomainModel generateMatrix( RestfulGraphDatabase rgd ) {
35 String key = "key_get";
36 String value = "value";
37
38 DomainModel dm = new DomainModel();
39
40 DomainEntity thomas = new DomainEntity();
41 thomas.properties.put("name", "Thomas Anderson");
42 thomas.location = (URI) rgd.createNode( "{\"name\":\"" + "Thomas Anderson" + "\"}" ).getMetadata().getFirst(
43 "Location" );
44 dm.add(thomas);
45
46 DomainEntity agent = new DomainEntity();
47 agent.properties.put("name", "Agent Smith");
48 agent.location = (URI) rgd.createNode( "{\"name\":\"" + "Agent Smith" + "\"}" ).getMetadata().getFirst(
49 "Location" );
50 dm.add(agent);
51
52 dm.nodeIndexName = "matrixal-nodes";
53 dm.indexedNodeKeyValues.put(key, value);
54 dm.indexedNodeUriToEntityMap.put( (URI) rgd.addToNodeIndex( dm.nodeIndexName, key, value,
55 JsonHelper.createJsonFrom( thomas.location.toString() ) ).getMetadata().getFirst(
56 "Location" ), thomas );
57 dm.indexedNodeUriToEntityMap.put( (URI) rgd.addToNodeIndex( dm.nodeIndexName, key, value,
58 JsonHelper.createJsonFrom( agent.location.toString() ) ).getMetadata().getFirst(
59 "Location" ), agent);
60
61 return dm;
62 }
63
64 public static class DomainEntity
65 {
66 public URI location;
67 public Map<String,String> properties = new HashMap<String, String>();
68 }
69
70 public static class DomainModel {
71 public Map<URI, DomainEntity> nodeUriToEntityMap = new HashMap<URI, DomainEntity>();
72 String nodeIndexName = "nodes";
73 public Map<String,String> indexedNodeKeyValues = new HashMap<String, String>();
74 public Map<URI, DomainEntity> indexedNodeUriToEntityMap = new HashMap<URI, DomainEntity>();
75 String relationshipIndexName = "relationships";
76 public Map<URI, DomainEntity> indexedRelationshipUriToEntityMap = new HashMap<URI, DomainEntity>();
77 public Map<String,String> indexedRelationshipKeyValues = new HashMap<String, String>();
78
79 public void add(DomainEntity de)
80 {
81 nodeUriToEntityMap.put(de.location, de);
82 }
83 }
84 }