Browse Source

added code to update notes referencing stock items

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
module/stock.v2
Stephan Richter 3 weeks ago
parent
commit
cfa5dd7ed1
  1. 2
      backend/src/main/java/de/srsoftware/umbrella/backend/Application.java
  2. 1
      core/src/main/java/de/srsoftware/umbrella/core/model/Location.java
  3. 44
      core/src/main/java/de/srsoftware/umbrella/core/model/Note.java
  4. 4
      notes/src/main/java/de/srsoftware/umbrella/notes/SqliteDb.java
  5. 20
      stock/src/main/java/de/srsoftware/umbrella/stock/SqliteDb.java
  6. 2
      stock/src/main/java/de/srsoftware/umbrella/stock/StockDb.java
  7. 2
      stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

2
backend/src/main/java/de/srsoftware/umbrella/backend/Application.java

@ -71,11 +71,11 @@ public class Application { @@ -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);

1
core/src/main/java/de/srsoftware/umbrella/core/model/Location.java

@ -7,7 +7,6 @@ import static de.srsoftware.umbrella.core.ModuleRegistry.stockService; @@ -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;

44
core/src/main/java/de/srsoftware/umbrella/core/model/Note.java

@ -11,7 +11,41 @@ import java.sql.SQLException; @@ -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 @@ -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<String, Object> toMap() {
return Map.of(

4
notes/src/main/java/de/srsoftware/umbrella/notes/SqliteDb.java

@ -203,7 +203,9 @@ CREATE TABLE IF NOT EXISTS "{0}" ( @@ -203,7 +203,9 @@ CREATE TABLE IF NOT EXISTS "{0}" (
public Map<Long, Note> list(String module, String entityId) {
try {
var notes = new HashMap<Long, Note>();
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);

20
stock/src/main/java/de/srsoftware/umbrella/stock/SqliteDb.java

@ -7,16 +7,16 @@ import static de.srsoftware.tools.jdbc.Condition.isNull; @@ -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 { @@ -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 { @@ -417,4 +418,19 @@ public class SqliteDb extends BaseDb implements StockDb {
throw databaseException("Failed to transform {0} table!",TABLE_LOCATIONS);
}
}
private void updateNotes(HashMap<String, Long> oldItemIdsToNew) {
var noteService = noteService();
Map<Long, Note> 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));
}
}
}
}

2
stock/src/main/java/de/srsoftware/umbrella/stock/StockDb.java

@ -1,8 +1,8 @@ @@ -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 {

2
stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

@ -19,10 +19,10 @@ import de.srsoftware.tools.Path; @@ -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;

Loading…
Cancel
Save