preparing filling of intermediate table

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-13 08:50:01 +02:00
parent 3bdf7dbab6
commit dabacd3d00
4 changed files with 74 additions and 51 deletions

View File

@@ -116,6 +116,7 @@ public class Constants {
public static final String LANGUAGE = "language";
public static final String LAST_CUSTOMER_NUMBER = "last_customer_number";
public static final String LIMIT = "limit";
public static final String LOCATION_ID = "location_id";
public static final String LOGIN = "login";
public static final String MEMBERS = "members";

View File

@@ -1,10 +1,60 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.core.model;
import java.sql.ResultSet;
import java.sql.SQLException;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
public class Location {
long owner;
boolean ownerIsCompany = false;
private long id;
private long parentLocationId;
private Long parentLocationId;
private String name;
private String description;
private String relation; // when added to an item, this field describes the type of the relation
private Location(long owner, boolean ownerIsCompany, long id, Long parentLocationId, String name, String description){
this.owner = owner;
this.ownerIsCompany = ownerIsCompany;
this.id = id;
this.parentLocationId = parentLocationId;
this.name = name;
this.description = description;
}
public static Location of(ResultSet rs){
return null;
}
public static Location ofLegacy(ResultSet rs) throws SQLException {
var id = rs.getString(ID);
var parent = rs.getString(LOCATION_ID);
var name = rs.getString(NAME);
var description = rs.getString(DESCRIPTION);
var ownerIsCompany = false;
var parts = id.split(":");
if (parts.length != 3) throw databaseException("Legacy id expected to be of format ss:dd:ss, encountered {0}",id);
switch (parts[0]){
case "company":
ownerIsCompany = true; break;
case "user":
break;
case null, default:
throw databaseException("Legacy id expected to start with 'company' or 'user', encountered {0}",id);
}
var owner = 0L;
try {
owner = Long.parseLong(parts[1]);
} catch (NumberFormatException nfe){
throw databaseException("Legacy id expected to be of format ss:dd:ss, encountered {0}",id);
}
Long parentLocationId = null;
if (parent != null){
// TODO
}
return new Location(owner, ownerIsCompany, id, parentLocationId, name, description);
}
}