package be.cytomine.client.abst;
import be.cytomine.client.*;
import java.util.*;
import org.json.simple.*;
import java.util.Date;
import be.cytomine.client.JobData;
import be.cytomine.client.Server;
import org.json.simple.JSONObject;
/**
* Data created by a job. This concerns only data files (annotation or term are store in domain database). If config cytomine.jobdata.filesystem is true, file are stored in filesystem, otherwise they are store 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 AbstractJobData
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;
/**
* File key (what's the file)
*
*/
protected String key;
/**
* The job that store the data
*
*/
protected Long job;
/**
* Data filename with extension
*
*/
protected String filename;
/**
* Data size (in Bytes)
*
*/
protected Long size;
/**
* File full path if 'cytomine.jobdata.filesystem' config is true
*
*/
protected String dir;
/**
* File data (from blob field) if 'cytomine.jobdata.filesystem' config is false
*
*/
protected Long value;
/**
*
* @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
* File key (what's the file)
*/
public String getKey()
throws Exception
{
return key;
}
/**
*
* @param key
* File key (what's the file)
*/
public void setKey(String key)
throws Exception
{
this.key = key;
}
/**
*
* @return
* The job that store the data
*/
public Long getJob()
throws Exception
{
return job;
}
/**
*
* @param job
* The job that store the data
*/
public void setJob(Long job)
throws Exception
{
this.job = job;
}
/**
*
* @return
* Data filename with extension
*/
public String getFilename()
throws Exception
{
return filename;
}
/**
*
* @param filename
* Data filename with extension
*/
public void setFilename(String filename)
throws Exception
{
this.filename = filename;
}
/**
*
* @return
* Data size (in Bytes)
*/
public Long getSize()
throws Exception
{
return size;
}
public void build(String key, Long job, String filename)
throws Exception
{
this.key=key;
this.job=job;
this.filename=filename;
}
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.key =JSONUtils.extractJSONString(json.get("key"));
this.job =JSONUtils.extractJSONLong(json.get("job"));
this.filename =JSONUtils.extractJSONString(json.get("filename"));
this.size =JSONUtils.extractJSONLong(json.get("size"));
this.dir =JSONUtils.extractJSONString(json.get("dir"));
this.value =JSONUtils.extractJSONLong(json.get("value"));
}
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("key",JSONUtils.formatJSON(this.key));
json.put("job",JSONUtils.formatJSON(this.job));
json.put("filename",JSONUtils.formatJSON(this.filename));
json.put("size",JSONUtils.formatJSON(this.size));
return json;
}
public static JobData get(Server server, Long id)
throws Exception
{
String path = "/api/jobdata/{id}.json?";
path = path.replace("{id}",id+"");
JSONObject json = server.doGET(path);
JobData domain = new JobData();
domain.build(json);
return domain;
}
public static JobData download(Server server, Long id)
throws Exception
{
throw new Exception("Not yet implemented");
}
public static JobData upload(Server server, Long id)
throws Exception
{
throw new Exception("Not yet implemented");
}
public static JobData view(Server server, Long id)
throws Exception
{
throw new Exception("Not yet implemented");
}
public static JobData listByJob(Server server, Long id, Integer max, Integer offset)
throws Exception
{
throw new Exception("Not yet implemented");
}
public void add(Server server)
throws Exception
{
String path = "/api/jobdata.json?";
JSONObject json = server.doPOST(path,this.toJSON());
this.build((JSONObject)json.get("jobdata"));
}
public static JobData list(Server server, Integer max, Integer offset)
throws Exception
{
throw new Exception("Not yet implemented");
}
public void delete(Server server)
throws Exception
{
String path = "/api/jobdata/{id}.json?";
path = path.replace("{id}",getId()+"");
server.doDELETE(path);
build(new JSONObject());
}
public void edit(Server server)
throws Exception
{
String path = "/api/jobdata/{id}.json?";
path = path.replace("{id}",getId()+"");
JSONObject json = server.doPUT(path,this.toJSON());
this.build((JSONObject)json.get("jobdata"));
}
}