Mercurial > hg > Members > nobuyasu > Consensus
changeset 82:cddb5ed942a6 draft
modified copyConsensusTree method
author | one |
---|---|
date | Sat, 09 Mar 2013 21:26:40 +0900 |
parents | 3ebc3061f869 |
children | c6929060c85f |
files | app/controllers/Claim.java app/models/ClaimModel.java app/models/TPGraph.java app/models/UserModel.java |
diffstat | 4 files changed, 23 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/app/controllers/Claim.java Fri Mar 08 21:12:37 2013 +0900 +++ b/app/controllers/Claim.java Sat Mar 09 21:26:40 2013 +0900 @@ -155,16 +155,6 @@ return created(); } - public static Result copyClaims(String id) { - TPGraph tpGraph = TPGraph.getInstance(); - ClaimModel claim = new ClaimModel(tpGraph.getVertex(id)); - if ( claim.getVertex() == null) { - return badRequest("Claim id " + id + " does not exist."); - } - tpGraph.copyConsensusTree(claim); - return ok("copy success"); - } - public static Result getClaimInfo(String id) { TPGraph tpGraph = TPGraph.getInstance(); Vertex claimV = tpGraph.getVertex(id); @@ -189,6 +179,17 @@ return ok(resultEntity); } + public static Result copyClaims(String id) { + TPGraph tpGraph = TPGraph.getInstance(); + ClaimModel claim = new ClaimModel(tpGraph.getVertex(id)); + if (claim.getVertex() == null) { + return badRequest("Claim id " + id + " does not exist."); + } + String timestamp = Long.toString(System.currentTimeMillis()); + tpGraph.copyConsensusTree(claim, timestamp); + return ok("copy success"); + } + private static Object[] toStringObject(JsonNode jsonNode) { if (jsonNode == null) { return null;
--- a/app/models/ClaimModel.java Fri Mar 08 21:12:37 2013 +0900 +++ b/app/models/ClaimModel.java Sat Mar 09 21:26:40 2013 +0900 @@ -448,13 +448,11 @@ return newClaim; } - public ClaimModel cloneAndSetLabelPrev() { + public ClaimModel cloneAndSetLabelPrev(String timestamp) { ClaimModel newClaim = this.clone(); + newClaim.setProperty(TIMESTAMP, timestamp); TPGraph tpGraph = TPGraph.getInstance(); tpGraph.setLabelPrev(newClaim, this); return newClaim; } - - - }
--- a/app/models/TPGraph.java Fri Mar 08 21:12:37 2013 +0900 +++ b/app/models/TPGraph.java Sat Mar 09 21:26:40 2013 +0900 @@ -210,8 +210,6 @@ } return set.toArray(); } - - /* * Return CLAIM numbers of above [id] CLAIM. @@ -255,32 +253,30 @@ return v; } - private void recursiveCopyDownClaimsAndSetLabel(ClaimModel oldUpClaim, ClaimModel latestUpClaim, String... labels) { + private void recursiveCopyDownClaimsAndSetLabel(ClaimModel oldUpClaim, ClaimModel latestUpClaim, + String timestamp, String... labels) { for (String label: labels) { GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); pipe.start(oldUpClaim.getVertex()).out(label); for (Vertex oldDownV : pipe) { ClaimModel oldDownClaim = new ClaimModel(oldDownV); - ClaimModel latestDownClaim = oldDownClaim.cloneAndSetLabelPrev(); + ClaimModel latestDownClaim = oldDownClaim.cloneAndSetLabelPrev(timestamp); setLabel(latestUpClaim.getVertex(), latestDownClaim.getVertex(), label); - recursiveCopyDownClaimsAndSetLabel(oldDownClaim, latestDownClaim, labels); + recursiveCopyDownClaimsAndSetLabel(oldDownClaim, latestDownClaim, timestamp, labels); } } } - private ClaimModel copyDownClaims(ClaimModel oldTopClaim) { - ClaimModel latestTopClaim = oldTopClaim.cloneAndSetLabelPrev(); - recursiveCopyDownClaimsAndSetLabel(oldTopClaim, latestTopClaim, + private ClaimModel copyDownClaims(ClaimModel oldTopClaim, String timestamp) { + ClaimModel latestTopClaim = oldTopClaim.cloneAndSetLabelPrev(timestamp); + recursiveCopyDownClaimsAndSetLabel(oldTopClaim, latestTopClaim, timestamp, NodeModel.L_REFUTATION, NodeModel.L_QUESTION, NodeModel.L_SUGGESTION); return latestTopClaim; } - /* - * TODO: update TimeStamp - */ - public ClaimModel copyConsensusTree(ClaimModel claim) { + public ClaimModel copyConsensusTree(ClaimModel claim, String timestamp) { ClaimModel oldTopClaim = new ClaimModel(getVertex(getTopClaimVertexId(claim.getId()))); - ClaimModel latestTopClaim = copyDownClaims(oldTopClaim); + ClaimModel latestTopClaim = copyDownClaims(oldTopClaim, timestamp); return latestTopClaim; }
--- a/app/models/UserModel.java Fri Mar 08 21:12:37 2013 +0900 +++ b/app/models/UserModel.java Sat Mar 09 21:26:40 2013 +0900 @@ -41,6 +41,7 @@ GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); pipe.start(tpGraph.getVertex(vId)).in(L_PREV); /* + * get latest claims. * c1 <--prev-- c1' <--prev-- c1'' * c1'' is latest. */