# HG changeset patch # User one # Date 1349276500 -32400 # Node ID 5f7fcdf983808698fb210dae5a21a08d031c81d1 # Parent 5d422941b70255ff2c4a1c227c165731f781a9e1 create editClaim diff -r 5d422941b702 -r 5f7fcdf98380 app/controllers/Claim.java --- a/app/controllers/Claim.java Wed Oct 03 18:43:49 2012 +0900 +++ b/app/controllers/Claim.java Thu Oct 04 00:01:40 2012 +0900 @@ -36,7 +36,7 @@ tpGraph.setLabelToAuthor(newClaim, author); newClaim.setClaimProperties(toulmin, type); String[] users = toStringArray(usersJson); - tpGraph.setLabelStatusToUsers(newClaim, users, NodeModel.L_REQUEST, NodeModel.FAIL); + Boolean flag = tpGraph.setLabelStatusToUsers(newClaim, users, NodeModel.L_REQUEST, NodeModel.FAIL); tpGraph.setLabelToRootClaim(newClaim); return created(); } @@ -47,9 +47,12 @@ 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."); + ClaimModel claim = new ClaimModel(graph.getVertex(id)); + if ( claim.getVertex() == null ) { + return badRequest("Claim id "+ id + "does not exist."); + } + if ( !claim.getAuthorId().equals(author)) { + return badRequest("Wrong Author."); } if ( graph.getVertex(author) == null) { return badRequest("Author "+ author + "is not exist."); @@ -58,13 +61,11 @@ if (toulmin.findPath(NodeModel.TITLE) == null) { return badRequest("Please set title"); } - JsonNode usersJson = json.get(NodeModel.USERS); + 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); + Object[] users = toStringObject(usersJson); + claim.editRequestsEdgeUsers(users); tpGraph.setLabelToRootClaim(claim); return created(); } @@ -111,7 +112,6 @@ ClaimModel claim = new ClaimModel(claimV); ObjectNode claimInfo = claim.getSimpleClaimInfo(); ObjectNode result = Json.newObject(); - result.put("status", "OK"); result.put("message", claimInfo); return ok(result); } @@ -127,10 +127,18 @@ ObjectNode resultEntity = consensusRoot.getClaimInfoTraverse(); return ok(resultEntity); } - - - + private static Object[] toStringObject(JsonNode jsonNode) { + int length = jsonNode.size(); + if (length == 0) { + return null; + } + Object[] userArray = new Object[length]; + for (int i=0; i currentUsersHashSet = new HashSet(); + for (Object u : currentUsers) { + currentUsersHashSet.add(u); + } + for (Object updateUser : updateUsers) { + if (currentUsersHashSet.contains(updateUser)) { + currentUsersHashSet.remove(updateUser); + } else { + tpGraph.setLabelStatusToUser(this, updateUser.toString(), L_REQUEST, UNKNOWN); + } + } + tpGraph.deleteRequestEdge(this, currentUsersHashSet); + } + public Object getAuthorId() { GremlinPipeline pipe = new GremlinPipeline(); pipe.start(vertex).out(L_AUTHOR); diff -r 5d422941b702 -r 5f7fcdf98380 app/models/NodeModel.java --- a/app/models/NodeModel.java Wed Oct 03 18:43:49 2012 +0900 +++ b/app/models/NodeModel.java Thu Oct 04 00:01:40 2012 +0900 @@ -48,6 +48,7 @@ public static final String FAIL = "fail"; public static final String AGREED = "agreed"; public static final String DENIED = "denied"; + public static final String UNKNOWN = "unknown"; // Use This key Json Data public static final String CLAIM = "claim"; @@ -57,7 +58,11 @@ public NodeModel(Vertex vertex) { this.vertex = vertex; - this.id = vertex.getId(); + if (vertex == null) { + this.id = null; + } else { + this.id = vertex.getId(); + } } public void setId(Object id) { diff -r 5d422941b702 -r 5f7fcdf98380 app/models/TPGraph.java --- a/app/models/TPGraph.java Wed Oct 03 18:43:49 2012 +0900 +++ b/app/models/TPGraph.java Thu Oct 04 00:01:40 2012 +0900 @@ -106,12 +106,22 @@ return true; } + public Boolean setLabelStatusToUser(ClaimModel claim, String userName, String label, String status) { + Vertex userVertex = graph.getVertex(userName); + if (userVertex == null) { + return false; + } + Edge edge = setLabel(claim.getVertex(), userVertex, label); + edge.setProperty(NodeModel.STATUS, status); + return true; + } + public Boolean setLabelStatusToUsers(ClaimModel claim, String[] users, String label, String status) { for (String userName: users) { - Vertex userVertex = graph.getVertex(userName); - if (userVertex == null) return false; - Edge edge = setLabel(claim.getVertex(), userVertex, label); - edge.setProperty(NodeModel.STATUS, status); + Boolean createFlag = setLabelStatusToUser(claim, userName, label, status); + if (!createFlag) { + return false; + } } return true; } @@ -120,6 +130,24 @@ return setLabel(fromClaim.getVertex(), toClaim.getVertex(), label); } + public Boolean deleteRequestEdge(ClaimModel claim, HashSet userSet) { + GremlinPipeline pipeEdge = new GremlinPipeline(); + pipeEdge.start(claim.getVertex()).outE(NodeModel.L_REQUEST); + ArrayList deleteEdgeArray = new ArrayList(); + for (Edge e : pipeEdge) { + GremlinPipeline pipeUserVertex = new GremlinPipeline(); + pipeUserVertex.start(e).inV(); + Vertex userVertex = pipeUserVertex.next(); + if (userSet.contains(userVertex.getId())) { + deleteEdgeArray.add(e); + } + } + for (Edge e : deleteEdgeArray) { + graph.removeEdge(e); + } + return true; + } + public Object[] checkConsensus(HashSet set) { Iterator iter = set.iterator(); while (iter.hasNext()) { diff -r 5d422941b702 -r 5f7fcdf98380 app/models/UserModel.java --- a/app/models/UserModel.java Wed Oct 03 18:43:49 2012 +0900 +++ b/app/models/UserModel.java Thu Oct 04 00:01:40 2012 +0900 @@ -48,7 +48,7 @@ if (set.size() == 0) return null; return set; } - + /* public Object[] getUserConsensus() { return null; diff -r 5d422941b702 -r 5f7fcdf98380 conf/routes --- a/conf/routes Wed Oct 03 18:43:49 2012 +0900 +++ b/conf/routes Thu Oct 04 00:01:40 2012 +0900 @@ -15,6 +15,7 @@ POST /claims/create controllers.Claim.crateClaim() POST /claims/:mentionType/:id/create controllers.Claim.createMention(mentionType: String ,id: String) +POST /claims/edit/:id controllers.Claim.editClaim(id: String) GET /consensus/browse/:id controllers.Claim.getClaimTree(id: String) diff -r 5d422941b702 -r 5f7fcdf98380 logs/application.log --- a/logs/application.log Wed Oct 03 18:43:49 2012 +0900 +++ b/logs/application.log Thu Oct 04 00:01:40 2012 +0900 @@ -1,94 +1,12 @@ -2012-10-03 16:31:09,013 - [INFO] - from play in main +2012-10-03 23:52:13,026 - [INFO] - from play in main Listening for HTTP on port 9000... -2012-10-03 16:31:15,139 - [INFO] - from play in play-akka.actor.default-dispatcher-2 -Application started (Dev) - -2012-10-03 16:31:45,206 - [INFO] - from application in play-akka.actor.default-dispatcher-1 -Application shutdown... - -2012-10-03 16:31:45,229 - [INFO] - from play in play-akka.actor.default-dispatcher-1 -Application started (Dev) - -2012-10-03 16:35:57,771 - [INFO] - from application in play-akka.actor.default-dispatcher-1 -Application shutdown... - -2012-10-03 16:35:57,790 - [INFO] - from play in play-akka.actor.default-dispatcher-1 +2012-10-03 23:52:27,823 - [INFO] - from play in play-akka.actor.default-dispatcher-2 Application started (Dev) -2012-10-03 16:40:03,578 - [INFO] - from application in play-akka.actor.default-dispatcher-1 -Application shutdown... - -2012-10-03 16:40:03,595 - [INFO] - from play in play-akka.actor.default-dispatcher-1 -Application started (Dev) - -2012-10-03 16:40:04,414 - [ERROR] - from application in play-akka.actor.actions-dispatcher-8 - - -! @6bpi0n84b - Internal server error, for request [GET /claims/browse/10] -> - -play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[FastNoSuchElementException: null]] - at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.3] - at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.3] - at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2] - at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.3] - at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2] - at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2] - at akka.dispatch.Mailbox.run(Mailbox.scala:179) [akka-actor.jar:2.0.2] - at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516) [akka-actor.jar:2.0.2] - at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) [akka-actor.jar:2.0.2] - at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) [akka-actor.jar:2.0.2] - at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479) [akka-actor.jar:2.0.2] - at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) [akka-actor.jar:2.0.2] -com.tinkerpop.pipes.util.FastNoSuchElementException: null - -2012-10-03 16:41:51,310 - [INFO] - from application in play-akka.actor.default-dispatcher-1 +2012-10-03 23:55:53,105 - [INFO] - from application in play-akka.actor.default-dispatcher-2 Application shutdown... -2012-10-03 16:41:51,328 - [INFO] - from play in play-akka.actor.default-dispatcher-1 -Application started (Dev) - -2012-10-03 16:42:05,908 - [INFO] - from application in play-akka.actor.default-dispatcher-1 -Application shutdown... - -2012-10-03 16:42:05,926 - [INFO] - from play in play-akka.actor.default-dispatcher-1 +2012-10-03 23:55:53,125 - [INFO] - from play in play-akka.actor.default-dispatcher-2 Application started (Dev) -2012-10-03 16:42:06,744 - [ERROR] - from application in play-akka.actor.actions-dispatcher-8 - - -! @6bpi0n84c - Internal server error, for request [GET /claims/browse/10] -> - -play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[FastNoSuchElementException: null]] - at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.3] - at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.3] - at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2] - at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.3] - at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2] - at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2] - at akka.dispatch.Mailbox.run(Mailbox.scala:179) [akka-actor.jar:2.0.2] - at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516) [akka-actor.jar:2.0.2] - at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) [akka-actor.jar:2.0.2] - at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) [akka-actor.jar:2.0.2] - at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479) [akka-actor.jar:2.0.2] - at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) [akka-actor.jar:2.0.2] -com.tinkerpop.pipes.util.FastNoSuchElementException: null - -2012-10-03 16:43:42,491 - [INFO] - from application in play-akka.actor.default-dispatcher-1 -Application shutdown... - -2012-10-03 16:43:42,508 - [INFO] - from play in play-akka.actor.default-dispatcher-1 -Application started (Dev) - -2012-10-03 16:52:28,593 - [INFO] - from application in play-akka.actor.default-dispatcher-1 -Application shutdown... - -2012-10-03 16:52:28,609 - [INFO] - from play in play-akka.actor.default-dispatcher-1 -Application started (Dev) - -2012-10-03 16:54:26,214 - [INFO] - from application in play-akka.actor.default-dispatcher-1 -Application shutdown... - -2012-10-03 16:54:26,229 - [INFO] - from play in play-akka.actor.default-dispatcher-1 -Application started (Dev) - diff -r 5d422941b702 -r 5f7fcdf98380 target/.history --- a/target/.history Wed Oct 03 18:43:49 2012 +0900 +++ b/target/.history Thu Oct 04 00:01:40 2012 +0900 @@ -3,3 +3,11 @@ run ~ run ~ run +run +console +help +help comand +help command +help command* +play starting +run diff -r 5d422941b702 -r 5f7fcdf98380 target/scala-2.9.1/cache/compile/copy-resources Binary file target/scala-2.9.1/cache/compile/copy-resources has changed diff -r 5d422941b702 -r 5f7fcdf98380 test/RequestTest.java --- a/test/RequestTest.java Wed Oct 03 18:43:49 2012 +0900 +++ b/test/RequestTest.java Thu Oct 04 00:01:40 2012 +0900 @@ -28,6 +28,11 @@ String[] users2 = {user2}; createClaim(user1, users2); JsonNode user1Claim = getUserInfo(user1,"consensus/"); + getClaimInfo(user1Claim.get(0).asInt()); + editClaimInfo(user1, users2, user1Claim.get(0).asInt()); + getClaimInfo(user1Claim.get(0).asInt()); + +/* String[] users3 = {user1}; for (int i=0; i