Merge branch 'main' into dev
This commit is contained in:
@@ -98,7 +98,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.getInt(key); break;
|
||||
case STATUS: status = json.get(key) instanceof Number state ? json.getInt(key) : Status.matching(json.getString(key)).code(); break;
|
||||
case TAG_COLORS:
|
||||
tagColors.clear();
|
||||
json.getJSONObject(TAG_COLORS).toMap().forEach((k,v) -> tagColors.put(k,v.toString()));
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.CODE;
|
||||
import static de.srsoftware.umbrella.core.Constants.NAME;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public record Status(String name, int code) implements Mappable {
|
||||
public static final Status PENDING = new Status("PENDING", 10); // was 40
|
||||
@@ -18,6 +19,17 @@ public record Status(String name, int code) implements Mappable {
|
||||
public static final Status CANCELLED = new Status("CANCELLED", 100);
|
||||
public static final List<Status> PREDEFINED = List.of(OPEN, STARTED, PENDING, COMPLETE, CANCELLED);
|
||||
|
||||
public static Status matching(String name){
|
||||
return switch (name.toLowerCase()){
|
||||
case "pending" -> PENDING;
|
||||
case "open" -> OPEN;
|
||||
case "started" -> STARTED;
|
||||
case "complete" -> COMPLETE;
|
||||
case "cancelled" -> CANCELLED;
|
||||
case null, default -> throw invalidFieldException(STATUS,"one of: "+PREDEFINED.stream().map(Status::name).collect(Collectors.joining(", ")));
|
||||
};
|
||||
}
|
||||
|
||||
public static Status of(int code){
|
||||
return switch (code){
|
||||
case 10 -> PENDING;
|
||||
|
||||
Reference in New Issue
Block a user