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 java.util.Map; import be.cytomine.client.Ontology; import be.cytomine.client.Server; import org.json.simple.JSONObject; /** * An ontology is a list of term. Each term may be link to other term with a special relation (parent, synonym,...) * * @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 AbstractOntology 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 name of the ontology * */ protected String name; /** * The author of the ontology * */ protected Long user; /** * Undefined * */ protected Object title; /** * Undefined * */ protected Object attr; /** * Undefined * */ protected Object data; /** * Undefined * */ protected Object isFolder; /** * Undefined * */ protected Object key; /** * Undefined * */ protected Object hideCheckbox; /** * Undefined * */ protected Object state; /** * Undefined * */ protected Object projects; /** * Term Tree * */ protected Map children; /** * * @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 name of the ontology */ public String getName() throws Exception { return name; } /** * * @param name * The name of the ontology */ public void setName(String name) throws Exception { this.name = name; } /** * * @return * The author of the ontology */ public Long getUser() throws Exception { return user; } /** * * @param user * The author of the ontology */ public void setUser(Long user) throws Exception { this.user = user; } /** * * @return * Undefined */ public Object getTitle() throws Exception { return title; } /** * * @param title * Undefined */ public void setTitle(Object title) throws Exception { this.title = title; } /** * * @return * Undefined */ public Object getAttr() throws Exception { return attr; } /** * * @param attr * Undefined */ public void setAttr(Object attr) throws Exception { this.attr = attr; } /** * * @return * Undefined */ public Object getData() throws Exception { return data; } /** * * @param data * Undefined */ public void setData(Object data) throws Exception { this.data = data; } /** * * @return * Undefined */ public Object getIsFolder() throws Exception { return isFolder; } /** * * @param isFolder * Undefined */ public void setIsFolder(Object isFolder) throws Exception { this.isFolder = isFolder; } /** * * @return * Undefined */ public Object getKey() throws Exception { return key; } /** * * @param key * Undefined */ public void setKey(Object key) throws Exception { this.key = key; } /** * * @return * Undefined */ public Object getHideCheckbox() throws Exception { return hideCheckbox; } /** * * @param hideCheckbox * Undefined */ public void setHideCheckbox(Object hideCheckbox) throws Exception { this.hideCheckbox = hideCheckbox; } /** * * @return * Undefined */ public Object getState() throws Exception { return state; } /** * * @param state * Undefined */ public void setState(Object state) throws Exception { this.state = state; } /** * * @return * Undefined */ public Object getProjects() throws Exception { return projects; } /** * * @param projects * Undefined */ public void setProjects(Object projects) throws Exception { this.projects = projects; } /** * * @return * Term Tree */ public Map getChildren() throws Exception { return children; } public void build(String name, Long user) throws Exception { this.name=name; this.user=user; } 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.name =JSONUtils.extractJSONString(json.get("name")); this.user =JSONUtils.extractJSONLong(json.get("user")); this.title =JSONUtils.extractJSONObject(json.get("title")); this.attr =JSONUtils.extractJSONObject(json.get("attr")); this.data =JSONUtils.extractJSONObject(json.get("data")); this.isFolder =JSONUtils.extractJSONObject(json.get("isFolder")); this.key =JSONUtils.extractJSONObject(json.get("key")); this.hideCheckbox =JSONUtils.extractJSONObject(json.get("hideCheckbox")); this.state =JSONUtils.extractJSONObject(json.get("state")); this.projects =JSONUtils.extractJSONObject(json.get("projects")); this.children =JSONUtils.extractJSONMap(json.get("children")); } 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("name",JSONUtils.formatJSON(this.name)); json.put("user",JSONUtils.formatJSON(this.user)); json.put("title",JSONUtils.formatJSON(this.title)); json.put("attr",JSONUtils.formatJSON(this.attr)); json.put("data",JSONUtils.formatJSON(this.data)); json.put("isFolder",JSONUtils.formatJSON(this.isFolder)); json.put("key",JSONUtils.formatJSON(this.key)); json.put("hideCheckbox",JSONUtils.formatJSON(this.hideCheckbox)); json.put("state",JSONUtils.formatJSON(this.state)); json.put("projects",JSONUtils.formatJSON(this.projects)); json.put("children",JSONUtils.formatJSON(this.children)); return json; } public static Ontology get(Server server, Long id) throws Exception { String path = "/api/ontology/{id}.json?"; path = path.replace("{id}",id+""); JSONObject json = server.doGET(path); Ontology domain = new Ontology(); domain.build(json); return domain; } public void add(Server server) throws Exception { String path = "/api/ontology.json?"; JSONObject json = server.doPOST(path,this.toJSON()); this.build((JSONObject)json.get("ontology")); } public static List list(Server server, Boolean light) throws Exception { String path = "/api/ontology.json?"; path = path + "&light=" + light; JSONArray json = server.doGETList(path); List<Ontology> domains = new ArrayList<Ontology>(); for(int i=0;i<json.size();i++) { Ontology domain = new Ontology(); domain.build((JSONObject)json.get(i)); domains.add(domain); } return domains; } public static List list(Server server, Boolean light, Integer max, Integer offset) throws Exception { String path = "/api/ontology.json?"; path = path + "&light=" + light; path = path + "&max=" + max; path = path + "&offset=" + offset; JSONArray json = server.doGETList(path); List<Ontology> domains = new ArrayList<Ontology>(); for(int i=0;i<json.size();i++) { Ontology domain = new Ontology(); domain.build((JSONObject)json.get(i)); domains.add(domain); } return domains; } public void delete(Server server) throws Exception { String path = "/api/ontology/{id}.json?"; path = path.replace("{id}",getId()+""); path = path.replace("{task}",getTask()+""); server.doDELETE(path); build(new JSONObject()); } public void edit(Server server) throws Exception { String path = "/api/ontology/{id}.json?"; path = path.replace("{id}",getId()+""); JSONObject json = server.doPUT(path,this.toJSON()); this.build((JSONObject)json.get("ontology")); } }