intermediate
This commit is contained in:
@@ -15,13 +15,13 @@ public class Project implements Mappable {
|
||||
private final Map<Long,Member> members;
|
||||
private boolean showClosed;
|
||||
private final Long companyId;
|
||||
private Status status;
|
||||
private int status;
|
||||
private String name;
|
||||
private final long id;
|
||||
private String description;
|
||||
private final Set<String> dirtyFields = new HashSet<>();
|
||||
|
||||
public Project(long id, String name, String description, Status status, Long companyId, boolean showClosed, Map<Long,Member> members) {
|
||||
public Project(long id, String name, String description, int status, Long companyId, boolean showClosed, Map<Long,Member> members) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -81,7 +81,7 @@ public class Project implements Mappable {
|
||||
|
||||
public static Project of(ResultSet rs) throws SQLException {
|
||||
var companyId = rs.getLong(COMPANY_ID);
|
||||
return new Project(rs.getLong(ID),rs.getString(NAME),rs.getString(DESCRIPTION),Status.of(rs.getInt(STATUS)),companyId == 0 ? null : companyId,rs.getBoolean(SHOW_CLOSED),new HashMap<>());
|
||||
return new Project(rs.getLong(ID),rs.getString(NAME),rs.getString(DESCRIPTION),rs.getInt(STATUS),companyId == 0 ? null : companyId,rs.getBoolean(SHOW_CLOSED),new HashMap<>());
|
||||
}
|
||||
|
||||
public Project patch(JSONObject json) {
|
||||
@@ -90,7 +90,7 @@ public class Project implements Mappable {
|
||||
case DESCRIPTION: description = json.getString(key); break;
|
||||
case NAME: name = json.getString(key); break;
|
||||
case SHOW_CLOSED: showClosed = json.getBoolean(SHOW_CLOSED); break;
|
||||
case STATUS: status = json.get(key) instanceof Number number ? Status.of(number.intValue()) : Status.valueOf(json.getString(key)); break;
|
||||
case STATUS: status = json.getInt(key); break;
|
||||
default: key = null;
|
||||
}
|
||||
if (key != null) dirtyFields.add(key);
|
||||
@@ -102,7 +102,7 @@ public class Project implements Mappable {
|
||||
return showClosed;
|
||||
}
|
||||
|
||||
public Status status(){
|
||||
public int status(){
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class Project implements Mappable {
|
||||
map.put(ID,id);
|
||||
map.put(NAME,name);
|
||||
map.put(DESCRIPTION,mapMarkdown(description));
|
||||
map.put(STATUS,Map.of(STATUS_CODE,status.code(), NAME,status.name()));
|
||||
map.put(STATUS,status);
|
||||
map.put(COMPANY_ID,companyId);
|
||||
map.put(SHOW_CLOSED,showClosed);
|
||||
map.put(MEMBERS,memberMap);
|
||||
|
||||
@@ -1,31 +1,22 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
public enum Status{
|
||||
OPEN(10),
|
||||
STARTED(20),
|
||||
PENDING(40),
|
||||
COMPLETE(60),
|
||||
CANCELLED(100);
|
||||
public record Status(String name, int code){
|
||||
public static final Status OPEN = new Status("OPEN",10);
|
||||
public static final Status STARTED = new Status("STARTED",20);
|
||||
public static final Status PENDING = new Status("PENDING", 40);
|
||||
public static final Status COMPLETE = new Status("COMPLETE",60);
|
||||
public static final Status CANCELLED = new Status("CANCELLED", 100);
|
||||
public static final Status[] PREDEFINED = {OPEN, STARTED, PENDING, COMPLETE, CANCELLED};
|
||||
|
||||
private int code;
|
||||
|
||||
Status(int code){
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int code(){
|
||||
return code;
|
||||
}
|
||||
|
||||
public static Status of(int code){
|
||||
return switch (code){
|
||||
case 10 -> OPEN;
|
||||
case 20 -> STARTED;
|
||||
case 40 -> PENDING;
|
||||
case 60 -> COMPLETE;
|
||||
case 100 -> CANCELLED;
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
}
|
||||
}
|
||||
public static Status of(int code){
|
||||
return switch (code){
|
||||
case 10 -> OPEN;
|
||||
case 20 -> STARTED;
|
||||
case 40 -> PENDING;
|
||||
case 60 -> COMPLETE;
|
||||
case 100 -> CANCELLED;
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class Task implements Mappable {
|
||||
private final long id, projectId;
|
||||
private Long parentTaskId;
|
||||
private String description, name;
|
||||
private Status status;
|
||||
private int status;
|
||||
private Double estimatedTime;
|
||||
private LocalDate dueDate, start;
|
||||
private boolean noIndex, showClosed;
|
||||
@@ -28,7 +28,7 @@ public class Task implements Mappable {
|
||||
private final Set<String> dirtyFields = new HashSet<>();
|
||||
|
||||
|
||||
public Task (long id, long projectId, Long parentTaskId, String name, String description, Status status, Double estimatedTime, LocalDate start, LocalDate dueDate, boolean showClosed, boolean noIndex, Map<Long,Member> members){
|
||||
public Task (long id, long projectId, Long parentTaskId, String name, String description, int status, Double estimatedTime, LocalDate start, LocalDate dueDate, boolean showClosed, boolean noIndex, Map<Long,Member> members){
|
||||
this.id = id;
|
||||
this.projectId = projectId;
|
||||
this.parentTaskId = parentTaskId;
|
||||
@@ -109,7 +109,7 @@ public class Task implements Mappable {
|
||||
parentTaskId == 0d ? null : parentTaskId,
|
||||
rs.getString(NAME),
|
||||
rs.getString(DESCRIPTION),
|
||||
Status.of(rs.getInt(STATUS)),
|
||||
rs.getInt(STATUS),
|
||||
estTime == 0d ? null : estTime,
|
||||
startDate != null ? LocalDate.parse(startDate) : null,
|
||||
dueDate != null ? LocalDate.parse(dueDate) : null,
|
||||
@@ -131,10 +131,11 @@ public class Task implements Mappable {
|
||||
default -> throw invalidFieldException(json.get(DESCRIPTION).getClass().getSimpleName(),"String or JSON");
|
||||
};
|
||||
|
||||
var status = Status.OPEN;
|
||||
|
||||
|
||||
var status = Status.OPEN.code();
|
||||
if (json.has(STATUS) && json.get(STATUS) instanceof JSONObject state){
|
||||
if (state.get(CODE) instanceof Number code) status = Status.of(code.intValue());
|
||||
if (state.get(CODE) instanceof String code) status = Status.valueOf(code);
|
||||
if (state.get(CODE) instanceof Number code) status = code.intValue();
|
||||
}
|
||||
Double estimatedTime = null;
|
||||
if (json.has(ESTIMATED_TIME)) {
|
||||
@@ -165,7 +166,7 @@ public class Task implements Mappable {
|
||||
case PARENT_TASK_ID: parentTaskId = json.getLong(PARENT_TASK_ID); break;
|
||||
case SHOW_CLOSED: showClosed = json.getBoolean(SHOW_CLOSED); break;
|
||||
case START_DATE: start = json.isNull(START_DATE) || json.getString(START_DATE).isBlank() ? null : LocalDate.parse(json.getString(START_DATE)); break;
|
||||
case STATUS: status = json.get(key) instanceof Number number ? Status.of(number.intValue()) : Status.valueOf(json.getString(key)); break;
|
||||
case STATUS: status = json.getInt(key); break;
|
||||
default: {
|
||||
LOG.log(WARNING,"Tried to patch field ''{0}'' of task, which is not implemented!",key);
|
||||
key = null;
|
||||
@@ -192,7 +193,7 @@ public class Task implements Mappable {
|
||||
return start;
|
||||
}
|
||||
|
||||
public Status status(){
|
||||
public int status(){
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -208,7 +209,7 @@ public class Task implements Mappable {
|
||||
map.put(PARENT_TASK_ID, parentTaskId);
|
||||
map.put(NAME, name);
|
||||
map.put(DESCRIPTION, mapMarkdown(description));
|
||||
map.put(STATUS, Map.of(NAME,status.name(),STATUS_CODE,status.code()));
|
||||
map.put(STATUS, status);
|
||||
map.put(ESTIMATED_TIME, estimatedTime);
|
||||
map.put(START_DATE,start);
|
||||
map.put(DUE_DATE,dueDate);
|
||||
|
||||
Reference in New Issue
Block a user