view app/models/ClaimModel.java @ 29:fbb232e78422

create getClaimInfo
author one
date Wed, 03 Oct 2012 13:28:00 +0900
parents 7112b826a53a
children 80b5628f17d8
line wrap: on
line source

package models;

import java.util.ArrayList;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.ObjectNode;

import play.libs.Json;

import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.gremlin.java.GremlinPipeline;

public class ClaimModel extends NodeModel {

	
	public ClaimModel(Vertex vertex) {
		super(vertex);
	}
	
		
	public ObjectNode getClaimInfoFromGraph() {
		
		ObjectNode property = Json.newObject();
		property.put(TYPE, Json.toJson(getProperty(TYPE)));
		property.put(STATUS, Json.toJson(getProperty(STATUS)));
		property.put(TOULMIN, Json.toJson(getProperty(TOULMIN)));
		
		property.put(L_AUTHOR, Json.toJson(getAuthor()));
		property.put(MENTIONS, Json.toJson(getMentions()));
		property.put(USERS, Json.toJson(getUsers()));
		
		return property;
	}
	
	public Object getAuthor() {
		GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
		pipe.start(vertex).out(L_AUTHOR);
		if (pipe.hasNext()) return null;
		Vertex authorV = pipe.next();
		return authorV.getId();
	}
	
	public Object[] getMentions() {
		GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
		pipe.start(vertex).out(L_QUESTION,L_REFUTATION,L_SUGGESTION);
		ArrayList<Object> array = new ArrayList<Object>();
		for (Vertex v : pipe) array.add(v.getId());
		if (array.size() == 0) return null;
		return array.toArray();
	}
	
	public Object[] getUsers() {
		GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
		pipe.start(vertex).out(L_REQUEST);
		ArrayList<Object> array = new ArrayList<Object>();
		for (Vertex v : pipe) array.add(v.getId());
		if (array.size() == 0) return null;
		return array.toArray();
	}
	
	
	
	public void setClaimProperties(JsonNode toulmin, String type) {
		String title = toulmin.findPath(TITLE).getTextValue();
		String contents = toulmin.findPath(CONTENTS).getTextValue();
		String q = toulmin.findPath(QUALIFIER).getTextValue(); // Qualifier
		String d = toulmin.findPath(DATA).getTextValue(); // Data
		String w = toulmin.findPath(WARRANT).getTextValue(); // Warrant
		String b = toulmin.findPath(BACKING).getTextValue(); // Backing
		String r = toulmin.findPath(REBUTTLE).getTextValue(); // Rebuttle

		ObjectNode t = Json.newObject();
		t.put(TITLE, title);
		t.put(CONTENTS, contents);
		t.put(QUALIFIER, q);
		t.put(DATA, d);
		t.put(WARRANT, w);
		t.put(BACKING, b);
		t.put(REBUTTLE, r);

		setProperty(TYPE, type);
		setProperty(STATUS, FAIL); // Default Status is fail.
		setProperty(TOULMIN, t);
	}
	
	public void setClaimMention(String label) {
		
		
	}

	
	
}