10 changed files with 151 additions and 8 deletions
@ -1,12 +1,53 @@ |
|||||||
/* © SRSoftware 2025 */ |
/* © SRSoftware 2025 */ |
||||||
package de.srsoftware.umbrella.core.model; |
package de.srsoftware.umbrella.core.model; |
||||||
|
|
||||||
|
import de.srsoftware.tools.Mappable; |
||||||
|
|
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.SQLException; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import static de.srsoftware.umbrella.core.Constants.*; |
||||||
|
|
||||||
public class Item { |
public class Item implements Mappable { |
||||||
private long id; |
private long id; |
||||||
private String code; |
private Mappable owner; |
||||||
private boolean physical; |
private String code, name; |
||||||
private Location location; |
private Location location; |
||||||
private Collection<Property> properties; |
private Collection<Property> properties; |
||||||
|
|
||||||
|
private Item(Mappable owner, long id, Location location, String code, String name) { |
||||||
|
this.owner = owner; |
||||||
|
this.id = id; |
||||||
|
this.location = location; |
||||||
|
this.code = code; |
||||||
|
this.name = name; |
||||||
|
this.properties = new HashSet<>(); |
||||||
|
} |
||||||
|
|
||||||
|
public static Item of(ResultSet rs, Mappable owner, Location location) throws SQLException { |
||||||
|
var id = rs.getLong(ID); |
||||||
|
var code = rs.getString(CODE); |
||||||
|
var name = rs.getString(NAME); |
||||||
|
return new Item(owner, id, location, code, name); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Map<String, Object> toMap() { |
||||||
|
return Map.of( |
||||||
|
OWNER, owner.toMap(), |
||||||
|
ID, id, |
||||||
|
LOCATION, location.toMap(), |
||||||
|
CODE, code, |
||||||
|
NAME, name, |
||||||
|
PROPERTIES, properties.stream().map(Property::toMap).toList() |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return name; |
||||||
|
} |
||||||
} |
} |
||||||
|
|||||||
@ -1,10 +1,27 @@ |
|||||||
/* © SRSoftware 2025 */ |
/* © SRSoftware 2025 */ |
||||||
package de.srsoftware.umbrella.core.model; |
package de.srsoftware.umbrella.core.model; |
||||||
|
|
||||||
public class Property { |
import de.srsoftware.tools.Mappable; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import static de.srsoftware.umbrella.core.Constants.*; |
||||||
|
|
||||||
|
public class Property implements Mappable { |
||||||
long id; |
long id; |
||||||
String name; |
String name; |
||||||
Object value; |
Object value; |
||||||
String unit; |
String unit; |
||||||
String quantity; |
String quantity; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Map<String, Object> toMap() { |
||||||
|
return Map.of( |
||||||
|
ID, id, |
||||||
|
NAME, name, |
||||||
|
VALUE, value, |
||||||
|
UNIT, unit, |
||||||
|
QUANTITY, quantity |
||||||
|
); |
||||||
|
} |
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue