Add investigation state handling for CheckedSchematic

This commit is contained in:
2025-05-31 22:44:40 +02:00
parent c30f24ab8f
commit 9ba8a83a3b
6 changed files with 61 additions and 15 deletions
@@ -28,13 +28,16 @@ import lombok.Getter;
import java.sql.Timestamp;
import java.util.List;
import java.util.Optional;
@AllArgsConstructor
public class CheckedSchematic {
public static final String INVESTIGATION_PENDING_KEY = "$invest:";
private static final Table<CheckedSchematic> table = new Table<>(CheckedSchematic.class);
private static final SelectStatement<CheckedSchematic> statusOfNode = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
private static final SelectStatement<CheckedSchematic> nodeHistory = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
private static final SelectStatement<CheckedSchematic> statusOfNode = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != 'Prüfvorgang abgebrochen' AND DeclineReason NOT LIKE '" + INVESTIGATION_PENDING_KEY + "%' ORDER BY EndTime DESC");
private static final SelectStatement<CheckedSchematic> lastCheck = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC LIMIT 1");
private static final Statement insert = table.insertAll();
public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason){
@@ -45,12 +48,16 @@ public class CheckedSchematic {
create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason);
}
public static void createInvestigationPending(SchematicNode node, Timestamp startTime, Timestamp endTime, int validator, String reason){
create(node, validator, startTime, endTime, INVESTIGATION_PENDING_KEY + reason);
}
public static List<CheckedSchematic> getLastDeclinedOfNode(int node){
return statusOfNode.listSelect(node);
}
public static List<CheckedSchematic> previousChecks(SchematicNode node) {
return nodeHistory.listSelect(node.getId());
public static Optional<CheckedSchematic> getLastCheck(int node){
return Optional.ofNullable(lastCheck.select(node));
}
@Field(nullable = true)
@@ -83,4 +90,20 @@ public class CheckedSchematic {
public int getSchemOwner() {
return nodeOwner;
}
public boolean isInvestigationPending() {
return declineReason.startsWith(INVESTIGATION_PENDING_KEY);
}
public String getInvestigationPendingReason() {
return declineReason.substring(INVESTIGATION_PENDING_KEY.length());
}
public Optional<CheckedSchematic> castToUserSafe() {
if (isInvestigationPending()) {
return Optional.empty();
} else {
return Optional.of(this);
}
}
}