
com.github.automately.java.data.Job Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of automately-java Show documentation
Show all versions of automately-java Show documentation
A Scalable Backend Platform
The newest version!
package com.github.automately.java.data;
import io.jsync.json.JsonObject;
import io.jsync.json.impl.Json;
import io.jsync.utils.Token;
import java.util.Date;
public class Job {
private JsonObject config = new JsonObject(); // By default results are empty;
private boolean service = false;
private String serviceName = "";
private JsonObject serviceConfig = new JsonObject();
private String userToken;
private String status = "queued";
private JsonObject results = new JsonObject();
private Date created = new Date();
private Date updated = new Date();
private boolean registered = false;
private String token = Token.generateToken().toHex();
public Job(JsonObject json){
if(json == null){
throw new NullPointerException();
}
this.token = json.getString("token", this.token);
this.userToken = json.getString("userToken", this.userToken);
this.results = json.getObject("results", this.results);
this.config = json.getObject("config", this.config);
this.service = json.getBoolean("service", this.service);
this.serviceName = json.getString("serviceName", this.serviceName);
this.serviceConfig.getObject("serviceConfig", this.serviceConfig);
this.status = json.getString("status", this.status);
// For some reason data didn't work out too well
if(json.getValue("created") instanceof JsonObject &&
json.getObject("created", new JsonObject()).containsField("$numberLong")){
json.putValue("created", Long.valueOf(json.getObject("created", new JsonObject()).getValue("$numberLong")));
}
this.created = new Date(json.getLong("created", created.getTime()));
// For some reason data didn't work out too well
if(json.getValue("updated") instanceof JsonObject &&
json.getObject("updated", new JsonObject()).containsField("$numberLong")){
json.putValue("updated", Long.valueOf(json.getObject("updated", new JsonObject()).getValue("$numberLong")));
}
this.updated = new Date(json.getLong("updated", updated.getTime()));
this.registered = json.getBoolean("registered", registered);
}
public boolean isService(){
return service;
}
public String getServiceName(){
return serviceName;
}
public JsonObject getServiceConfig(){
return serviceConfig;
}
public String getUserToken(){
return userToken;
}
public String getStatus(){
return status;
}
public JsonObject getResults(){
return results;
}
public Date getCreated(){
return created;
}
public Date getUpdated(){
return updated;
}
public String getToken(){
return token;
}
public boolean isRegistered(){
return registered;
}
public JsonObject toJson() {
JsonObject ret = new JsonObject(Json.encode(this));
ret.putNumber("created", created.getTime());
ret.putNumber("updated", updated.getTime());
ret.putString("token", token);
ret.putObject("config", config);
ret.putObject("results", results);
ret.putObject("serviceConfig", serviceConfig);
return ret;
}
@Override
public String toString(){
return toJson().encode();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy