Mercurial > hg > Members > nobuyasu > Consensus
changeset 60:589bc7c508cc
add initialData method
author | one |
---|---|
date | Tue, 13 Nov 2012 03:41:28 +0900 |
parents | e2b703e173ab |
children | 0268b4239da1 |
files | app/Global.java |
diffstat | 1 files changed, 77 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/app/Global.java Mon Nov 12 17:43:50 2012 +0900 +++ b/app/Global.java Tue Nov 13 03:41:28 2012 +0900 @@ -1,4 +1,9 @@ +import org.codehaus.jackson.node.ObjectNode; + +import models.ClaimModel; +import models.NodeModel; import models.TPGraph; +import models.UserModel; import com.tinkerpop.blueprints.Graph; import com.tinkerpop.blueprints.Vertex; @@ -6,27 +11,90 @@ import play.Application; import play.GlobalSettings; import play.Logger; +import play.libs.Json; public class Global extends GlobalSettings { @Override public void onStart(Application app) { - TPGraph tpgraph = TPGraph.getInstance(); - tpgraph.setPath("/tmp/data"); - tpgraph.setPath(null); - Graph graph = tpgraph.newGraph(); -// Graph graph = tpgraph.newGraph(); +/* + TPGraph tpGraph = TPGraph.getInstance(); + tpGraph.setPath(null); + Graph graph = tpGraph.getGraph(); + // Graph graph = tpGraph.newGraph(); Vertex claimV = graph.addVertex(null); - tpgraph.setClaimRootId(claimV.getId()); + tpGraph.setClaimRootId(claimV.getId()); Vertex userV = graph.addVertex(null); - tpgraph.setUserRootId(userV.getId()); + tpGraph.setUserRootId(userV.getId()); + */ + initialData(); } @Override public void onStop(Application app) { Logger.info("Application shutdown..."); - TPGraph tpgraph = TPGraph.getInstance(); - tpgraph.shutdownGraph(); + TPGraph tpGraph = TPGraph.getInstance(); + tpGraph.shutdownGraph(); + } + + + public void initialData() { + TPGraph tpGraph = TPGraph.getInstance(); + tpGraph.setPath(null); + Graph graph = tpGraph.newGraph(); + Vertex claimV = graph.addVertex(null); + tpGraph.setClaimRootId(claimV.getId()); + Vertex userV = graph.addVertex(null); + tpGraph.setUserRootId(userV.getId()); + + String user1 = "Takaaki"; + String user2 = "Akifumi"; + String user3 = "Yosiaki"; + + String[] otherUser1 = {user2,user3}; + String[] otherUser2 = {user1,user3}; + String[] otherUser3 = {user1,user2}; + + UserModel user1Model = new UserModel(graph.addVertex(user1)); + UserModel user2Model = new UserModel(graph.addVertex(user2)); + UserModel user3Model = new UserModel(graph.addVertex(user3)); + + tpGraph.setLabelToRootUser(user1Model); + tpGraph.setLabelToRootUser(user2Model); + tpGraph.setLabelToRootUser(user3Model); + + ClaimModel claim1Model = new ClaimModel(graph.addVertex(null)); + tpGraph.setLabelToAuthor(claim1Model, user1); + ObjectNode t1 = createToulmin("アプリでGraphDBを利用する。"); + createClaimSetToulmin(claim1Model, t1, user1, otherUser1); + + } + + private void createClaimSetToulmin(ClaimModel claim, ObjectNode t, String author, String[] users) { + TPGraph tpGraph = TPGraph.getInstance(); + tpGraph.setLabelToAuthor(claim, author); + claim.setProperty(NodeModel.TOULMIN,t); + claim.setProperty(NodeModel.TYPE, NodeModel.UNANIMOUSLY); + claim.setProperty(NodeModel.STATUS, NodeModel.UNKNOWN); + tpGraph.setLabelStatusToUsers(claim, users, NodeModel.L_REQUEST, NodeModel.UNKNOWN); + tpGraph.setLabelToRootClaim(claim); + } + private ObjectNode createToulmin(String title) { + ObjectNode t = Json.newObject(); + t.put(NodeModel.TITLE, title); + t.put(NodeModel.CONTENTS,title); + t.put(NodeModel.QUALIFIER,""); + t.put(NodeModel.DATA,""); + t.put(NodeModel.WARRANT,""); + t.put(NodeModel.BACKING,""); + t.put(NodeModel.REBUTTLE,""); + return t; + } + + + + + }