4 changed files with 74 additions and 51 deletions
@ -1,10 +1,60 @@ |
|||||||
/* © SRSoftware 2025 */ |
/* © SRSoftware 2025 */ |
||||||
package de.srsoftware.umbrella.core.model; |
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 { |
public class Location { |
||||||
|
long owner; |
||||||
|
boolean ownerIsCompany = false; |
||||||
private long id; |
private long id; |
||||||
private long parentLocationId; |
private Long parentLocationId; |
||||||
private String name; |
private String name; |
||||||
private String description; |
private String description; |
||||||
private String relation; // when added to an item, this field describes the type of the relation
|
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); |
||||||
|
} |
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue