7
|
1 package models;
|
|
2
|
8
|
3 import java.util.HashMap;
|
17
|
4 import java.util.Iterator;
|
|
5
|
|
6
|
|
7
|
|
8 import org.codehaus.jackson.JsonNode;
|
|
9 import org.codehaus.jackson.node.ArrayNode;
|
|
10 import org.codehaus.jackson.node.JsonNodeFactory;
|
|
11
|
|
12 import play.libs.Json;
|
8
|
13
|
18
|
14 import com.tinkerpop.blueprints.Direction;
|
|
15 import com.tinkerpop.blueprints.Edge;
|
7
|
16 import com.tinkerpop.blueprints.Vertex;
|
18
|
17 import com.tinkerpop.gremlin.java.GremlinPipeline;
|
7
|
18
|
|
19 public class UserModel extends NodeModel {
|
8
|
20
|
7
|
21
|
|
22 public UserModel(Vertex vertex) {
|
|
23 super(vertex);
|
|
24 }
|
|
25
|
18
|
26 private Object[] getEdgeInUser(String labels) {
|
|
27 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
|
|
28 pipe.start(this.vertex).in(labels);
|
|
29 long length = pipe.count();
|
|
30 if (length == 0) return null;
|
|
31 Object[] requests = new Object[(int) length];
|
|
32 int i = 0;
|
|
33 for (Vertex v :pipe) {
|
|
34 requests[i] = v.getId();
|
|
35 i++;
|
|
36 }
|
|
37 return requests;
|
9
|
38 }
|
|
39
|
18
|
40 public Object[] getUserRequests() {
|
|
41 return getEdgeInUser(L_REQUEST);
|
|
42 }
|
|
43
|
|
44 public Object[] getUserClaims() {
|
|
45 return getEdgeInUser(L_CLAIMS);
|
10
|
46 }
|
17
|
47
|
18
|
48 public Object[] getUserConsensus() {
|
|
49 return null;
|
10
|
50 }
|
|
51
|
17
|
52 public void appendRequests(Vertex claimVertex) {
|
18
|
53 Object[] requestsObj = getUserRequests();
|
17
|
54 int length = requestsObj == null ? 0 : requestsObj.length;
|
|
55 Object[] newRequestsObj = new Object[length+1];
|
|
56 for (int i=0; i<length; i++ ) {
|
|
57 newRequestsObj[i] = requestsObj[i];
|
|
58 }
|
|
59 newRequestsObj[length] = claimVertex.getId();
|
18
|
60 // vertex.setProperty(REQUESTS, newRequestsObj);
|
17
|
61 }
|
8
|
62
|
|
63 /*
|
7
|
64 public Vertex setName(String name) {
|
|
65 this.vertex.setProperty(NAME, name);
|
|
66 return vertex;
|
|
67 }
|
8
|
68 */
|
7
|
69
|
|
70
|
|
71
|
|
72 }
|