package be.cytomine.client.abst;
import be.cytomine.client.*;
import java.util.*;
import org.json.simple.*;
import java.util.Date;
import java.util.List;
import be.cytomine.client.Relation;
import be.cytomine.client.Server;
import org.json.simple.JSONObject;
/**
* Relation between a term 1 , a term 2 and a relantion domain (e.g. term1 PARENT term2)
*
* @author ClientBuilder (Loïc Rollus)
* @version 0.1
*
* DO NOT EDIT THIS FILE. THIS IS CODE IS BUILD AUTOMATICALY. ALL CHANGE WILL BE LOST AFTER NEXT GENERATION.
*
* IF YOU WANT TO EDIT A DOMAIN FILE (change method, add property,...), JUST EDIT THE CHILD FILE “YourDomain.java” instead of this file “AbstractYourDomain.java”. I WON'T BE CLEAR IF IT ALREADY EXIST.
*
*/
public abstract class AbstractRelation
extends AbstractDomain
{
/**
* The full class name of the domain
*
*/
protected String clazz;
/**
* The domain id
*
*/
protected Long id;
/**
* The date of the domain creation
*
*/
protected Date created;
/**
* The date of the domain modification
*
*/
protected Date updated;
/**
* When domain was removed from Cytomine
*
*/
protected Date deleted;
/**
* The relation
*
*/
protected Long relation;
/**
* The first term
*
*/
protected Long term1;
/**
* The second term
*
*/
protected Long term2;
/**
*
* @return
* The full class name of the domain
*/
public String getClazz()
throws Exception
{
return clazz;
}
/**
*
* @return
* The domain id
*/
public Long getId()
throws Exception
{
return id;
}
/**
*
* @return
* The date of the domain creation
*/
public Date getCreated()
throws Exception
{
return created;
}
/**
*
* @return
* The date of the domain modification
*/
public Date getUpdated()
throws Exception
{
return updated;
}
/**
*
* @return
* When domain was removed from Cytomine
*/
public Date getDeleted()
throws Exception
{
return deleted;
}
/**
*
* @return
* The relation
*/
public Long getRelation()
throws Exception
{
return relation;
}
/**
*
* @param relation
* The relation
*/
public void setRelation(Long relation)
throws Exception
{
this.relation = relation;
}
/**
*
* @return
* The first term
*/
public Long getTerm1()
throws Exception
{
return term1;
}
/**
*
* @param term1
* The first term
*/
public void setTerm1(Long term1)
throws Exception
{
this.term1 = term1;
}
/**
*
* @return
* The second term
*/
public Long getTerm2()
throws Exception
{
return term2;
}
/**
*
* @param term2
* The second term
*/
public void setTerm2(Long term2)
throws Exception
{
this.term2 = term2;
}
public void build(Long relation, Long term1, Long term2)
throws Exception
{
this.relation=relation;
this.term1=term1;
this.term2=term2;
}
public void build(JSONObject json)
throws Exception
{
this.clazz =JSONUtils.extractJSONString(json.get("class"));
this.id =JSONUtils.extractJSONLong(json.get("id"));
this.created =JSONUtils.extractJSONDate(json.get("created"));
this.updated =JSONUtils.extractJSONDate(json.get("updated"));
this.deleted =JSONUtils.extractJSONDate(json.get("deleted"));
this.relation =JSONUtils.extractJSONLong(json.get("relation"));
this.term1 =JSONUtils.extractJSONLong(json.get("term1"));
this.term2 =JSONUtils.extractJSONLong(json.get("term2"));
}
public JSONObject toJSON()
throws Exception
{
JSONObject json=new JSONObject();
json.put("class",JSONUtils.formatJSON(this.clazz));
json.put("id",JSONUtils.formatJSON(this.id));
json.put("created",JSONUtils.formatJSON(this.created));
json.put("updated",JSONUtils.formatJSON(this.updated));
json.put("deleted",JSONUtils.formatJSON(this.deleted));
json.put("relation",JSONUtils.formatJSON(this.relation));
json.put("term1",JSONUtils.formatJSON(this.term1));
json.put("term2",JSONUtils.formatJSON(this.term2));
return json;
}
public static Relation get(Server server, Long id)
throws Exception
{
String path = "/api/relation/{id}.json?";
path = path.replace("{id}",id+"");
JSONObject json = server.doGET(path);
Relation domain = new Relation();
domain.build(json);
return domain;
}
public static List list(Server server)
throws Exception
{
String path = "/api/relation.json?";
JSONArray json = server.doGETList(path);
List<Relation> domains = new ArrayList<Relation>();
for(int i=0;i<json.size();i++) {
Relation domain = new Relation();
domain.build((JSONObject)json.get(i));
domains.add(domain);
}
return domains;
}
public static List list(Server server, Integer max, Integer offset)
throws Exception
{
String path = "/api/relation.json?";
path = path + "&max=" + max;
path = path + "&offset=" + offset;
JSONArray json = server.doGETList(path);
List<Relation> domains = new ArrayList<Relation>();
for(int i=0;i<json.size();i++) {
Relation domain = new Relation();
domain.build((JSONObject)json.get(i));
domains.add(domain);
}
return domains;
}
}