Mercurial > hg > Members > nobuyasu > Consensus
view app/controllers/User.java @ 20:34ea98c5a18c
modified UserModel/getEdgeInUser
author | one |
---|---|
date | Tue, 02 Oct 2012 22:49:16 +0900 |
parents | c8ad59a52c7e |
children | 6506b8742343 |
line wrap: on
line source
package controllers; import java.util.HashMap; import com.tinkerpop.blueprints.Graph; import com.tinkerpop.blueprints.Vertex; import models.TPGraph; import models.UserModel; import play.libs.Json; import play.mvc.Controller; import play.mvc.Result; public class User extends Controller { public static Result createUser(String name) { TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); Vertex v = null; UserModel newUser = null; try { v = graph.addVertex(name); } catch (IllegalArgumentException e) { return status(CONFLICT, name+" is already exists"); } newUser = new UserModel(v); tpGraph.setLabelToRootUser(newUser); // newUser.setName(name); // user node hasn't name property(only TinkerGraph). return created(); } public static Result getUser(String name) { TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); Vertex v = graph.getVertex(name); if (v == null) { return notFound(); } else { UserModel user = new UserModel(v); HashMap<Object,Object> hash = user.getAllProperty(); // HashMap<Object,Object> hash = user.getAllInfo(); return created(Json.toJson(hash)); } } public static Result getUserRequests(String name) { TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); Vertex v = graph.getVertex(name); if (v == null) { return notFound("user: "+name+" not found"); } else { UserModel user = new UserModel(v); Object[] requests = user.getUserRequests(); if (requests == null) return notFound("Requests not found"); return created(Json.toJson(requests)); } } public static Result getUserConsensus(String name) { TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); Vertex v = graph.getVertex(name); if (v == null) { return notFound("user: "+name+" not found"); } else { UserModel user = new UserModel(v); Object[] consensus = user.getUserConsensus(); if (consensus == null) return notFound("Consensus not found"); return created(Json.toJson(consensus)); } } public static Result getUserClaims(String name) { TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); Vertex v = graph.getVertex(name); if (v == null) { return notFound("user: "+name+" not found"); } else { UserModel user = new UserModel(v); Object[] claims = user.getUserClaims(); if (claims == null) return notFound("Claims not found"); return created(Json.toJson(claims)); } } }