From 6ca47c13a06fefda865e2637bc2213621d2e231b Mon Sep 17 00:00:00 2001 From: Claus Nagel Date: Wed, 18 Dec 2024 15:16:31 +0100 Subject: [PATCH] type and property descriptions are available through the schema mapping --- .../java/org/citydb/database/schema/DataType.java | 11 ++++++----- .../org/citydb/database/schema/FeatureType.java | 12 +++++++----- .../java/org/citydb/database/schema/Property.java | 13 ++++++++++--- .../main/java/org/citydb/database/schema/Type.java | 10 ++++++++-- .../sql-scripts/schema/datatype-instances.sql | 2 +- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/citydb-database/src/main/java/org/citydb/database/schema/DataType.java b/citydb-database/src/main/java/org/citydb/database/schema/DataType.java index af8a1d3c..404c181d 100644 --- a/citydb-database/src/main/java/org/citydb/database/schema/DataType.java +++ b/citydb-database/src/main/java/org/citydb/database/schema/DataType.java @@ -31,19 +31,20 @@ public class DataType extends Type implements ValueObject { public static final DataType UNDEFINED = new DataType(1, "core:Undefined", Name.of("Undefined", Namespaces.CORE), - Table.PROPERTY, false, null, null, null, null, null); + Table.PROPERTY, null, false, null, null, null, null, null); private final Value value; - private DataType(int id, String identifier, Name name, Table table, boolean isAbstract, Integer superTypeId, - Map properties, Value value, Join join, JoinTable joinTable) { - super(id, identifier, name, table, isAbstract, superTypeId, properties, join, joinTable); + private DataType(int id, String identifier, Name name, Table table, String description, boolean isAbstract, + Integer superTypeId, Map properties, Value value, Join join, JoinTable joinTable) { + super(id, identifier, name, table, description, isAbstract, superTypeId, properties, join, joinTable); this.value = value; } static DataType of(int id, Name name, boolean isAbstract, Integer superTypeId, JSONObject object) throws SchemaException { String identifier = object.getString("identifier"); String tableName = object.getString("table"); + String description = object.getString("description"); JSONArray propertiesArray = object.getJSONArray("properties"); JSONObject valueObject = object.getJSONObject("value"); JSONObject joinObject = object.getJSONObject("join"); @@ -63,7 +64,7 @@ static DataType of(int id, Name name, boolean isAbstract, Integer superTypeId, J } try { - return new DataType(id, identifier, name, table, isAbstract, superTypeId, + return new DataType(id, identifier, name, table, description, isAbstract, superTypeId, propertiesArray != null ? Type.buildProperties(propertiesArray) : null, valueObject != null ? Value.of(valueObject) : null, joinObject != null ? Join.of(joinObject) : null, diff --git a/citydb-database/src/main/java/org/citydb/database/schema/FeatureType.java b/citydb-database/src/main/java/org/citydb/database/schema/FeatureType.java index f27277a8..be86b9bb 100644 --- a/citydb-database/src/main/java/org/citydb/database/schema/FeatureType.java +++ b/citydb-database/src/main/java/org/citydb/database/schema/FeatureType.java @@ -30,19 +30,21 @@ public class FeatureType extends Type { public static final FeatureType UNDEFINED = new FeatureType(1, "core:Undefined", - Name.of("Undefined", Namespaces.CORE), Table.FEATURE, false, false, null, null, null, null); + Name.of("Undefined", Namespaces.CORE), Table.FEATURE, null, false, false, null, null, null, null); private final boolean isTopLevel; - private FeatureType(int id, String identifier, Name name, Table table, boolean isAbstract, boolean isTopLevel, - Integer superTypeId, Map properties, Join join, JoinTable joinTable) { - super(id, identifier, name, table, isAbstract, superTypeId, properties, join, joinTable); + private FeatureType(int id, String identifier, Name name, Table table, String description, boolean isAbstract, + boolean isTopLevel, Integer superTypeId, Map properties, Join join, + JoinTable joinTable) { + super(id, identifier, name, table, description, isAbstract, superTypeId, properties, join, joinTable); this.isTopLevel = isTopLevel; } static FeatureType of(int id, Name name, boolean isAbstract, boolean isTopLevel, Integer superTypeId, JSONObject object) throws SchemaException { String identifier = object.getString("identifier"); String tableName = object.getString("table"); + String description = object.getString("description"); JSONArray propertiesArray = object.getJSONArray("properties"); JSONObject joinObject = object.getJSONObject("join"); JSONObject joinTableObject = object.getJSONObject("joinTable"); @@ -61,7 +63,7 @@ static FeatureType of(int id, Name name, boolean isAbstract, boolean isTopLevel, } try { - return new FeatureType(id, identifier, name, table, isAbstract, isTopLevel, superTypeId, + return new FeatureType(id, identifier, name, table, description, isAbstract, isTopLevel, superTypeId, propertiesArray != null ? Type.buildProperties(propertiesArray) : null, joinObject != null ? Join.of(joinObject) : null, joinTableObject != null ? JoinTable.of(joinTableObject) : null); diff --git a/citydb-database/src/main/java/org/citydb/database/schema/Property.java b/citydb-database/src/main/java/org/citydb/database/schema/Property.java index b74edda7..966edfcb 100644 --- a/citydb-database/src/main/java/org/citydb/database/schema/Property.java +++ b/citydb-database/src/main/java/org/citydb/database/schema/Property.java @@ -31,6 +31,7 @@ public class Property implements ValueObject, Typeable, Joinable { private final Name name; + private final String description; private final Integer parentIndex; private final Value value; private final String typeIdentifier; @@ -42,9 +43,10 @@ public class Property implements ValueObject, Typeable, Joinable { private Map properties; private Join join; - private Property(Name name, Integer parentIndex, Value value, String typeIdentifier, String targetIdentifier, - Join join, JoinTable joinTable) { + private Property(Name name, String description, Integer parentIndex, Value value, String typeIdentifier, + String targetIdentifier, Join join, JoinTable joinTable) { this.name = name; + this.description = description; this.parentIndex = parentIndex; this.value = value; this.typeIdentifier = typeIdentifier; @@ -55,6 +57,7 @@ private Property(Name name, Integer parentIndex, Value value, String typeIdentif static Property of(JSONObject object) throws SchemaException { String propertyName = object.getString("name"); + String description = object.getString("description"); String namespace = object.getString("namespace"); Integer parentIndex = object.getInteger("parent"); JSONObject valueObject = object.getJSONObject("value"); @@ -86,7 +89,7 @@ static Property of(JSONObject object) throws SchemaException { }; } - return new Property(Name.of(propertyName, namespace), parentIndex, + return new Property(Name.of(propertyName, namespace), description, parentIndex, valueObject != null ? Value.of(valueObject) : null, typeIdentifier, targetIdentifier, joinObject != null ? Join.of(joinObject) : null, @@ -98,6 +101,10 @@ public Name getName() { return name; } + public Optional getDescription() { + return Optional.ofNullable(description); + } + Integer getParentIndex() { return parentIndex; } diff --git a/citydb-database/src/main/java/org/citydb/database/schema/Type.java b/citydb-database/src/main/java/org/citydb/database/schema/Type.java index 4b8afa90..0abf5dfb 100644 --- a/citydb-database/src/main/java/org/citydb/database/schema/Type.java +++ b/citydb-database/src/main/java/org/citydb/database/schema/Type.java @@ -32,6 +32,7 @@ public abstract class Type> implements Joinable { final String identifier; final Name name; final Table table; + final String description; final boolean isAbstract; final Integer superTypeId; final Map properties; @@ -39,12 +40,13 @@ public abstract class Type> implements Joinable { final JoinTable joinTable; T superType; - Type(int id, String identifier, Name name, Table table, boolean isAbstract, Integer superTypeId, - Map properties, Join join, JoinTable joinTable) { + Type(int id, String identifier, Name name, Table table, String description, boolean isAbstract, + Integer superTypeId, Map properties, Join join, JoinTable joinTable) { this.id = id; this.identifier = identifier; this.name = name; this.table = table; + this.description = description; this.isAbstract = isAbstract; this.superTypeId = superTypeId; this.properties = properties; @@ -90,6 +92,10 @@ public Table getTable() { return table; } + public Optional getDescription() { + return Optional.ofNullable(description); + } + public boolean isAbstract() { return isAbstract; } diff --git a/resources/3dcitydb/postgresql/sql-scripts/schema/datatype-instances.sql b/resources/3dcitydb/postgresql/sql-scripts/schema/datatype-instances.sql index f308e317..a0fb911f 100644 --- a/resources/3dcitydb/postgresql/sql-scripts/schema/datatype-instances.sql +++ b/resources/3dcitydb/postgresql/sql-scripts/schema/datatype-instances.sql @@ -33,7 +33,7 @@ INSERT INTO datatype (ID, SUPERTYPE_ID, TYPENAME, IS_ABSTRACT, NAMESPACE_ID, SCH VALUES (10, null, 'FeatureProperty', 0, 1, '{"identifier":"core:FeatureProperty","description":"FeatureProperty links a feature or property to a feature.","table":"property","join":{"table":"feature","fromColumn":"val_feature_id","toColumn":"id","conditions":[{"column":"objectclass_id","value":"@target.objectclass_id@","type":"integer"}]}}'); INSERT INTO datatype (ID, SUPERTYPE_ID, TYPENAME, IS_ABSTRACT, NAMESPACE_ID, SCHEMA) -VALUES (11, null, 'GeometryProperty', 0, 1, '{"identifier":"core:GeometryProperty","description":"GeometryProperty links a feature or property to a geometry.","table":"property","properties":[{"name":"lod","namespace":"http://3dcitydb.org/3dcitydb/core/5.0","value":{"column":"val_lod","type":"string"}}],"join":{"table":"geometry_data","fromColumn":"val_geometry_id","toColumn":"id"}}'); +VALUES (11, null, 'GeometryProperty', 0, 1, '{"identifier":"core:GeometryProperty","description":"GeometryProperty links a feature or property to a geometry.","table":"property","properties":[{"name":"lod","namespace":"http://3dcitydb.org/3dcitydb/core/5.0","description":"Specifies the Level of Detail of the geometry.","value":{"column":"val_lod","type":"string"}}],"join":{"table":"geometry_data","fromColumn":"val_geometry_id","toColumn":"id"}}'); INSERT INTO datatype (ID, SUPERTYPE_ID, TYPENAME, IS_ABSTRACT, NAMESPACE_ID, SCHEMA) VALUES (12, null, 'Reference', 0, 1, '{"identifier":"core:Reference","description":"Reference links a feature or property to a remote resource identified by a URI.","table":"property","value":{"column":"val_uri","type":"uri"}}');