Skip to content

Commit ef00f91

Browse files
authored
HTM-1760: use list of editable attributes instead of read only attributes in feature type settings (#1467)
* make not editable standard and use list of editable attributes * create flyway script to replace readOnlyAttributes with editableAttributes in featureTypeSettings * adapt check for editable in attribute to editableAttributes list * add attributes to editableAttributes in populate testdata * add attributes to editableAttributes in populate testdata in featuretypes used in tests * bugfix: getEditableAttributes should remove readonly attributes fom layer settings * add geometry attribute to editable attributes * add all geometry attributes to editable attributes
1 parent 5fa5605 commit ef00f91

File tree

7 files changed

+90
-15
lines changed

7 files changed

+90
-15
lines changed

src/main/java/org/tailormap/api/configuration/dev/PopulateTestData.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,21 @@ private void createCatalogTestData() throws Exception {
932932
} catch (IOException | SQLException e) {
933933
throw new RuntimeException("Failed to create attachments table", e);
934934
}
935+
ft.getSettings().addEditableAttributesItem("identificatie");
936+
ft.getSettings().addEditableAttributesItem("bronhouder");
937+
ft.getSettings().addEditableAttributesItem("class");
938+
ft.getSettings().addEditableAttributesItem("gmlid");
939+
ft.getSettings().addEditableAttributesItem("lv_publicatiedatum");
940+
ft.getSettings().addEditableAttributesItem("creationdate");
941+
ft.getSettings().addEditableAttributesItem("tijdstipregistratie");
942+
ft.getSettings().addEditableAttributesItem("eindregistratie");
943+
ft.getSettings().addEditableAttributesItem("terminationdate");
944+
ft.getSettings().addEditableAttributesItem("inonderzoek");
945+
ft.getSettings().addEditableAttributesItem("relatievehoogteligging");
946+
ft.getSettings().addEditableAttributesItem("bgt_status");
947+
ft.getSettings().addEditableAttributesItem("plus_status");
948+
ft.getSettings().addEditableAttributesItem("plus_fysiekvoorkomen");
949+
ft.getSettings().addEditableAttributesItem("begroeidterreindeeloptalud");
935950
});
936951

937952
featureSources.get("postgis").getFeatureTypes().stream()
@@ -966,6 +981,20 @@ private void createCatalogTestData() throws Exception {
966981
} catch (IOException | SQLException e) {
967982
throw new RuntimeException("Failed to create attachments table", e);
968983
}
984+
ft.getSettings().addEditableAttributesItem("GMLID");
985+
ft.getSettings().addEditableAttributesItem("IDENTIFICATIE");
986+
ft.getSettings().addEditableAttributesItem("LV_PUBLICATIEDATUM");
987+
ft.getSettings().addEditableAttributesItem("CREATIONDATE");
988+
ft.getSettings().addEditableAttributesItem("TIJDSTIPREGISTRATIE");
989+
ft.getSettings().addEditableAttributesItem("EINDREGISTRATIE");
990+
ft.getSettings().addEditableAttributesItem("TERMINATIONDATE");
991+
ft.getSettings().addEditableAttributesItem("BRONHOUDER");
992+
ft.getSettings().addEditableAttributesItem("INONDERZOEK");
993+
ft.getSettings().addEditableAttributesItem("RELATIEVEHOOGTELIGGING");
994+
ft.getSettings().addEditableAttributesItem("BGT_STATUS");
995+
ft.getSettings().addEditableAttributesItem("PLUS_STATUS");
996+
ft.getSettings().addEditableAttributesItem("CLASS");
997+
ft.getSettings().addEditableAttributesItem("PLUS_TYPE");
969998
});
970999
featureSources.get("sqlserver").getFeatureTypes().stream()
9711000
.filter(ft -> ft.getName().equals("wegdeel"))
@@ -981,12 +1010,38 @@ private void createCatalogTestData() throws Exception {
9811010
} catch (IOException | SQLException e) {
9821011
throw new RuntimeException("Failed to create attachments table", e);
9831012
}
1013+
ft.getSettings().addEditableAttributesItem("gmlid");
1014+
ft.getSettings().addEditableAttributesItem("identificatie");
1015+
ft.getSettings().addEditableAttributesItem("lv_publicatiedatum");
1016+
ft.getSettings().addEditableAttributesItem("creationdate");
1017+
ft.getSettings().addEditableAttributesItem("tijdstipregistratie");
1018+
ft.getSettings().addEditableAttributesItem("eindregistratie");
1019+
ft.getSettings().addEditableAttributesItem("terminationdate");
1020+
ft.getSettings().addEditableAttributesItem("bronhouder");
1021+
ft.getSettings().addEditableAttributesItem("inonderzoek");
1022+
ft.getSettings().addEditableAttributesItem("relatievehoogteligging");
1023+
ft.getSettings().addEditableAttributesItem("bgt_status");
1024+
ft.getSettings().addEditableAttributesItem("plus_status");
1025+
ft.getSettings().addEditableAttributesItem("function_");
1026+
ft.getSettings().addEditableAttributesItem("plus_functiewegdeel");
1027+
ft.getSettings().addEditableAttributesItem("plus_fysiekvoorkomenwegdeel");
1028+
ft.getSettings().addEditableAttributesItem("surfacematerial");
1029+
ft.getSettings().addEditableAttributesItem("wegdeeloptalud");
9841030
});
9851031

