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.Server; import be.cytomine.client.User; import org.json.simple.JSONObject; /** * A cytomine human user * * @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 AbstractUser 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 username of the user * */ protected String username; /** * If true, user is a userjob * */ protected Boolean algo; /** * The firstname of the user * */ protected String firstname; /** * The lastname of the user * */ protected String lastname; /** * The email of the user * */ protected String email; /** * The SIP account of the user * */ protected String sipAccount; /** * The user public key * */ protected String publicKey; /** * The user private key * */ protected String privateKey; /** * If true, password is expired * */ protected Boolean passwordExpired; /** * Undefined * */ protected Object color; /** * If true, account is expired * */ protected Boolean accountExpired; /** * If true, account is locked * */ protected Boolean accountLocked; /** * (ONLY VISIBLE WHEN DOING GET /api/user/id.format service) True if the user is ADMIN * */ protected Boolean admin; /** * If true, account is enabled * */ protected Boolean enabled; /** * (ONLY VISIBLE WHEN DOING GET /api/user/id.format service) True if the user is NOT ADMIN, NOT USER but a simple GHEST * */ protected Boolean ghest; /** * The user password * */ protected String password; /** * The skype account of the user * */ protected String skypeAccount; /** * (ONLY VISIBLE WHEN DOING GET /api/user/id.format service) True if the user is NOT ADMIN and is USER * */ protected Boolean user; /** * * @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 username of the user */ public String getUsername() throws Exception { return username; } /** * * @param username * The username of the user */ public void setUsername(String username) throws Exception { this.username = username; } /** * * @return * If true, user is a userjob */ public Boolean getAlgo() throws Exception { return algo; } /** * * @return * The firstname of the user */ public String getFirstname() throws Exception { return firstname; } /** * * @param firstname * The firstname of the user */ public void setFirstname(String firstname) throws Exception { this.firstname = firstname; } /** * * @return * The lastname of the user */ public String getLastname() throws Exception { return lastname; } /** * * @param lastname * The lastname of the user */ public void setLastname(String lastname) throws Exception { this.lastname = lastname; } /** * * @return * The email of the user */ public String getEmail() throws Exception { return email; } /** * * @param email * The email of the user */ public void setEmail(String email) throws Exception { this.email = email; } /** * * @return * The SIP account of the user */ public String getSipAccount() throws Exception { return sipAccount; } /** * * @param sipAccount * The SIP account of the user */ public void setSipAccount(String sipAccount) throws Exception { this.sipAccount = sipAccount; } /** * * @return * The user public key */ public String getPublicKey() throws Exception { return publicKey; } /** * * @param publicKey * The user public key */ public void setPublicKey(String publicKey) throws Exception { this.publicKey = publicKey; } /** * * @return * The user private key */ public String getPrivateKey() throws Exception { return privateKey; } /** * * @param privateKey * The user private key */ public void setPrivateKey(String privateKey) throws Exception { this.privateKey = privateKey; } /** * * @return * Undefined */ public Object getColor() throws Exception { return color; } /** * * @param color * Undefined */ public void setColor(Object color) throws Exception { this.color = color; } /** * * @param password * The user password */ public void setPassword(String password) throws Exception { this.password = password; } /** * * @param skypeAccount * The skype account of the user */ public void setSkypeAccount(String skypeAccount) throws Exception { this.skypeAccount = skypeAccount; } public void build(String username, String firstname, String lastname, String email, String sipAccount, String password, String skypeAccount) throws Exception { this.username=username; this.firstname=firstname; this.lastname=lastname; this.email=email; this.sipAccount=sipAccount; this.password=password; this.skypeAccount=skypeAccount; } 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.username =JSONUtils.extractJSONString(json.get("username")); this.algo =JSONUtils.extractJSONBoolean(json.get("algo")); this.firstname =JSONUtils.extractJSONString(json.get("firstname")); this.lastname =JSONUtils.extractJSONString(json.get("lastname")); this.email =JSONUtils.extractJSONString(json.get("email")); this.sipAccount =JSONUtils.extractJSONString(json.get("sipAccount")); this.publicKey =JSONUtils.extractJSONString(json.get("publicKey")); this.privateKey =JSONUtils.extractJSONString(json.get("privateKey")); this.passwordExpired =JSONUtils.extractJSONBoolean(json.get("passwordExpired")); this.color =JSONUtils.extractJSONObject(json.get("color")); this.accountExpired =JSONUtils.extractJSONBoolean(json.get("accountExpired")); this.accountLocked =JSONUtils.extractJSONBoolean(json.get("accountLocked")); this.admin =JSONUtils.extractJSONBoolean(json.get("admin")); this.enabled =JSONUtils.extractJSONBoolean(json.get("enabled")); this.ghest =JSONUtils.extractJSONBoolean(json.get("ghest")); this.password =JSONUtils.extractJSONString(json.get("password")); this.skypeAccount =JSONUtils.extractJSONString(json.get("skypeAccount")); this.user =JSONUtils.extractJSONBoolean(json.get("user")); } 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("username",JSONUtils.formatJSON(this.username)); json.put("algo",JSONUtils.formatJSON(this.algo)); json.put("firstname",JSONUtils.formatJSON(this.firstname)); json.put("lastname",JSONUtils.formatJSON(this.lastname)); json.put("email",JSONUtils.formatJSON(this.email)); json.put("sipAccount",JSONUtils.formatJSON(this.sipAccount)); json.put("publicKey",JSONUtils.formatJSON(this.publicKey)); json.put("privateKey",JSONUtils.formatJSON(this.privateKey)); json.put("color",JSONUtils.formatJSON(this.color)); return json; } public static User get(Server server, Object id) throws Exception { String path = "/api/user/{id}.json?"; path = path.replace("{id}",id+""); JSONObject json = server.doGET(path); User domain = new User(); domain.build(json); return domain; } public static User showByProject(Server server, Long id, Boolean online, Integer max, Integer offset) throws Exception { throw new Exception("Not yet implemented"); } public static User showAdminByProject(Server server, Long id, Integer max, Integer offset) throws Exception { throw new Exception("Not yet implemented"); } public static User showCreatorByProject(Server server, Long id, Integer max, Integer offset) throws Exception { throw new Exception("Not yet implemented"); } public static User showCreatorByOntology(Server server, Long id, Integer max, Integer offset) throws Exception { throw new Exception("Not yet implemented"); } public static User showUserByOntology(Server server, Long id, Integer max, Integer offset) throws Exception { throw new Exception("Not yet implemented"); } public static User showLayerByProject(Server server, Long id, Long image, Integer max, Integer offset) throws Exception { throw new Exception("Not yet implemented"); } public static User showCurrent(Server server) throws Exception { throw new Exception("Not yet implemented"); } public static Object addUserToProject(Server server, Long id, Long idUser) throws Exception { throw new Exception("Not yet implemented"); } public static Object deleteUserFromProject(Server server, Long id, Long idUser) throws Exception { throw new Exception("Not yet implemented"); } public static Object addUserAdminToProject(Server server, Long id, Long idUser) throws Exception { throw new Exception("Not yet implemented"); } public static Object deleteUserAdminFromProject(Server server, Long id, Long idUser) throws Exception { throw new Exception("Not yet implemented"); } public static User resetPassword(Server server, Long id, String password) throws Exception { throw new Exception("Not yet implemented"); } public static List listFriends(Server server, Long id, Long project, Boolean offline) throws Exception { String path = "/api/user/{id}/friends.json?"; path = path.replace("{id}",id+""); path = path + "&project=" + project; path = path + "&offline=" + offline; JSONArray json = server.doGETList(path); List<User> domains = new ArrayList<User>(); for(int i=0;i<json.size();i++) { User domain = new User(); domain.build((JSONObject)json.get(i)); domains.add(domain); } return domains; } public static List listFriends(Server server, Long id, Long project, Boolean offline, Integer max, Integer offset) throws Exception { String path = "/api/user/{id}/friends.json?"; path = path.replace("{id}",id+""); path = path + "&project=" + project; path = path + "&offline=" + offline; path = path + "&max=" + max; path = path + "&offset=" + offset; JSONArray json = server.doGETList(path); List<User> domains = new ArrayList<User>(); for(int i=0;i<json.size();i++) { User domain = new User(); domain.build((JSONObject)json.get(i)); domains.add(domain); } return domains; } public static Object listOnlineFriendsWithPosition(Server server, Long id, Integer max, Integer offset) throws Exception { throw new Exception("Not yet implemented"); } public static User addFromLDAP(Server server, Long username, Integer max, Integer offset) throws Exception { throw new Exception("Not yet implemented"); } public static Object signature(Server server, String method, String content_MD5, String content_type, String date, String queryString, String forwardURI) throws Exception { throw new Exception("Not yet implemented"); } public void add(Server server) throws Exception { String path = "/api/user.json?"; JSONObject json = server.doPOST(path,this.toJSON()); this.build((JSONObject)json.get("user")); } public static List list(Server server, String publicKey) throws Exception { String path = "/api/user.json?"; path = path + "&publicKey=" + publicKey; JSONArray json = server.doGETList(path); List<User> domains = new ArrayList<User>(); for(int i=0;i<json.size();i++) { User domain = new User(); domain.build((JSONObject)json.get(i)); domains.add(domain); } return domains; } public static List list(Server server, String publicKey, Integer max, Integer offset) throws Exception { String path = "/api/user.json?"; path = path + "&publicKey=" + publicKey; path = path + "&max=" + max; path = path + "&offset=" + offset; JSONArray json = server.doGETList(path); List<User> domains = new ArrayList<User>(); for(int i=0;i<json.size();i++) { User domain = new User(); domain.build((JSONObject)json.get(i)); domains.add(domain); } return domains; } public static Object keys(Server server, Long id, String publicKey) throws Exception { throw new Exception("Not yet implemented"); } public void delete(Server server) throws Exception { String path = "/api/user/{id}.json?"; path = path.replace("{id}",getId()+""); server.doDELETE(path); build(new JSONObject()); } public void edit(Server server) throws Exception { String path = "/api/user/{id}.json?"; path = path.replace("{id}",getId()+""); JSONObject json = server.doPUT(path,this.toJSON()); this.build((JSONObject)json.get("user")); } }