-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.shell_history
executable file
·142 lines (142 loc) · 6.56 KB
/
.shell_history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
start parent=node(46) MATCH parent-[r:CONTAINS]->category WHERE has(category.key) and category.type = 'categoryNode' and category.key = 'C' REMOVE category.key RETURN category;
MATCH parent-[r:CONTAINS]->category WHERE id(parent) = 46 has(category.key) and category.type = 'categoryNode' and category.key = 'C' REMOVE category.key RETURN category;
MATCH andres WHERE andres.name='Andres' REMOVE andres.age RETURN andres;
help
start parent=node(46) MATCH parent-[r:CONTAINS]->category WHERE has(category.key) and category.type = 'categoryNode' and category.key = 'C' DELETE category.key RETURN category ;
cd import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.io.IOUtils;
import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.apache.commons.lang.*;
import com.google.common.collect.Sets;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
public class Server {
@Path("yurl")
public static class HelloWorldResource { // Must be public
final String CYPHER_URI = "http://netgear.rohidekar.com:7474/db/data/cypher";
@GET
@Path("parent")
@Produces("application/json")
public Response parent(@QueryParam("nodeId") Integer nodeId) throws JSONException,
IOException {
Map<String, Object> params = new HashMap<String, Object>();
params.put("nodeId", nodeId);
// TODO: order these by most recent-first (so that they appear this
// way in the UI)
JSONObject json = queryNeo4j(
"start n=node({nodeId}) MATCH p-[r:CONTAINS]->n RETURN id(p)", params);
JSONArray data = (JSONArray) json.get("data");
JSONArray ret = new JSONArray();
for (int i = 0; i < data.length(); i++) {
JSONArray a = data.getJSONArray(i);
JSONObject o = new JSONObject();
String id = (String) a.get(0);
o.put("id", id);
ret.put(o);
}
return Response.ok().header("Access-Control-Allow-Origin", "*").entity(ret.toString())
.type("application/json").build();
}
@GET
@Path("uncategorized")
@Produces("application/json")
public Response uncategorized(@QueryParam("rootId") Integer rootId) throws JSONException,
IOException {
// TODO: check rootId is not null or empty
// TODO: the source is null clause should be obsoleted
Map<String, Object> params = new HashMap<String, Object>();
params.put("rootId", rootId);
// TODO: order these by most recent-first (so that they appear this
// way in the UI)
JSONObject json = queryNeo4j(
"start n=node(*) MATCH n<-[r?:CONTAINS]-source where (source is null or ID(source) = {rootId}) and not(has(n.type)) AND id(n) > 0 return distinct ID(n),n.title?,n.url?",
params);
JSONArray data = (JSONArray) json.get("data");
JSONArray ret = new JSONArray();
for (int i = 0; i < data.length(); i++) {
JSONArray a = data.getJSONArray(i);
JSONObject o = new JSONObject();
String id = (String) a.get(0);
o.put("id", id);
String title = (String) a.get(1);
String url = (String) a.get(2);
o.put("title", title);
o.put("url", url);
ret.put(o);
}
return Response.ok().header("Access-Control-Allow-Origin", "*").entity(ret.toString())
.type("application/json").build();
}
@GET
@Path("keysUpdate")
@Produces("application/json")
// TODO: we will have to start supporting disassociation of key bindings
// with child categories
public Response keysUpdate(@QueryParam("parentId") Integer parentId,
@QueryParam("newKeyBindings") String newKeyBindings,
@QueryParam("oldKeyBindings") String oldKeyBindings) throws JSONException,
IOException {
System.out.println("keysUpdate");
Set<String> oldKeyBindingsSet = new HashSet<String>();
Collections.addAll(oldKeyBindingsSet, oldKeyBindings.trim().split("\n"));
Set<String> newKeyBindingsSet = new HashSet<String>();
Collections.addAll(newKeyBindingsSet, newKeyBindings.trim().split("\n"));
// NOTE: This is not symmetric (commutative?). If you want to
// support removal do that in a separate loop
Set<String> newKeyBindingLines = Sets.difference(newKeyBindingsSet, oldKeyBindingsSet);
System.out.println("Old: " + oldKeyBindingsSet);
System.out.println("New: " + newKeyBindingsSet);
System.out.println("Difference: " + newKeyBindingLines);
Map<String, String> keyBindings = new HashMap<String, String>();
for (String newKeyBinding : newKeyBindingLines) {
if (newKeyBinding.trim().startsWith("#") && !newKeyBinding.trim().startsWith("#=")) {
continue;// A commented out keybinding
}
String[] lineElements = newKeyBinding.split("=");
String aKeyCode = lineElements[0].trim();
// Ignore trailing comments
String[] aRightHandSideElements = lineElements[1].trim().split("#");
String aName = aRightHandSideElements[0].trim();
//
System.out.println("Accepting proposal to create key binding for " + aName + "("
+ aKeyCode + ")");
keyBindings.put(aKeyCode, aName);
// TODO: if it fails, recover and create the remaining ones
}
for (String aKeyCode : keyBindings.keySet()) {
start source=node(37567) match source-[r:CONTAINS*1..2]->u where (source is null or ID(source) = 37567) and not(has(u.type)) AND id(u) > 0 return u.title?, extract(r1 in r | id(r1));
start source=node(37567) match source-[r:CONTAINS*1..2]->u where (source is null or ID(source) = 37567) and not(has(u.type)) AND id(u) > 0 return distinct ID(u),u.title?,u.url?,u.created?,u.ordinal?, extract(r1 in r | id(r1)) ORDER BY u.ordinal? DESC;
start source=node(37567) match source-[r:CONTAINS*1..2]->u where (source is null or ID(source) = 37567) and not(has(u.type)) AND id(u) > 0 return distinct ID(u),u.title?,u.url?,u.created?,u.ordinal?, extract(r1 in r | id(r1)) as relationshipsORDER BY u.ordinal? DESC;
start source=node(37567) match source-[r:CONTAINS*1..2]->u where (source is null or ID(source) = 37567) and not(has(u.type)) AND id(u) > 0 return distinct ID(u),u.title?,u.url?,u.created?,u.ordinal?, extract(r1 in r | id(r1)) as path ORDER BY u.ordinal? DESC;