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));

View File

@@ -83,8 +83,10 @@ PRIMARY KEY (project_id, code)
createUsersTable();
case 1:
createStatesTable();
case 2:
swapStates(TABLE_PROJECTS);
}
return setCurrentVersion(2);
return setCurrentVersion(3);
}
private void createUsersTable(){
@@ -131,11 +133,6 @@ CREATE TABLE IF NOT EXISTS {0} (
}
}
private void init(){
var version = createTables();
LOG.log(INFO,"Updated project db to version {0}",version);
}
@Override
public Project load(long projectId) throws UmbrellaException {
try {
@@ -243,4 +240,5 @@ CREATE TABLE IF NOT EXISTS {0} (
throw new UmbrellaException("Failed to create custom state!");
}
}
}

View File

@@ -38,9 +38,11 @@ public class SqliteDb extends BaseDb implements TaskDb {
case 0:
createTaskTables();
createTasksUsersTable();
case 1:
swapStates(TABLE_TASKS);
}
return setCurrentVersion(1);
return setCurrentVersion(2);
}
private void createTaskTables() {

View File

@@ -4,6 +4,7 @@
"add_login_service": "Login-Service anlegen",
"add_member": "Mitarbeiter hinzufügen",
"add_position": "hinzufügen",
"add_state": "Status hinzufügen",
"add_subtask": "Unteraufgabe hinzufügen",
"add_task": "Aufgabe hinzufügen",
"advertisement" : "Umbrella ist ein Produkt von {producer}.",