comparison app/controllers/db/Data.java @ 4:e12d0b6dbe02 draft default tip

add some files
author e085711
date Wed, 26 Sep 2012 14:43:57 +0900
parents
children
comparison
equal deleted inserted replaced
3:5a097a2336fa 4:e12d0b6dbe02
1 package controllers.db;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7 import java.util.Map;
8
9 import javax.ws.rs.core.MediaType;
10
11 import models.NodeModel;
12 import models.TPGraph;
13
14 import org.json.JSONException;
15 import org.json.JSONObject;
16
17 import com.sun.corba.se.impl.orbutil.graph.Node;
18 import com.tinkerpop.blueprints.Graph;
19 import com.tinkerpop.blueprints.Vertex;
20
21 import play.mvc.Controller;
22 import play.mvc.Http;
23
24 public class Data extends Controller {
25
26 public static void index() {
27
28
29 renderText("renderText");
30 }
31
32
33 public static void node() throws JSONException, IOException {
34 Http.Header accept = request.headers.get("accept");
35 if (!(accept.toString()).equals("["+MediaType.APPLICATION_JSON+"]") ) {
36 renderText("please set accept application/json");
37 return;
38 }
39
40 TPGraph tpgraph = TPGraph.getInstance();
41 Graph graph = tpgraph.getGraph();
42
43 Vertex v = graph.addVertex(null);
44 NodeModel node = new NodeModel(v);
45
46 String str="";
47 InputStream in = request.body;
48 BufferedReader br = new BufferedReader(new InputStreamReader(in));
49 String tmp ="";
50 while ( (tmp = br.readLine()) != null) str += tmp;
51
52 node.setPropetiesFromJson(new JSONObject(str));
53 renderJSON(node.getNodeJson().toString());
54
55
56 }
57
58
59 public static void node(String id) throws JSONException {
60 Http.Header accept = request.headers.get("accept");
61 if (!(accept.toString()).equals("["+MediaType.APPLICATION_JSON+"]") ) {
62 renderText("please set accept application/json");
63 return;
64 }
65
66 TPGraph tpgraph = TPGraph.getInstance();
67 Graph graph = tpgraph.getGraph();
68 if (request.method.equals("GET")) {
69 Vertex v = graph.getVertex(id);
70 if (v == null) {
71 renderText("Not exist Vertex ID "+id);
72 return;
73 } else {
74 NodeModel node = new NodeModel(v);
75 node.getProperties();
76 JSONObject jobj = node.getNodeJson();
77 renderJSON(jobj.toString());
78 return;
79 }
80 }
81 }
82
83
84 public static void test(String id) {
85 renderText(id);
86
87 }
88
89
90
91
92 }