working on referenceable locations

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-11-03 20:16:57 +01:00
parent 8e10909c81
commit 71d9a4b15f
6 changed files with 88 additions and 54 deletions

View File

@@ -286,6 +286,30 @@ public class SqliteDb extends BaseDb implements StockDb {
}
}
@Override
public Map<String, Object> pathToLocation(Location target) {
var root = new HashMap<String,Object>();
var location = loadLocation(target.id());
root.put(NAME,location.name());
root.put(ID,location.id());
try {
while (!is0(location.parent())) {
var rs = select(ALL).from(TABLE_LOCATIONS).where(ID, equal(location.parent())).exec(db);
var parent = DbLocation.of(rs);
rs.close();
var current = new HashMap<String,Object>();
current.put(NAME,parent.name());
current.put(ID,parent.id());
current.put(PATH,root);
root = current;
location = parent;
}
} catch (SQLException e){
throw databaseException("Failed to load path to location {0}",target);
}
return root;
}
private void replaceItemsTable() throws SQLException {
db.prepareStatement(format("DROP TABLE {0}",TABLE_ITEMS)).execute();
db.prepareStatement(format("ALTER TABLE {0} RENAME TO {1}","items_temp",TABLE_ITEMS)).execute();

View File

@@ -5,20 +5,21 @@ import de.srsoftware.umbrella.core.api.Owner;
import de.srsoftware.umbrella.core.model.*;
import de.srsoftware.umbrella.core.model.Location;
import java.util.Collection;
import java.util.Map;
public interface StockDb {
Property addNewProperty(long itemId, String name, Object value, String unit);
Location delete(DbLocation location);
Collection<DbLocation> listChildLocations(long parentId);
Collection<DbLocation> listCompanyLocations(Company company);
Collection<Item> listItemsAt(Location location);
Collection<Property> listProperties();
Collection<DbLocation> listUserLocations(UmbrellaUser userId);
Item loadItem(long id);
DbLocation loadLocation(long locationId);
DbLocation save(DbLocation location);
Item save(Item item);
Property setProperty(long itemId, long existingPropId, Object value);
long nextItemNumberFor(Owner owner);
Property addNewProperty(long itemId, String name, Object value, String unit);
Location delete(DbLocation location);
Collection<DbLocation> listChildLocations(long parentId);
Collection<DbLocation> listCompanyLocations(Company company);
Collection<Item> listItemsAt(Location location);
Collection<Property> listProperties();
Collection<DbLocation> listUserLocations(UmbrellaUser userId);
Item loadItem(long id);
DbLocation loadLocation(long locationId);
long nextItemNumberFor(Owner owner);
Map<String,Object> pathToLocation(Location location);
DbLocation save(DbLocation location);
Item save(Item item);
Property setProperty(long itemId, long existingPropId, Object value);
}

View File

@@ -165,8 +165,8 @@ public class StockModule extends BaseHandler implements StockService {
case USER -> List.of(owner.id());
case null, default -> throw unprocessable("Unprocessable owner type: {0}",owner.type());
};
return sendContent(ex,Map.of(ITEMS,items,USERS,userIds));
var pathToLocation = stockDb.pathToLocation(location);
return sendContent(ex,Map.of(ITEMS,items,USERS,userIds,PATH,pathToLocation));
}
private boolean getLocations(Path path, UmbrellaUser user, HttpExchange ex) throws IOException {