added code to update notes referencing stock items

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-16 13:23:14 +02:00
parent 5ca6e3c3b8
commit cfa5dd7ed1
7 changed files with 67 additions and 8 deletions

View File

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

View File

@@ -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 {

View File

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