added code to update notes referencing stock items
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -71,11 +71,11 @@ public class Application {
|
|||||||
new CompanyLegacy(config).bindPath("/legacy/company").on(server);
|
new CompanyLegacy(config).bindPath("/legacy/company").on(server);
|
||||||
new ContactModule(config).bindPath("/api/contact").on(server);
|
new ContactModule(config).bindPath("/api/contact").on(server);
|
||||||
new DocumentApi(config).bindPath("/api/document").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 UserLegacy(config).bindPath("/legacy/user").on(server);
|
||||||
new NotesLegacy(config).bindPath("/legacy/notes").on(server);
|
new NotesLegacy(config).bindPath("/legacy/notes").on(server);
|
||||||
new MarkdownApi().bindPath("/api/markdown").on(server);
|
new MarkdownApi().bindPath("/api/markdown").on(server);
|
||||||
new NoteModule(config).bindPath("/api/notes").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 ProjectModule(config).bindPath("/api/project").on(server);
|
||||||
new ProjectLegacy(config).bindPath("/legacy/project").on(server);
|
new ProjectLegacy(config).bindPath("/legacy/project").on(server);
|
||||||
new TaskModule(config).bindPath("/api/task").on(server);
|
new TaskModule(config).bindPath("/api/task").on(server);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import static de.srsoftware.umbrella.core.ModuleRegistry.stockService;
|
|||||||
import static java.text.MessageFormat.format;
|
import static java.text.MessageFormat.format;
|
||||||
|
|
||||||
import de.srsoftware.tools.Mappable;
|
import de.srsoftware.tools.Mappable;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|||||||
@@ -11,7 +11,41 @@ import java.sql.SQLException;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Map;
|
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 {
|
public static Note of(ResultSet rs) throws SQLException {
|
||||||
return new Note(
|
return new Note(
|
||||||
rs.getLong(ID),
|
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
|
@Override
|
||||||
public Map<String, Object> toMap() {
|
public Map<String, Object> toMap() {
|
||||||
return Map.of(
|
return Map.of(
|
||||||
|
|||||||
@@ -203,7 +203,9 @@ CREATE TABLE IF NOT EXISTS "{0}" (
|
|||||||
public Map<Long, Note> list(String module, String entityId) {
|
public Map<Long, Note> list(String module, String entityId) {
|
||||||
try {
|
try {
|
||||||
var notes = new HashMap<Long, Note>();
|
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()) {
|
while (rs.next()) {
|
||||||
var note = Note.of(rs);
|
var note = Note.of(rs);
|
||||||
notes.put(note.id(),note);
|
notes.put(note.id(),note);
|
||||||
|
|||||||
@@ -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.*;
|
||||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||||
import static de.srsoftware.umbrella.core.Constants.*;
|
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.core.exceptions.UmbrellaException.databaseException;
|
||||||
import static de.srsoftware.umbrella.stock.Constants.*;
|
import static de.srsoftware.umbrella.stock.Constants.*;
|
||||||
import static java.lang.System.Logger.Level.ERROR;
|
import static java.lang.System.Logger.Level.ERROR;
|
||||||
import static java.lang.System.Logger.Level.WARNING;
|
import static java.lang.System.Logger.Level.WARNING;
|
||||||
import static java.text.MessageFormat.format;
|
import static java.text.MessageFormat.format;
|
||||||
|
|
||||||
import de.srsoftware.tools.Mappable;
|
|
||||||
import de.srsoftware.umbrella.core.BaseDb;
|
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.*;
|
||||||
|
import de.srsoftware.umbrella.core.model.Location;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@@ -403,6 +403,7 @@ public class SqliteDb extends BaseDb implements StockDb {
|
|||||||
createIntermediatePropsTable();
|
createIntermediatePropsTable();
|
||||||
var oldLocationIdsToNew = transformLocations();
|
var oldLocationIdsToNew = transformLocations();
|
||||||
var oldItemIdsToNew = transformItems(oldLocationIdsToNew);
|
var oldItemIdsToNew = transformItems(oldLocationIdsToNew);
|
||||||
|
updateNotes(oldItemIdsToNew);
|
||||||
transformProperties(oldItemIdsToNew);
|
transformProperties(oldItemIdsToNew);
|
||||||
replaceLocationsTable();
|
replaceLocationsTable();
|
||||||
replaceItemsTable();
|
replaceItemsTable();
|
||||||
@@ -417,4 +418,19 @@ public class SqliteDb extends BaseDb implements StockDb {
|
|||||||
throw databaseException("Failed to transform {0} table!",TABLE_LOCATIONS);
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/* © SRSoftware 2025 */
|
/* © SRSoftware 2025 */
|
||||||
package de.srsoftware.umbrella.stock;
|
package de.srsoftware.umbrella.stock;
|
||||||
|
|
||||||
import de.srsoftware.umbrella.core.model.Location;
|
|
||||||
import de.srsoftware.umbrella.core.model.*;
|
import de.srsoftware.umbrella.core.model.*;
|
||||||
|
import de.srsoftware.umbrella.core.model.Location;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public interface StockDb {
|
public interface StockDb {
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ import de.srsoftware.tools.Path;
|
|||||||
import de.srsoftware.tools.SessionToken;
|
import de.srsoftware.tools.SessionToken;
|
||||||
import de.srsoftware.umbrella.core.BaseHandler;
|
import de.srsoftware.umbrella.core.BaseHandler;
|
||||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
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.api.StockService;
|
||||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
import de.srsoftware.umbrella.core.model.*;
|
import de.srsoftware.umbrella.core.model.*;
|
||||||
|
import de.srsoftware.umbrella.core.model.Location;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|||||||
Reference in New Issue
Block a user