working on adding new properties to existing items

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-15 00:21:08 +02:00
parent 48128c5bf4
commit 846ef4a27a
9 changed files with 191 additions and 57 deletions

View File

@@ -149,6 +149,7 @@ public class Constants {
public static final String PROJECT = "project";
public static final String PROJECT_ID = "project_id";
public static final String PROPERTIES = "properties";
public static final String PROPERTY = "property";
public static final String RECEIVERS = "receivers";
public static final String REDIRECT = "redirect";

View File

@@ -47,8 +47,9 @@ public class Item implements Mappable {
@Override
public Map<String, Object> toMap() {
var ownerMap = owner instanceof Company comp ? Map.of(COMPANY,comp.id()) : (owner instanceof UmbrellaUser u ? Map.of(USER,u.id()) : Map.of());
return Map.of(
OWNER, owner.toMap(),
OWNER, ownerMap,
ID, id,
LOCATION, location.toMap(),
CODE, code,

View File

@@ -1,11 +1,13 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.core.model;
import static de.srsoftware.tools.Optionals.nullable;
import static de.srsoftware.umbrella.core.Constants.*;
import de.srsoftware.tools.Mappable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class Property implements Mappable {
@@ -24,18 +26,23 @@ public class Property implements Mappable {
public static Property of(ResultSet rs) throws SQLException {
var id = rs.getLong(ID);
var name = rs.getString(NAME);
var value = rs.getObject(VALUE);
Object value = null;
try {
value = rs.getObject(VALUE);
} catch (SQLException e){
if (!e.getMessage().contains("no such column")) throw e;
}
var unit = rs.getString(UNIT);
return new Property(id, name, value, unit);
}
@Override
public Map<String, Object> toMap() {
return Map.of(
ID, id,
NAME, name,
VALUE, value,
UNIT, unit
);
var map = new HashMap<String,Object>();
map.put(ID,id);
if (name != null) map.put(NAME,name);
if (value != null) map.put(VALUE,value);
if (unit != null) map.put(UNIT,unit);
return map;
}
}