package be.cytomine.client.abst;
import be.cytomine.client.*;
import java.util.*;
import org.json.simple.*;
import java.util.Date;
import be.cytomine.client.Server;
import be.cytomine.client.UserGroup;
import org.json.simple.JSONObject;
/**
* Link between a group and a user in database
*
* @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 AbstractUserGroup
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 user id
*
*/
protected Long user;
/**
* The group id
*
*/
protected Long group;
/**
*
* @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 user id
*/
public Long getUser()
throws Exception
{
return user;
}
/**
*
* @param user
* The user id
*/
public void setUser(Long user)
throws Exception
{
this.user = user;
}
/**
*
* @return
* The group id
*/
public Long getGroup()
throws Exception
{
return group;
}
/**
*
* @param group
* The group id
*/
public void setGroup(Long group)
throws Exception
{
this.group = group;
}
public void build(Long user, Long group)
throws Exception
{
this.user=user;
this.group=group;
}
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.user =JSONUtils.extractJSONLong(json.get("user"));
this.group =JSONUtils.extractJSONLong(json.get("group"));
}
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("user",JSONUtils.formatJSON(this.user));
json.put("group",JSONUtils.formatJSON(this.group));
return json;
}
public static UserGroup get(Server server, Long user, Long group)
throws Exception
{
String path = "/api/user/{user}/group/{group}.json?";
path = path.replace("{user}",user+"");
path = path.replace("{group}",group+"");
JSONObject json = server.doGET(path);
UserGroup domain = new UserGroup();
domain.build(json);
return domain;
}
public void add(Server server)
throws Exception
{
String path = "/api/user/{user}/group.json?";
JSONObject json = server.doPOST(path,this.toJSON());
this.build((JSONObject)json.get("usergroup"));
}
public static UserGroup list(Server server, Long user, Integer max, Integer offset)
throws Exception
{
throw new Exception("Not yet implemented");
}
public void delete(Server server)
throws Exception
{
String path = "/api/user/{user}/group/{group}.json?";
path = path.replace("{user}",getUser()+"");
path = path.replace("{group}",getGroup()+"");
server.doDELETE(path);
build(new JSONObject());
}
}