package be.cytomine.client.abst; import be.cytomine.client.*; import java.util.*; import org.json.simple.*; import java.util.Date; import be.cytomine.client.SecUserSecRole; import be.cytomine.client.Server; import org.json.simple.JSONObject; /** * User - role link. A user may have many role (USER, ADMIN, GUEST) * * @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 AbstractSecUserSecRole 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; /** * Undefined * */ protected Object user; /** * Undefined * */ protected Object role; /** * The role id * */ protected Long secRole; /** * The user id * */ protected Long secUser; /** * * @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 * Undefined */ public Object getUser() throws Exception { return user; } /** * * @param user * Undefined */ public void setUser(Object user) throws Exception { this.user = user; } /** * * @return * Undefined */ public Object getRole() throws Exception { return role; } /** * * @param role * Undefined */ public void setRole(Object role) throws Exception { this.role = role; } /** * * @param secRole * The role id */ public void setSecRole(Long secRole) throws Exception { this.secRole = secRole; } /** * * @param secUser * The user id */ public void setSecUser(Long secUser) throws Exception { this.secUser = secUser; } public void build(Long secRole, Long secUser) throws Exception { this.secRole=secRole; this.secUser=secUser; } 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.extractJSONObject(json.get("user")); this.role =JSONUtils.extractJSONObject(json.get("role")); this.secRole =JSONUtils.extractJSONLong(json.get("secRole")); this.secUser =JSONUtils.extractJSONLong(json.get("secUser")); } 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("role",JSONUtils.formatJSON(this.role)); return json; } public static SecUserSecRole get(Server server, String user, String role) throws Exception { String path = "/api/user/{user}/role/{role}.json?"; path = path.replace("{user}",user+""); path = path.replace("{role}",role+""); JSONObject json = server.doGET(path); SecUserSecRole domain = new SecUserSecRole(); domain.build(json); return domain; } public void add(Server server) throws Exception { String path = "/api/user/{user}/role.json?"; path = path.replace("{user}",getUser()+""); path = path.replace("{role}",getRole()+""); JSONObject json = server.doPOST(path,this.toJSON()); this.build((JSONObject)json.get("secusersecrole")); } public static SecUserSecRole list(Server server, String 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}/role/{role}.json?"; path = path.replace("{user}",getUser()+""); path = path.replace("{role}",getRole()+""); server.doDELETE(path); build(new JSONObject()); } }