|
|
|
@ -1,6 +1,7 @@ |
|
|
|
/* © SRSoftware 2025 */ |
|
|
|
/* © SRSoftware 2025 */ |
|
|
|
package de.srsoftware.umbrella.core.model; |
|
|
|
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.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.core.Util.markdown; |
|
|
|
import static de.srsoftware.umbrella.core.Util.markdown; |
|
|
|
|
|
|
|
|
|
|
|
@ -8,9 +9,39 @@ import de.srsoftware.tools.Mappable; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
|
|
public record Project(long id, String name, String description, Status status, Long companyId, boolean showClosed, Collection<Member> members) implements Mappable { |
|
|
|
public class Project implements Mappable { |
|
|
|
|
|
|
|
private final Collection<Member> members; |
|
|
|
|
|
|
|
private final boolean showClosed; |
|
|
|
|
|
|
|
private final Long companyId; |
|
|
|
|
|
|
|
private Status 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, Collection<Member> members) { |
|
|
|
|
|
|
|
this.id = id; |
|
|
|
|
|
|
|
this.name = name; |
|
|
|
|
|
|
|
this.description = description; |
|
|
|
|
|
|
|
this.status = status; |
|
|
|
|
|
|
|
this.companyId = companyId; |
|
|
|
|
|
|
|
this.showClosed = showClosed; |
|
|
|
|
|
|
|
this.members = members; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Optional<Long> companyId(){ |
|
|
|
|
|
|
|
return nullable(companyId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String description(){ |
|
|
|
|
|
|
|
return description; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Set<String> dirtyFields(){ |
|
|
|
|
|
|
|
return dirtyFields; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean hasMember(UmbrellaUser user) { |
|
|
|
public boolean hasMember(UmbrellaUser user) { |
|
|
|
for (var member : members){ |
|
|
|
for (var member : members){ |
|
|
|
@ -19,12 +50,44 @@ public record Project(long id, String name, String description, Status status, L |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public long id(){ |
|
|
|
|
|
|
|
return id; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Collection<Member> members(){ |
|
|
|
|
|
|
|
return members; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String name(){ |
|
|
|
|
|
|
|
return name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Project of(ResultSet rs) throws SQLException { |
|
|
|
public static Project of(ResultSet rs) throws SQLException { |
|
|
|
var companyId = rs.getLong(COMPANY_ID); |
|
|
|
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 ArrayList<>()); |
|
|
|
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 ArrayList<>()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Project patch(JSONObject json) { |
|
|
|
|
|
|
|
for (var key : json.keySet()){ |
|
|
|
|
|
|
|
switch (key){ |
|
|
|
|
|
|
|
case DESCRIPTION: description = json.getString(key); break; |
|
|
|
|
|
|
|
case NAME: name = json.getString(key); break; |
|
|
|
|
|
|
|
case STATUS: status = Status.of(json.getInt(key)); break; |
|
|
|
|
|
|
|
default: key = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (key != null) dirtyFields.add(key); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean showClosed(){ |
|
|
|
|
|
|
|
return showClosed; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Status status(){ |
|
|
|
|
|
|
|
return status; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Map<String, Object> toMap() { |
|
|
|
public Map<String, Object> toMap() { |
|
|
|
var map = new HashMap<String, Object>(); |
|
|
|
var map = new HashMap<String, Object>(); |
|
|
|
@ -37,4 +100,12 @@ public record Project(long id, String name, String description, Status status, L |
|
|
|
map.put(MEMBERS,members == null ? List.of() : members.stream().map(Member::toMap).toList()); |
|
|
|
map.put(MEMBERS,members == null ? List.of() : members.stream().map(Member::toMap).toList()); |
|
|
|
return map; |
|
|
|
return map; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isDirty() { |
|
|
|
|
|
|
|
return !dirtyFields.isEmpty(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void clean() { |
|
|
|
|
|
|
|
dirtyFields.clear(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|