84 lines
1.8 KiB
Java
84 lines
1.8 KiB
Java
package be.jeffcheasey88.todo.model;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map.Entry;
|
|
|
|
import dev.peerat.framework.utils.json.JsonArray;
|
|
import dev.peerat.framework.utils.json.JsonMap;
|
|
|
|
public class Project implements JsonSerializable{
|
|
|
|
private String name;
|
|
private List<String> users;
|
|
private List<Task> tasks;
|
|
|
|
private Map<String, String> states;
|
|
|
|
public Project(){
|
|
this.users = new ArrayList<>();
|
|
this.tasks = new ArrayList<>();
|
|
this.states = new LinkedHashMap<>();
|
|
}
|
|
|
|
public Project(JsonMap json){
|
|
this();
|
|
this.name = json.get("name");
|
|
for(Object user : json.<JsonArray>get("users").toList()){
|
|
this.users.add((String) user);
|
|
}
|
|
for(Object task : json.<JsonArray>get("tasks").toList()){
|
|
this.tasks.add(new Task((JsonMap) task));
|
|
}
|
|
for(Entry<String, Object> entries : json.<JsonMap>get("states").entries()){
|
|
states.put(entries.getKey(), (String) entries.getValue());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void serialize(JsonMap json){
|
|
json.set("name", this.name);
|
|
|
|
JsonArray jUsers = new JsonArray();
|
|
for(String user : users) jUsers.add(user);
|
|
json.set("users", jUsers);
|
|
|
|
JsonArray jTasks = new JsonArray();
|
|
for(Task task : tasks){
|
|
JsonMap jTask = new JsonMap();
|
|
task.serialize(jTask);
|
|
jTasks.add(jTask);
|
|
}
|
|
json.set("tasks", jTasks);
|
|
|
|
JsonMap jstates = new JsonMap();
|
|
for(Entry<String, String> entries : states.entrySet()){
|
|
jstates.set(entries.getKey(), entries.getValue());
|
|
}
|
|
json.set("states", jstates);
|
|
}
|
|
|
|
public String getName(){
|
|
return this.name;
|
|
}
|
|
|
|
public void setName(String name){
|
|
this.name = name;
|
|
}
|
|
|
|
public List<String> getUsers(){
|
|
return this.users;
|
|
}
|
|
|
|
public List<Task> getTasks(){
|
|
return this.tasks;
|
|
}
|
|
|
|
public Map<String, String> getStates(){
|
|
return this.states;
|
|
}
|
|
|
|
}
|