working on custom states for projects
This commit is contained in:
@@ -10,6 +10,7 @@ public class Constants {
|
||||
private Constants(){}
|
||||
|
||||
public static final String ADDRESS = "address";
|
||||
public static final String ALLOWED_STATES = "allowed_states";
|
||||
public static final String ATTACHMENTS = "attachments";
|
||||
public static final String AUTHORIZATION = "Authorization";
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ package de.srsoftware.umbrella.core.model;
|
||||
import static de.srsoftware.tools.Optionals.nullable;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||
import static de.srsoftware.umbrella.core.model.Status.PREDEFINED;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import java.sql.ResultSet;
|
||||
@@ -13,6 +14,7 @@ import org.json.JSONObject;
|
||||
|
||||
public class Project implements Mappable {
|
||||
private final Map<Long,Member> members;
|
||||
private final Collection<Status> allowedStates;
|
||||
private boolean showClosed;
|
||||
private final Long companyId;
|
||||
private int status;
|
||||
@@ -21,7 +23,7 @@ public class Project implements Mappable {
|
||||
private String description;
|
||||
private final Set<String> dirtyFields = new HashSet<>();
|
||||
|
||||
public Project(long id, String name, String description, int 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, Collection<Status> allowedStates) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -29,6 +31,11 @@ public class Project implements Mappable {
|
||||
this.companyId = companyId;
|
||||
this.showClosed = showClosed;
|
||||
this.members = members;
|
||||
this.allowedStates = allowedStates;
|
||||
}
|
||||
|
||||
public Collection<Status> allowedStates(){
|
||||
return allowedStates;
|
||||
}
|
||||
|
||||
public Project clean() {
|
||||
@@ -81,7 +88,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),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<>(),PREDEFINED);
|
||||
}
|
||||
|
||||
public Project patch(JSONObject json) {
|
||||
@@ -120,6 +127,9 @@ public class Project implements Mappable {
|
||||
map.put(COMPANY_ID,companyId);
|
||||
map.put(SHOW_CLOSED,showClosed);
|
||||
map.put(MEMBERS,memberMap);
|
||||
var stateMap = new HashMap<Integer,String>();
|
||||
for (var state : allowedStates) stateMap.put(state.code(),state.name());
|
||||
map.put(ALLOWED_STATES,stateMap);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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};
|
||||
public static final List<Status> PREDEFINED = new ArrayList<>(List.of(OPEN, STARTED, PENDING, COMPLETE, CANCELLED));
|
||||
|
||||
public static Status of(int code){
|
||||
return switch (code){
|
||||
|
||||
Reference in New Issue
Block a user