implemented swapping of project/task states

such that the state order is now
* pending
* open
* started
* complete
* cancelled
This commit is contained in:
2025-08-01 23:07:02 +02:00
parent eed0ce0e8e
commit d0d7baccf0
5 changed files with 27 additions and 11 deletions

View File

@@ -7,6 +7,7 @@ import java.sql.SQLException;
import static de.srsoftware.tools.jdbc.Condition.equal;
import static de.srsoftware.tools.jdbc.Query.replaceInto;
import static de.srsoftware.tools.jdbc.Query.update;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Constants.TABLE_SETTINGS;
import static java.lang.System.Logger.Level.ERROR;
@@ -14,7 +15,7 @@ import static java.lang.System.Logger.Level.INFO;
import static java.text.MessageFormat.format;
public abstract class BaseDb {
private final System.Logger LOG = System.getLogger(getClass().getSimpleName());
private final System.Logger LOG = System.getLogger(getClass().getInterfaces()[0].getSimpleName());
protected final Connection db;
@@ -61,4 +62,18 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
}
return version;
}
public void swapStates(String table) {
try {
db.setAutoCommit(false);
update(table).set(STATUS).where(STATUS,equal(40)).prepare(db).apply(0).execute();
update(table).set(STATUS).where(STATUS,equal(20)).prepare(db).apply(40).execute();
update(table).set(STATUS).where(STATUS,equal(10)).prepare(db).apply(20).execute();
update(table).set(STATUS).where(STATUS,equal(0)).prepare(db).apply(10).execute();
db.setAutoCommit(true);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -13,9 +13,9 @@ import static de.srsoftware.umbrella.core.Constants.CODE;
import static de.srsoftware.umbrella.core.Constants.NAME;
public record Status(String name, int code) implements Mappable {
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 PENDING = new Status("PENDING", 10); // was 40
public static final Status OPEN = new Status("OPEN",20); // was 10
public static final Status STARTED = new Status("STARTED",40); // was 20
public static final Status COMPLETE = new Status("COMPLETE",60);
public static final Status CANCELLED = new Status("CANCELLED", 100);
public static final List<Status> PREDEFINED = new ArrayList<>(List.of(OPEN, STARTED, PENDING, COMPLETE, CANCELLED));