Mercurial > hg > Members > nobuyasu > Consensus
changeset 35:5d422941b702
fix
author | one |
---|---|
date | Wed, 03 Oct 2012 18:43:49 +0900 |
parents | fac4aa26ea04 |
children | 5f7fcdf98380 |
files | app/controllers/Claim.java app/controllers/User.java app/models/TPGraph.java target/scala-2.9.1/cache/compile/compile test/RequestTest.java |
diffstat | 5 files changed, 64 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/app/controllers/Claim.java Wed Oct 03 16:58:34 2012 +0900 +++ b/app/controllers/Claim.java Wed Oct 03 18:43:49 2012 +0900 @@ -42,6 +42,35 @@ } @BodyParser.Of(BodyParser.Json.class) + public static Result editClaim(String id) { + JsonNode json = request().body().asJson(); + String author = json.findPath(NodeModel.L_AUTHOR).getTextValue(); // Author + TPGraph tpGraph = TPGraph.getInstance(); + Graph graph = tpGraph.getGraph(); + Vertex claimVertex = graph.getVertex(id); + if ( claimVertex == null ) { + return badRequest("Claim id "+ id + "is not exist."); + } + if ( graph.getVertex(author) == null) { + return badRequest("Author "+ author + "is not exist."); + } + JsonNode toulmin = json.findPath(NodeModel.TOULMIN); + if (toulmin.findPath(NodeModel.TITLE) == null) { + return badRequest("Please set title"); + } + JsonNode usersJson = json.get(NodeModel.USERS); + String type = json.findPath(NodeModel.TYPE).getTextValue(); // Type (majority|unanimously) + ClaimModel claim = new ClaimModel(claimVertex); + tpGraph.setLabelToAuthor(claim, author); + claim.setClaimProperties(toulmin, type); + String[] users = toStringArray(usersJson); + tpGraph.setLabelStatusToUsers(claim, users, NodeModel.L_REQUEST, NodeModel.FAIL); + tpGraph.setLabelToRootClaim(claim); + return created(); + } + + + @BodyParser.Of(BodyParser.Json.class) public static Result createMention(String mentionType, String id) { if ( !(mentionType.equals(NodeModel.L_QUESTION) ||mentionType.equals(NodeModel.L_REFUTATION) @@ -83,7 +112,7 @@ ObjectNode claimInfo = claim.getSimpleClaimInfo(); ObjectNode result = Json.newObject(); result.put("status", "OK"); - result.put("message", claimInfo.toString()); + result.put("message", claimInfo); return ok(result); } @@ -98,6 +127,8 @@ ObjectNode resultEntity = consensusRoot.getClaimInfoTraverse(); return ok(resultEntity); } + +
--- a/app/controllers/User.java Wed Oct 03 16:58:34 2012 +0900 +++ b/app/controllers/User.java Wed Oct 03 18:43:49 2012 +0900 @@ -15,7 +15,6 @@ public class User extends Controller { public static Result createUser(String name) { - TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); Vertex v = null; @@ -23,7 +22,7 @@ try { v = graph.addVertex(name); } catch (IllegalArgumentException e) { - return status(CONFLICT, name+" is already exists"); + return status(CONFLICT, name+" already exists"); } newUser = new UserModel(v); tpGraph.setLabelToRootUser(newUser);
--- a/app/models/TPGraph.java Wed Oct 03 16:58:34 2012 +0900 +++ b/app/models/TPGraph.java Wed Oct 03 18:43:49 2012 +0900 @@ -81,21 +81,18 @@ public Edge setLabelToRootUser(UserModel user) { Vertex rootUser = getUserRootVertex(); - // rootUser ---child---> newUser return setLabel(rootUser, user.getVertex(), CHILD); } public Edge setLabelToRootClaim(ClaimModel claim) { Vertex rootClaim = getClaimRootVertex(); - // rootUser ---child---> newUser return setLabel(rootClaim, claim.getVertex(), CHILD); } public Edge setLabelToAuthor(ClaimModel claim, String author) { Vertex authorVertex = graph.getVertex(author); - // claim ---author---> authorVertex(userVertex) return setLabel(claim.getVertex(), authorVertex, NodeModel.L_AUTHOR); } @@ -125,14 +122,12 @@ public Object[] checkConsensus(HashSet<Object> set) { Iterator<Object> iter = set.iterator(); - while (iter.hasNext()) { Object childId = iter.next(); ArrayList<Object> array = getAllUpperVertex(childId); for (Object parentId: array.toArray()) { if (set.contains(parentId)) { if (set.contains(childId)) { - // This behavior is anxiety. set.remove(childId); iter = set.iterator(); @@ -150,13 +145,11 @@ GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); pipe.start(startV).in(NodeModel.L_QUESTION, NodeModel.L_REFUTATION, NodeModel.L_SUGGESTION); ArrayList<Object> vertexArray = new ArrayList<Object>(); - while (pipe.hasNext()) { Object e = pipe.next().getId(); vertexArray.add(e); pipe.start(graph.getVertex(e)).in(NodeModel.L_QUESTION, NodeModel.L_REFUTATION, NodeModel.L_SUGGESTION); } - return vertexArray; }
--- a/test/RequestTest.java Wed Oct 03 16:58:34 2012 +0900 +++ b/test/RequestTest.java Wed Oct 03 18:43:49 2012 +0900 @@ -43,16 +43,25 @@ getUserInfo(user3,"consensus/"); for (int i=0; i<user1Claim.size(); i++) { int id = user1Claim.get(i).asInt(); + getClaimTree(id); getClaimInfo(user1Claim.get(i).asInt()); - getClaimTree(id); + editClaimInfo(id); + getClaimInfo(user1Claim.get(i).asInt()); break; } } + + public static JsonNode editClaimInfo(String id) { + + return null; + } public static JsonNode getClaimTree(int id) { final String uri = SERVER_ROOT_URI + "/consensus/browse/"+id; WebResource resource = Client.create().resource(uri); - ClientResponse response = resource.get(ClientResponse.class); +// ClientResponse response = resource.get(ClientResponse.class); + ClientResponse response = resource + .get(ClientResponse.class); System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus())); String resStr = response.getEntity(String.class); System.out.println(resStr); @@ -93,6 +102,26 @@ System.out.println(resStr); return Json.toJson(resStr); } + + public static ObjectNode createEditClaimParameter(String author, String[] users) { + ObjectNode toulmin = Json.newObject(); + toulmin.put(NodeModel.TITLE, "アプリでGraphDBを利用する。"); + toulmin.put(NodeModel.CONTENTS, "最近話題のデータベースとしてGraphDBがある。我々のアプリでは、新しい技術のためにもGraphDBを利用したい。"); + toulmin.put(NodeModel.QUALIFIER, "絶対"); + toulmin.put(NodeModel.WARRANT,"GraphDBの実用例 etc..."); + toulmin.put(NodeModel.BACKING, "GraphDBの最新動向 etc..."); + toulmin.put(NodeModel.DATA,"GraphDBの実用例 etc..."); + toulmin.put(NodeModel.REBUTTLE,""); + ObjectNode jobj = Json.newObject(); + jobj.put(NodeModel.TOULMIN, toulmin); + jobj.put(NodeModel.L_AUTHOR, author); + ArrayNode usersArray = jobj.putArray(NodeModel.USERS); + for (String u : users) usersArray.add(u); + + jobj.put(NodeModel.TYPE, NodeModel.UNANIMOUSLY); + return jobj; + } + public static ObjectNode createClaimParameter(String author, String[] users) { ObjectNode toulmin = Json.newObject();