diff --git a/backend/src/main/java/de/srsoftware/umbrella/backend/Application.java b/backend/src/main/java/de/srsoftware/umbrella/backend/Application.java index 03d2557..d27d444 100644 --- a/backend/src/main/java/de/srsoftware/umbrella/backend/Application.java +++ b/backend/src/main/java/de/srsoftware/umbrella/backend/Application.java @@ -71,11 +71,11 @@ public class Application { new CompanyLegacy(config).bindPath("/legacy/company").on(server); new ContactModule(config).bindPath("/api/contact").on(server); new DocumentApi(config).bindPath("/api/document").on(server); - new StockModule(config).bindPath("/api/stock").on(server); new UserLegacy(config).bindPath("/legacy/user").on(server); new NotesLegacy(config).bindPath("/legacy/notes").on(server); new MarkdownApi().bindPath("/api/markdown").on(server); new NoteModule(config).bindPath("/api/notes").on(server); + new StockModule(config).bindPath("/api/stock").on(server); new ProjectModule(config).bindPath("/api/project").on(server); new ProjectLegacy(config).bindPath("/legacy/project").on(server); new TaskModule(config).bindPath("/api/task").on(server); diff --git a/core/src/main/java/de/srsoftware/umbrella/core/model/Location.java b/core/src/main/java/de/srsoftware/umbrella/core/model/Location.java index e11e33d..33b5ca6 100644 --- a/core/src/main/java/de/srsoftware/umbrella/core/model/Location.java +++ b/core/src/main/java/de/srsoftware/umbrella/core/model/Location.java @@ -7,7 +7,6 @@ import static de.srsoftware.umbrella.core.ModuleRegistry.stockService; import static java.text.MessageFormat.format; import de.srsoftware.tools.Mappable; - import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map; diff --git a/core/src/main/java/de/srsoftware/umbrella/core/model/Note.java b/core/src/main/java/de/srsoftware/umbrella/core/model/Note.java index e00b285..adf28ab 100644 --- a/core/src/main/java/de/srsoftware/umbrella/core/model/Note.java +++ b/core/src/main/java/de/srsoftware/umbrella/core/model/Note.java @@ -11,7 +11,41 @@ import java.sql.SQLException; import java.time.LocalDateTime; import java.util.Map; -public record Note(long id, String module, String entityId, long authorId, String text, LocalDateTime timestamp) implements Mappable { +public class Note implements Mappable { + private long authorId, id; + private String entityId, module, text; + private LocalDateTime timestamp; + + public Note(long id, String module, String entityId, long authorId, String text, LocalDateTime timestamp){ + this.id = id; + this.module = module; + this.entityId = entityId; + this.authorId = authorId; + this.text = text; + this.timestamp = timestamp; + } + + public long authorId(){ + return authorId; + } + + public String entityId(){ + return entityId; + } + + public Note entityId(String newVal){ + entityId = newVal; + return this; + } + + public long id(){ + return id; + } + + public String module(){ + return module; + } + public static Note of(ResultSet rs) throws SQLException { return new Note( rs.getLong(ID), @@ -23,6 +57,14 @@ public record Note(long id, String module, String entityId, long authorId, Strin ); } + public String text() { + return text; + } + + public LocalDateTime timestamp(){ + return timestamp; + } + @Override public Map toMap() { return Map.of( diff --git a/notes/src/main/java/de/srsoftware/umbrella/notes/SqliteDb.java b/notes/src/main/java/de/srsoftware/umbrella/notes/SqliteDb.java index a3bf39e..609de64 100644 --- a/notes/src/main/java/de/srsoftware/umbrella/notes/SqliteDb.java +++ b/notes/src/main/java/de/srsoftware/umbrella/notes/SqliteDb.java @@ -203,7 +203,9 @@ CREATE TABLE IF NOT EXISTS "{0}" ( public Map list(String module, String entityId) { try { var notes = new HashMap(); - var rs = select(ALL).from(TABLE_NOTES).where(MODULE,equal(module)).where(ENTITY_ID,equal(entityId)).exec(db); + var query = select(ALL).from(TABLE_NOTES).where(MODULE,equal(module)); + if (entityId != null) query.where(ENTITY_ID,equal(entityId)); + var rs = query.exec(db); while (rs.next()) { var note = Note.of(rs); notes.put(note.id(),note); diff --git a/stock/src/main/java/de/srsoftware/umbrella/stock/SqliteDb.java b/stock/src/main/java/de/srsoftware/umbrella/stock/SqliteDb.java index f595cfe..4b03dde 100644 --- a/stock/src/main/java/de/srsoftware/umbrella/stock/SqliteDb.java +++ b/stock/src/main/java/de/srsoftware/umbrella/stock/SqliteDb.java @@ -7,16 +7,16 @@ import static de.srsoftware.tools.jdbc.Condition.isNull; import static de.srsoftware.tools.jdbc.Query.*; import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL; import static de.srsoftware.umbrella.core.Constants.*; +import static de.srsoftware.umbrella.core.ModuleRegistry.noteService; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException; import static de.srsoftware.umbrella.stock.Constants.*; import static java.lang.System.Logger.Level.ERROR; import static java.lang.System.Logger.Level.WARNING; import static java.text.MessageFormat.format; -import de.srsoftware.tools.Mappable; import de.srsoftware.umbrella.core.BaseDb; -import de.srsoftware.umbrella.core.model.Location; import de.srsoftware.umbrella.core.model.*; +import de.srsoftware.umbrella.core.model.Location; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -403,6 +403,7 @@ public class SqliteDb extends BaseDb implements StockDb { createIntermediatePropsTable(); var oldLocationIdsToNew = transformLocations(); var oldItemIdsToNew = transformItems(oldLocationIdsToNew); + updateNotes(oldItemIdsToNew); transformProperties(oldItemIdsToNew); replaceLocationsTable(); replaceItemsTable(); @@ -417,4 +418,19 @@ public class SqliteDb extends BaseDb implements StockDb { throw databaseException("Failed to transform {0} table!",TABLE_LOCATIONS); } } + + private void updateNotes(HashMap oldItemIdsToNew) { + var noteService = noteService(); + Map notes = noteService.getNotes("stock", null); + for (var entry : notes.entrySet()){ + var note = entry.getValue(); + var oldEntityId = note.entityId(); + var newEntityId = oldItemIdsToNew.get(oldEntityId); + if (newEntityId != null){ + noteService.save(note.entityId(""+newEntityId)); + } + } + + + } } diff --git a/stock/src/main/java/de/srsoftware/umbrella/stock/StockDb.java b/stock/src/main/java/de/srsoftware/umbrella/stock/StockDb.java index de60e72..a541da7 100644 --- a/stock/src/main/java/de/srsoftware/umbrella/stock/StockDb.java +++ b/stock/src/main/java/de/srsoftware/umbrella/stock/StockDb.java @@ -1,8 +1,8 @@ /* © SRSoftware 2025 */ package de.srsoftware.umbrella.stock; -import de.srsoftware.umbrella.core.model.Location; import de.srsoftware.umbrella.core.model.*; +import de.srsoftware.umbrella.core.model.Location; import java.util.Collection; public interface StockDb { diff --git a/stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java b/stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java index 2384e49..58c4668 100644 --- a/stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java +++ b/stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java @@ -19,10 +19,10 @@ import de.srsoftware.tools.Path; import de.srsoftware.tools.SessionToken; import de.srsoftware.umbrella.core.BaseHandler; import de.srsoftware.umbrella.core.ModuleRegistry; -import de.srsoftware.umbrella.core.model.Location; import de.srsoftware.umbrella.core.api.StockService; import de.srsoftware.umbrella.core.exceptions.UmbrellaException; import de.srsoftware.umbrella.core.model.*; +import de.srsoftware.umbrella.core.model.Location; import java.io.IOException; import java.util.*; import org.json.JSONObject;