# HG changeset patch # User one # Date 1362654495 -32400 # Node ID 9448734399db6467216aedaf8b4b31f17baa5863 # Parent c5ddd2cc52e19c472bf24baf6cc847861e50f9f1 modified copyConsensusTree diff -r c5ddd2cc52e1 -r 9448734399db app/controllers/Claim.java --- a/app/controllers/Claim.java Thu Mar 07 18:40:22 2013 +0900 +++ b/app/controllers/Claim.java Thu Mar 07 20:08:15 2013 +0900 @@ -160,7 +160,7 @@ targetClaim.computeAndUpdateStatus(); return created(); } - + public static Result copyClaims(String id) { TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); @@ -168,13 +168,9 @@ if ( claim.getVertex() == null) { return badRequest("Claim id " + id + " does not exist."); } - ClaimModel topClaim = ClaimModel(graph.getVertex(tpGraph.getTopClaimVertex(id))); - - - return ok(); + tpGraph.copyConsensusTree(claim); + return ok("copy success"); } - - public static Result getClaimInfo(String id) { TPGraph tpGraph = TPGraph.getInstance(); diff -r c5ddd2cc52e1 -r 9448734399db app/models/ClaimModel.java --- a/app/models/ClaimModel.java Thu Mar 07 18:40:22 2013 +0900 +++ b/app/models/ClaimModel.java Thu Mar 07 20:08:15 2013 +0900 @@ -441,7 +441,7 @@ TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); ClaimModel newClaim = new ClaimModel(graph.addVertex(null)); - String author = (this.getProperty(L_AUTHOR)).toString(); + String author = (getAuthorId()).toString(); String type = (this.getProperty(TYPE)).toString(); JsonNode toulmin = (JsonNode)this.getProperty(TOULMIN); newClaim.setClaimProperties(toulmin, type); @@ -450,6 +450,13 @@ return newClaim; } + public ClaimModel cloneAndSetLabelPrev() { + ClaimModel newClaim = this.clone(); + TPGraph tpGraph = TPGraph.getInstance(); + tpGraph.setLabelPrev(newClaim, this); + return newClaim; + } + } diff -r c5ddd2cc52e1 -r 9448734399db app/models/NodeModel.java --- a/app/models/NodeModel.java Thu Mar 07 18:40:22 2013 +0900 +++ b/app/models/NodeModel.java Thu Mar 07 20:08:15 2013 +0900 @@ -9,55 +9,53 @@ protected Vertex vertex; protected Object id; - protected HashMap properties = new HashMap(); + protected HashMap properties = new HashMap(); - public static final String ID = "id"; + public static final String ID = "id"; - - public static final String TYPE = "type"; - public static final String MENTIONS = "mentions"; - public static final String TIMESTAMP = "timestamp"; + public static final String TYPE = "type"; + public static final String MENTIONS = "mentions"; + public static final String TIMESTAMP = "timestamp"; /* - * Edge Labels. + * Edge Labels. */ - public static final String L_AUTHOR = "author"; - public static final String L_REQUEST = "request"; - public static final String L_QUESTION = "question"; - public static final String L_REFUTATION = "refutation"; - public static final String L_SUGGESTION = "suggestion"; + public static final String L_AUTHOR = "author"; + public static final String L_REQUEST = "request"; + public static final String L_QUESTION = "question"; + public static final String L_REFUTATION = "refutation"; + public static final String L_SUGGESTION = "suggestion"; + public static final String L_PREV = "prev"; - public static final String MAJORITY = "majority"; - public static final String UNANIMOUSLY = "unanimously"; - - + public static final String MAJORITY = "majority"; + public static final String UNANIMOUSLY = "unanimously"; + /* * Claim information key. */ - public static final String TOULMIN = "toulmin"; - public static final String TITLE = "title"; - public static final String CONTENTS = "contents"; - public static final String QUALIFIER = "q"; - public static final String DATA = "d"; - public static final String WARRANT = "w"; - public static final String BACKING = "b"; - public static final String REBUTTLE = "r"; - public static final String USERS = "users"; - public static final String STATUS = "status"; - // Status statement - public static final String PASS = "pass"; - public static final String FAILED = "failed"; - public static final String AGREED = "agreed"; - public static final String DENIED = "denied"; - public static final String UNKNOWN = "unknown"; - public static final String PEND = "pend"; - + public static final String TOULMIN = "toulmin"; + public static final String TITLE = "title"; + public static final String CONTENTS = "contents"; + public static final String QUALIFIER = "q"; + public static final String DATA = "d"; + public static final String WARRANT = "w"; + public static final String BACKING = "b"; + public static final String REBUTTLE = "r"; + public static final String USERS = "users"; + public static final String STATUS = "status"; + // Status statement + public static final String PASS = "pass"; + public static final String FAILED = "failed"; + public static final String AGREED = "agreed"; + public static final String DENIED = "denied"; + public static final String UNKNOWN = "unknown"; + public static final String PEND = "pend"; + // Use This key Json Data - public static final String CLAIM = "claim"; - public static final String REQUESTS = "requests"; - public static final String CONSENSUS = "consensus"; - - + public static final String CLAIM = "claim"; + public static final String REQUESTS = "requests"; + public static final String CONSENSUS = "consensus"; + public NodeModel(Vertex vertex) { this.vertex = vertex; if (vertex == null) { @@ -74,11 +72,11 @@ public Object getId() { return this.id; } - + public Vertex getVertex() { return this.vertex; } - + public void setProperty(String key, Object value) { this.vertex.setProperty(key, value); } @@ -86,14 +84,12 @@ public Object getProperty(String key) { return this.vertex.getProperty(key); } - - public HashMap getAllProperty() { + + public HashMap getAllProperty() { for (String key : vertex.getPropertyKeys()) { properties.put(key, vertex.getProperty(key)); } return properties; } - - } diff -r c5ddd2cc52e1 -r 9448734399db app/models/TPGraph.java --- a/app/models/TPGraph.java Thu Mar 07 18:40:22 2013 +0900 +++ b/app/models/TPGraph.java Thu Mar 07 20:08:15 2013 +0900 @@ -241,22 +241,32 @@ return v; } - private void copyDownClaimVertexAndSetLabel(ClaimModel cliam, String label) { - GremlinPipeline pipe = new GremlinPipeline(); - pipe.start(claim.getVertex()).outE(label); - + private void recursiveCopyDownClaimsAndSetLabel(ClaimModel oldUpClaim, ClaimModel latestUpClaim, String... labels) { + for (String label: labels) { + GremlinPipeline pipe = new GremlinPipeline(); + pipe.start(oldUpClaim.getVertex()).out(label); + for (Vertex oldDownV : pipe) { + ClaimModel oldDownClaim = new ClaimModel(oldDownV); + ClaimModel latestDownClaim = oldDownClaim.cloneAndSetLabelPrev(); + setLabel(latestUpClaim.getVertex(), latestDownClaim.getVertex(), label); + recursiveCopyDownClaimsAndSetLabel(oldDownClaim, latestDownClaim, labels); + } + } + } + + private ClaimModel copyDownClaims(ClaimModel oldTopClaim) { + ClaimModel latestTopClaim = oldTopClaim.cloneAndSetLabelPrev(); + recursiveCopyDownClaimsAndSetLabel(oldTopClaim, latestTopClaim, + NodeModel.L_REFUTATION, NodeModel.L_QUESTION, NodeModel.L_SUGGESTION); + return latestTopClaim; } public ClaimModel copyConsensusTree(ClaimModel claim) { - ClaimModel topClaim = new ClaimModel(graph.getVertex(getTopClaimVertexId(claim.getId()))); - - - ClaimModel copiedTopClaim = new ClaimModel(graph.addVertex(null)); - - return copiedTopClaim; + ClaimModel oldTopClaim = new ClaimModel(graph.getVertex(getTopClaimVertexId(claim.getId()))); + ClaimModel latestTopClaim = copyDownClaims(oldTopClaim); + return latestTopClaim; } - public void shutdownGraph() { if (path == null) { return; diff -r c5ddd2cc52e1 -r 9448734399db conf/routes --- a/conf/routes Thu Mar 07 18:40:22 2013 +0900 +++ b/conf/routes Thu Mar 07 20:08:15 2013 +0900 @@ -14,6 +14,7 @@ GET /claims/consensus/:id controllers.Claim.getClaimTree(id: String) GET /consensus/browse/:id controllers.Claim.getClaimTree(id: String) GET /claims/answer/:id/:name controllers.Claim.getUserConsensusStatus(id: String, name: String) +GET /copytree/:id controllers.Claim.copyClaims(id: String) POST /claims/answer/:id/:name/:status controllers.Claim.updateUserConsensusStatus(id: String, name: String, status: String) POST /claims/create controllers.Claim.createClaim() POST /claims/:mentionType/:id/create controllers.Claim.createMention(mentionType: String ,id: String)