implemented storing of tasks
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.getPath;
|
||||
import static de.srsoftware.tools.Optionals.nullIfEmpty;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.markdown;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
@@ -34,6 +39,29 @@ public record Task(long id, long projectId, Long parentTaskId, String name, Stri
|
||||
);
|
||||
}
|
||||
|
||||
public static Task of(JSONObject json){
|
||||
if (!(json.has(PROJECT_ID) && json.get(PROJECT_ID) instanceof Number prjId)) throw missingFieldException(PROJECT_ID);
|
||||
Long parentTaskId = json.has(PARENT_TASK_ID) && json.get(PARENT_TASK_ID) instanceof Number ptid ? ptid.longValue() : null;
|
||||
|
||||
if (!(json.has(NAME) && json.get(NAME) instanceof String name && !name.isBlank())) throw missingFieldException(NAME);
|
||||
if (!json.has(DESCRIPTION)) throw missingFieldException(DESCRIPTION);
|
||||
var description = switch (json.get(DESCRIPTION)){
|
||||
case String d -> d;
|
||||
case JSONObject j -> j.getString(SOURCE);
|
||||
default -> throw invalidFieldException(json.get(DESCRIPTION).getClass().getSimpleName(),"String or JSON");
|
||||
};
|
||||
|
||||
var status = Status.OPEN;
|
||||
Double estimatedTime = null; // TODO: provide form field
|
||||
LocalDate startDate = null;
|
||||
LocalDate dueDate = null;
|
||||
var showClosed = json.has(SHOW_CLOSED) && json.get(SHOW_CLOSED) instanceof Boolean sc ? sc : false;
|
||||
var noIndex = json.has(NO_INDEX) && json.get(NO_INDEX) instanceof Boolean ni ? ni : false;
|
||||
|
||||
if (!(json.has(MEMBERS) && json.get(MEMBERS) instanceof JSONObject members)) throw missingFieldException(MEMBERS);
|
||||
return new Task(0,prjId.longValue(),parentTaskId,name,description,status,estimatedTime,startDate,dueDate,showClosed,noIndex,new HashMap<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
var map = new HashMap<String,Object>();
|
||||
|
||||
Reference in New Issue
Block a user