9861032
featureSources.get("postgis").getFeatureTypes().stream()
9871033
.filter(ft -> ft.getName().equals("kadastraal_perceel"))
9881034
.findFirst()
9891035
.ifPresent(ft -> ft.getSettings().addHideAttributesItem("gml_id"));
1036+
1037+
featureSources.get("postgis_osm").getFeatureTypes().stream()
1038+
.filter(ft -> ft.getName().equals("osm_polygon"))
1039+
.findFirst()
1040+
.ifPresent(ft -> {
1041+
ft.getSettings().addEditableAttributesItem("osm_id");
1042+
ft.getSettings().addEditableAttributesItem("building");
1043+
ft.getSettings().addEditableAttributesItem("z_order");
1044+
});
9901045
}
9911046

9921047
public void createAppTestData() throws Exception {

src/main/java/org/tailormap/api/controller/EditFeatureController.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
*/
66
package org.tailormap.api.controller;
77

8+
import static org.tailormap.api.persistence.helper.TMFeatureTypeHelper.getEditableAttributes;
89
import static org.tailormap.api.persistence.helper.TMFeatureTypeHelper.getNonHiddenAttributeNames;
910
import static org.tailormap.api.persistence.helper.TMFeatureTypeHelper.getNonHiddenAttributes;
10-
import static org.tailormap.api.persistence.helper.TMFeatureTypeHelper.getReadOnlyAttributes;
1111

1212
import io.micrometer.core.annotation.Counted;
1313
import io.micrometer.core.annotation.Timed;
1414
import java.io.IOException;
1515
import java.io.Serializable;
1616
import java.lang.invoke.MethodHandles;
17-
import java.util.Collections;
1817
import java.util.List;
1918
import java.util.Map;
2019
import org.geotools.api.data.FeatureStore;
@@ -91,9 +90,8 @@ private static void checkFeatureHasOnlyValidAttributes(
9190
HttpStatus.BAD_REQUEST,
9291
"Feature cannot be edited, one or more requested attributes are not available on the feature type");
9392
}
94-
if (!Collections.disjoint(
95-
getReadOnlyAttributes(tmFeatureType, appLayerSettings),
96-
feature.getAttributes().keySet())) {
93+
if (!getEditableAttributes(tmFeatureType, appLayerSettings)
94+
.containsAll(feature.getAttributes().keySet())) {
9795
throw new ResponseStatusException(
9896
HttpStatus.BAD_REQUEST,
9997
"Feature cannot be edited, one or more requested attributes are not editable on the feature type");

src/main/java/org/tailormap/api/controller/LayerDescriptionController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public ResponseEntity<Serializable> getAppLayerDescription(
9898
}
9999
}
100100

101-
Set<String> readOnlyAttributes = TMFeatureTypeHelper.getReadOnlyAttributes(tmft, appLayerSettings);
101+
Set<String> editableAttributes = TMFeatureTypeHelper.getEditableAttributes(tmft, appLayerSettings);
102102

103103
getConfiguredAttributes(tmft, appLayerSettings).values().stream()
104104
.map(attributeWithSettings -> {
@@ -112,7 +112,7 @@ public ResponseEntity<Serializable> getAppLayerDescription(
112112
.type(isGeometry(a.getType()) ? TMAttributeType.GEOMETRY : a.getType())
113113
// primary key can never be edited
114114
.editable(!a.getName().equals(tmft.getPrimaryKeyAttribute())
115-
&& !readOnlyAttributes.contains(a.getName()))
115+
&& editableAttributes.contains(a.getName()))
116116
.defaultValue(a.getDefaultValue())
117117
.nullable(a.getNullable());
118118
})

src/main/java/org/tailormap/api/persistence/TMFeatureType.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ public String findDefaultGeometryAttribute() {
203203
.orElse(null);
204204
}
205205

206+
public List<String> getAllGeometryAttributeNames() {
207+
return getAttributes().stream()
208+
.filter(a -> TMAttributeTypeHelper.isGeometry(a.getType()))
209+
.map(TMAttributeDescriptor::getName)
210+
.toList();
211+
}
212+
206213
public Optional<TMAttributeDescriptor> getDefaultGeometryDescriptor() {
207214
return getAttributeByName(defaultGeometryAttribute);
208215
}

src/main/java/org/tailormap/api/persistence/helper/TMFeatureTypeHelper.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ public static Set<String> getHiddenAttributes(
5151
return hiddenAttributes;
5252
}
5353

54-
public static Set<String> getReadOnlyAttributes(
54+
public static Set<String> getEditableAttributes(
5555
@NotNull TMFeatureType featureType, @NotNull AppLayerSettings appLayerSettings) {
56-
Set<String> readOnlyAttributes = new HashSet<>();
57-
Optional.ofNullable(featureType.getSettings().getReadOnlyAttributes()).ifPresent(readOnlyAttributes::addAll);
58-
Optional.ofNullable(appLayerSettings.getReadOnlyAttributes()).ifPresent(readOnlyAttributes::addAll);
59-
return readOnlyAttributes;
56+
Set<String> editableAttributes = new HashSet<>();
57+
Optional.ofNullable(featureType.getSettings().getEditableAttributes()).ifPresent(editableAttributes::addAll);
58+
Optional.ofNullable(appLayerSettings.getReadOnlyAttributes()).ifPresent(editableAttributes::removeAll);
59+
Optional.ofNullable(featureType.getAllGeometryAttributeNames()).ifPresent(editableAttributes::addAll);
60+
return editableAttributes;
6061
}
6162

6263
public record AttributeWithSettings(TMAttributeDescriptor attributeDescriptor, AttributeSettings settings) {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
update feature_type as ft
2+
set settings = (ft.settings - 'readOnlyAttributes')
3+
|| jsonb_build_object(
4+
'editableAttributes',
5+
coalesce((
6+
select to_jsonb(array_agg(attr->> 'name'))
7+
from jsonb_array_elements(COALESCE(ft.attributes, '[]'::jsonb)) as attr
8+
where not exists (
9+
select 1
10+
from jsonb_array_elements_text(COALESCE(ft.settings -> 'readOnlyAttributes', '[]'::jsonb)) as name
11+
where name = (attr ->> 'name')
12+
)
13+
), '[]'::jsonb)
14+
)

src/main/resources/openapi/persistence-schemas.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ components:
240240
- attributeOrder
241241
- hideAttributes
242242
- attributeSettings
243-
- readOnlyAttributes
243+
- editableAttributes
244244
- attachmentAttributes
245245
properties:
246246
template:
@@ -257,8 +257,8 @@ components:
257257
type: array
258258
items:
259259
type: string
260-
readOnlyAttributes:
261-
description: List of attribute names that are not editable.
260+
editableAttributes:
261+
description: List of attribute names that are editable.
262262
type: array
263263
items:
264264
type: string

0 commit comments

Comments
 (0)