Mercurial > hg > Members > nobuyasu > TOModel
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/controllers/db/Data.java Wed Sep 26 14:43:57 2012 +0900 @@ -0,0 +1,92 @@ +package controllers.db; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import models.NodeModel; +import models.TPGraph; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.sun.corba.se.impl.orbutil.graph.Node; +import com.tinkerpop.blueprints.Graph; +import com.tinkerpop.blueprints.Vertex; + +import play.mvc.Controller; +import play.mvc.Http; + +public class Data extends Controller { + + public static void index() { + + + renderText("renderText"); + } + + + public static void node() throws JSONException, IOException { + Http.Header accept = request.headers.get("accept"); + if (!(accept.toString()).equals("["+MediaType.APPLICATION_JSON+"]") ) { + renderText("please set accept application/json"); + return; + } + + TPGraph tpgraph = TPGraph.getInstance(); + Graph graph = tpgraph.getGraph(); + + Vertex v = graph.addVertex(null); + NodeModel node = new NodeModel(v); + + String str=""; + InputStream in = request.body; + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String tmp =""; + while ( (tmp = br.readLine()) != null) str += tmp; + + node.setPropetiesFromJson(new JSONObject(str)); + renderJSON(node.getNodeJson().toString()); + + + } + + + public static void node(String id) throws JSONException { + Http.Header accept = request.headers.get("accept"); + if (!(accept.toString()).equals("["+MediaType.APPLICATION_JSON+"]") ) { + renderText("please set accept application/json"); + return; + } + + TPGraph tpgraph = TPGraph.getInstance(); + Graph graph = tpgraph.getGraph(); + if (request.method.equals("GET")) { + Vertex v = graph.getVertex(id); + if (v == null) { + renderText("Not exist Vertex ID "+id); + return; + } else { + NodeModel node = new NodeModel(v); + node.getProperties(); + JSONObject jobj = node.getNodeJson(); + renderJSON(jobj.toString()); + return; + } + } + } + + + public static void test(String id) { + renderText(id); + + } + + + + +}