View Javadoc
1   /*
2    * Copyright (C) 2023 B3Partners B.V.
3    *
4    * SPDX-License-Identifier: MIT
5    */
6   package org.tailormap.api.configuration.dev;
7   
8   import static org.tailormap.api.persistence.Configuration.HOME_PAGE;
9   import static org.tailormap.api.persistence.Configuration.PORTAL_MENU;
10  import static org.tailormap.api.persistence.json.GeoServiceProtocol.QUANTIZEDMESH;
11  import static org.tailormap.api.persistence.json.GeoServiceProtocol.TILES3D;
12  import static org.tailormap.api.persistence.json.GeoServiceProtocol.WMS;
13  import static org.tailormap.api.persistence.json.GeoServiceProtocol.WMTS;
14  import static org.tailormap.api.persistence.json.GeoServiceProtocol.XYZ;
15  import static org.tailormap.api.persistence.json.HiddenLayerFunctionalityEnum.ATTRIBUTE_LIST;
16  import static org.tailormap.api.persistence.json.HiddenLayerFunctionalityEnum.EXPORT;
17  import static org.tailormap.api.persistence.json.HiddenLayerFunctionalityEnum.FEATURE_INFO;
18  import static org.tailormap.api.security.AuthorisationService.ACCESS_TYPE_VIEW;
19  
20  import java.io.IOException;
21  import java.lang.invoke.MethodHandles;
22  import java.net.URI;
23  import java.nio.charset.StandardCharsets;
24  import java.sql.SQLException;
25  import java.time.OffsetDateTime;
26  import java.time.ZoneId;
27  import java.util.ArrayList;
28  import java.util.Collection;
29  import java.util.List;
30  import java.util.Map;
31  import java.util.NoSuchElementException;
32  import java.util.Optional;
33  import java.util.Properties;
34  import java.util.Set;
35  import java.util.UUID;
36  import org.apache.solr.client.solrj.SolrServerException;
37  import org.quartz.SchedulerException;
38  import org.slf4j.Logger;
39  import org.slf4j.LoggerFactory;
40  import org.springframework.beans.factory.annotation.Value;
41  import org.springframework.boot.SpringApplication;
42  import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
43  import org.springframework.boot.context.event.ApplicationReadyEvent;
44  import org.springframework.context.ApplicationContext;
45  import org.springframework.context.event.EventListener;
46  import org.springframework.core.io.ClassPathResource;
47  import org.springframework.jdbc.core.simple.JdbcClient;
48  import org.springframework.transaction.annotation.Transactional;
49  import org.springframework.util.PropertyPlaceholderHelper;
50  import org.tailormap.api.admin.model.CapabilitiesLoadingEvent;
51  import org.tailormap.api.admin.model.TaskSchedule;
52  import org.tailormap.api.geotools.featuresources.AttachmentsHelper;
53  import org.tailormap.api.geotools.featuresources.FeatureSourceFactoryHelper;
54  import org.tailormap.api.geotools.featuresources.JDBCFeatureSourceHelper;
55  import org.tailormap.api.geotools.featuresources.WFSFeatureSourceHelper;
56  import org.tailormap.api.persistence.Application;
57  import org.tailormap.api.persistence.Catalog;
58  import org.tailormap.api.persistence.Configuration;
59  import org.tailormap.api.persistence.GeoService;
60  import org.tailormap.api.persistence.Group;
61  import org.tailormap.api.persistence.Page;
62  import org.tailormap.api.persistence.SearchIndex;
63  import org.tailormap.api.persistence.TMFeatureSource;
64  import org.tailormap.api.persistence.TMFeatureType;
65  import org.tailormap.api.persistence.Upload;
66  import org.tailormap.api.persistence.UploadCategory;
67  import org.tailormap.api.persistence.User;
68  import org.tailormap.api.persistence.helper.CapabilitiesLoadingProgressReporting;
69  import org.tailormap.api.persistence.helper.GeoServiceHelper;
70  import org.tailormap.api.persistence.json.AppContent;
71  import org.tailormap.api.persistence.json.AppLayerSettings;
72  import org.tailormap.api.persistence.json.AppSettings;
73  import org.tailormap.api.persistence.json.AppTreeLayerNode;
74  import org.tailormap.api.persistence.json.AppTreeLevelNode;
75  import org.tailormap.api.persistence.json.AppTreeNode;
76  import org.tailormap.api.persistence.json.AppUiSettings;
77  import org.tailormap.api.persistence.json.AttachmentAttributeType;
78  import org.tailormap.api.persistence.json.AttributeSettings;
79  import org.tailormap.api.persistence.json.AttributeValueSettings;
80  import org.tailormap.api.persistence.json.AuthorizationRule;
81  import org.tailormap.api.persistence.json.AuthorizationRuleDecision;
82  import org.tailormap.api.persistence.json.Bounds;
83  import org.tailormap.api.persistence.json.CatalogNode;
84  import org.tailormap.api.persistence.json.FeatureTypeRef;
85  import org.tailormap.api.persistence.json.FeatureTypeTemplate;
86  import org.tailormap.api.persistence.json.Filter;
87  import org.tailormap.api.persistence.json.FilterEditConfiguration;
88  import org.tailormap.api.persistence.json.FilterGroup;
89  import org.tailormap.api.persistence.json.GeoServiceDefaultLayerSettings;
90  import org.tailormap.api.persistence.json.GeoServiceLayerSettings;
91  import org.tailormap.api.persistence.json.GeoServiceSettings;
92  import org.tailormap.api.persistence.json.JDBCConnectionProperties;
93  import org.tailormap.api.persistence.json.MenuItem;
94  import org.tailormap.api.persistence.json.PageTile;
95  import org.tailormap.api.persistence.json.ServiceAuthentication;
96  import org.tailormap.api.persistence.json.TailormapObjectRef;
97  import org.tailormap.api.persistence.json.TileLayerHiDpiMode;
98  import org.tailormap.api.persistence.json.WMSStyle;
99  import org.tailormap.api.repository.ApplicationRepository;
100 import org.tailormap.api.repository.CatalogRepository;
101 import org.tailormap.api.repository.ConfigurationRepository;
102 import org.tailormap.api.repository.FeatureSourceRepository;
103 import org.tailormap.api.repository.GeoServiceRepository;
104 import org.tailormap.api.repository.GroupRepository;
105 import org.tailormap.api.repository.PageRepository;
106 import org.tailormap.api.repository.SearchIndexRepository;
107 import org.tailormap.api.repository.UploadRepository;
108 import org.tailormap.api.repository.UserRepository;
109 import org.tailormap.api.scheduling.IndexTask;
110 import org.tailormap.api.scheduling.TMJobDataMap;
111 import org.tailormap.api.scheduling.Task;
112 import org.tailormap.api.scheduling.TaskManagerService;
113 import org.tailormap.api.scheduling.TaskType;
114 import org.tailormap.api.security.InternalAdminAuthentication;
115 import org.tailormap.api.service.UploadsService;
116 import org.tailormap.api.solr.SolrHelper;
117 import org.tailormap.api.solr.SolrService;
118 import org.tailormap.api.viewer.model.AppStyling;
119 import org.tailormap.api.viewer.model.Component;
120 import org.tailormap.api.viewer.model.ComponentConfig;
121 import tools.jackson.core.JacksonException;
122 import tools.jackson.databind.json.JsonMapper;
123 
124 /**
125  * Populates entities to add services and applications to demo functionality, support development and use in integration
126  * tests with a common set of test data. See README.md for usage details.
127  */
128 @org.springframework.context.annotation.Configuration
129 @ConditionalOnProperty(name = "tailormap-api.database.populate-testdata", havingValue = "true")
130 public class PopulateTestData {
131 
132   private static final Logger logger =
133       LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
134   private final ApplicationContext appContext;
135   private final UserRepository userRepository;
136   private final GroupRepository groupRepository;
137   private final CatalogRepository catalogRepository;
138   private final GeoServiceRepository geoServiceRepository;
139   private final GeoServiceHelper geoServiceHelper;
140   private final SolrService solrService;
141   private final TaskManagerService taskManagerService;
142   private final FeatureSourceRepository featureSourceRepository;
143   private final ApplicationRepository applicationRepository;
144   private final ConfigurationRepository configurationRepository;
145   private final SearchIndexRepository searchIndexRepository;
146   private final FeatureSourceFactoryHelper featureSourceFactoryHelper;
147   private final UploadRepository uploadRepository;
148   private final PageRepository pageRepository;
149   private final JdbcClient jdbcClient;
150 
151   @Value("${spatial.dbs.connect:false}")
152   private boolean connectToSpatialDbs;
153 
154   @Value("#{'${tailormap-api.database.populate-testdata.categories}'.split(',')}")
155   private Set<String> categories;
156 
157   @Value("${spatial.dbs.localhost:true}")
158   private boolean connectToSpatialDbsAtLocalhost;
159 
160   @Value("${tailormap-api.database.populate-testdata.admin-hashed-password}")
161   private String adminHashedPassword;
162 
163   @Value("${tailormap-api.database.populate-testdata.management-hashed-password}")
164   private String managementHashedPassword;
165 
166   @Value("${tailormap-api.database.populate-testdata.exit:false}")
167   private boolean exit;
168 
169   @Value("${MAP5_URL:#{null}}")
170   private String map5url;
171 
172   private final String tiles3dProxyUsername = "b3p";
173 
174   // Password is for proxying a public service for testing purposes, not really secret
175   private final String tiles3dProxyPassword = "cOxPlJFWmtndFk0eVg5VdL";
176 
177   @Value("${tailormap-api.solr-batch-size:1000}")
178   private int solrBatchSize;
179 
180   @Value("${tailormap-api.solr-geometry-validation-rule:repairBuffer0}")
181   private String solrGeometryValidationRule;
182 
183   @Value("${tailormap-api.timeout}")
184   private int timeout;
185 
186   private static final String PROVINCIE_FEATURE_TYPE_NAME = "bestuurlijkegebieden:Provinciegebied";
187   private static final String GEMEENTE_FEATURE_TYPE_NAME = "bestuurlijkegebieden:Gemeentegebied";
188   private static final String NWB_WEGVAKKEN_FEATURE_TYPE_NAME = "nwbwegen:wegvakken";
189 
190   public PopulateTestData(
191       ApplicationContext appContext,
192       UserRepository userRepository,
193       GroupRepository groupRepository,
194       CatalogRepository catalogRepository,
195       GeoServiceRepository geoServiceRepository,
196       GeoServiceHelper geoServiceHelper,
197       SolrService solrService,
198       TaskManagerService taskManagerService,
199       FeatureSourceRepository featureSourceRepository,
200       ApplicationRepository applicationRepository,
201       ConfigurationRepository configurationRepository,
202       FeatureSourceFactoryHelper featureSourceFactoryHelper,
203       SearchIndexRepository searchIndexRepository,
204       UploadRepository uploadRepository,
205       PageRepository pageRepository,
206       JdbcClient jdbcClient) {
207     this.appContext = appContext;
208     this.userRepository = userRepository;
209     this.groupRepository = groupRepository;
210     this.catalogRepository = catalogRepository;
211     this.geoServiceRepository = geoServiceRepository;
212     this.geoServiceHelper = geoServiceHelper;
213     this.solrService = solrService;
214     this.taskManagerService = taskManagerService;
215     this.featureSourceRepository = featureSourceRepository;
216     this.applicationRepository = applicationRepository;
217     this.configurationRepository = configurationRepository;
218     this.featureSourceFactoryHelper = featureSourceFactoryHelper;
219     this.searchIndexRepository = searchIndexRepository;
220     this.uploadRepository = uploadRepository;
221     this.pageRepository = pageRepository;
222     this.jdbcClient = jdbcClient;
223   }
224 
225   @EventListener(ApplicationReadyEvent.class)
226   @Transactional
227   public void populate() throws Exception {
228     InternalAdminAuthentication.setInSecurityContext();
229     try {
230       // Used in conjunction with tailormap-api.database.clean=true so the database has been cleaned
231       // and the latest schema re-created
232       createTestUsersAndGroups();
233       createConfigurationTestData();
234       if (categories.contains("catalog")) {
235         createCatalogTestData();
236       }
237       if (categories.contains("apps")) {
238         createAppTestData();
239       }
240       if (categories.contains("search-index")) {
241         try {
242           createSolrIndex();
243         } catch (Exception e) {
244           logger.error("Exception creating Solr Index for testdata (continuing)", e);
245         }
246       }
247       if (categories.contains("search-index")) {
248         createSearchIndexTasks();
249       }
250       if (categories.contains("pages")) {
251         createPages();
252       }
253       logger.info("Test entities created");
254       if (categories.contains("uploads")) {
255         createUploads();
256         logger.info("Test uploads created");
257       }
258       if (categories.contains("drawing")) {
259         insertTestDrawing();
260         logger.info("Test drawing created");
261         try {
262           insertDrawingStyle();
263           logger.info("Test drawing style created");
264         } catch (Exception e) {
265           logger.error("Exception creating drawing style", e);
266         }
267       }
268     } finally {
269       InternalAdminAuthentication.clearSecurityContextAuthentication();
270     }
271     if (exit) {
272       // Exit after transaction is completed - for 'mvn verify' to populate testdata before
273       // integration tests
274       new Thread(() -> {
275             try {
276               logger.info("Exiting in 10 seconds");
277               Thread.sleep(10000);
278             } catch (InterruptedException ignored) {
279               // Ignore
280             }
281             SpringApplication.exit(appContext, () -> 0);
282             System.exit(0);
283           })
284           .start();
285     }
286   }
287 
288   public void createTestUsersAndGroups() throws NoSuchElementException {
289     Group groupFoo = new Group().setName("test-foo").setDescription("Used for integration tests.");
290     groupRepository.save(groupFoo);
291 
292     Group groupBar = new Group().setName("test-bar").setDescription("Used for integration tests.");
293     groupBar.addOrUpdateAdminProperty("group-property", true, true);
294     groupBar.addOrUpdateAdminProperty("group-private-property", 999.9, false);
295     groupRepository.save(groupBar);
296 
297     Group groupBaz = new Group().setName("test-baz").setDescription("Used for integration tests.");
298     groupRepository.save(groupBaz);
299 
300     // Normal user
301     User u = new User().setUsername("user").setPassword("{noop}user").setEmail("user@example.com");
302     u.getGroups().addAll(List.of(groupFoo, groupBar, groupBaz));
303     userRepository.save(u);
304 
305     // Foo only user
306     u = new User()
307         .setUsername("foo")
308         .setPassword("{noop}foo")
309         .setEmail("foo@example.com")
310         .setName("Foo only user");
311     u.getGroups().add(groupFoo);
312     userRepository.save(u);
313 
314     u = new User()
315         .setUsername("disabled")
316         .setPassword("{noop}disabled")
317         .setEmail("disabled@example.com")
318         .setEnabled(false);
319     userRepository.save(u);
320 
321     u = new User()
322         .setUsername("expired")
323         .setPassword("{noop}expired")
324         .setEmail("expired@example.com")
325         .setValidUntil(
326             OffsetDateTime.now(ZoneId.systemDefault()).minusDays(1).toZonedDateTime());
327     userRepository.save(u);
328 
329     // Superuser with all access
330     u = new User().setUsername("tm-admin").setPassword(adminHashedPassword);
331     u.addOrUpdateAdminProperty("some-property", "some-value", true);
332     u.addOrUpdateAdminProperty("admin-property", "private-value", false);
333     u.getGroups().add(groupRepository.findById(Group.ADMIN).orElseThrow());
334     u.getGroups().add(groupBar);
335     userRepository.save(u);
336 
337     u = new User().setUsername(Group.ACTUATOR).setPassword(managementHashedPassword);
338     u.getGroups().add(groupRepository.findById(Group.ACTUATOR).orElseThrow());
339     userRepository.save(u);
340   }
341 
342   private final List<AuthorizationRule> ruleAnonymousRead = List.of(new AuthorizationRule()
343       .groupName(Group.ANONYMOUS)
344       .decisions(Map.of(ACCESS_TYPE_VIEW, AuthorizationRuleDecision.ALLOW)));
345 
346   private final List<AuthorizationRule> ruleLoggedIn = List.of(new AuthorizationRule()
347       .groupName(Group.AUTHENTICATED)
348       .decisions(Map.of(ACCESS_TYPE_VIEW, AuthorizationRuleDecision.ALLOW)));
349 
350   @SuppressWarnings("PMD.AvoidUsingHardCodedIP")
351   private void createCatalogTestData() throws Exception {
352     Catalog catalog = catalogRepository.findById(Catalog.MAIN).orElseThrow();
353     CatalogNode rootCatalogNode = catalog.getNodes().getFirst();
354     CatalogNode catalogNode = new CatalogNode().id("test").title("Test services");
355     rootCatalogNode.addChildrenItem(catalogNode.getId());
356     catalog.getNodes().add(catalogNode);
357 
358     String osmAttribution = "© [OpenStreetMap](https://www.openstreetmap.org/copyright) contributors";
359 
360     Bounds rdTileGridExtent =
361         new Bounds().minx(-285401.92).maxx(595401.92).miny(22598.08).maxy(903401.92);
362 
363     Upload legend = new Upload()
364         .setCategory(UploadCategory.LEGEND)
365         .setFilename("gemeentegebied-legend.png")
366         .setMimeType("image/png")
367         .setContent(new ClassPathResource("test/gemeentegebied-legend.png").getContentAsByteArray())
368         .setLastModified(OffsetDateTime.now(ZoneId.systemDefault()));
369     uploadRepository.save(legend);
370 
371     Upload pdokLogo = uploadRepository.save(new Upload()
372         .setCategory(UploadCategory.LAYER_ATTACHED_FILE)
373         .setFilename("pdok_logo.png")
374         .setMimeType("image/png")
375         .setDescription("PDOK logo for testing layer attached uploads")
376         .setContent(new ClassPathResource("test/pdok_logo.png").getContentAsByteArray())
377         .setLastModified(OffsetDateTime.now(ZoneId.systemDefault())));
378 
379     Collection<GeoService> services = List.of(
380         new GeoService()
381             .setId("demo")
382             .setProtocol(WMS)
383             .setTitle("Demo")
384             .setPublished(true)
385             .setAuthorizationRules(ruleAnonymousRead)
386             .setUrl("https://demo.tailormap.com/geoserver/geodata/ows?SERVICE=WMS"),
387         new GeoService()
388             .setId("osm")
389             .setProtocol(XYZ)
390             .setTitle("OSM")
391             .setUrl("https://tile.openstreetmap.org/{z}/{x}/{y}.png")
392             .setAuthorizationRules(ruleAnonymousRead)
393             .setSettings(new GeoServiceSettings()
394                 .xyzCrs("EPSG:3857")
395                 .layerSettings(Map.of(
396                     "xyz",
397                     new GeoServiceLayerSettings()
398                         .attribution(osmAttribution)
399                         .maxZoom(19)))),
400         // Layer settings configured later, using the same settings for this one and proxied one
401         new GeoService()
402             .setId("snapshot-geoserver")
403             .setProtocol(WMS)
404             .setTitle("Test GeoServer")
405             .setUrl("https://snapshot.tailormap.nl/geoserver/wms")
406             .setAuthorizationRules(ruleAnonymousRead)
407             .setPublished(true),
408         new GeoService()
409             .setId("filtered-snapshot-geoserver")
410             .setProtocol(WMS)
411             .setTitle("Test GeoServer (with authorization rules)")
412             .setUrl("https://snapshot.tailormap.nl/geoserver/wms")
413             .setAuthorizationRules(List.of(
414                 new AuthorizationRule()
415                     .groupName("test-foo")
416                     .decisions(Map.of(ACCESS_TYPE_VIEW, AuthorizationRuleDecision.ALLOW)),
417                 new AuthorizationRule()
418                     .groupName("test-baz")
419                     .decisions(Map.of(ACCESS_TYPE_VIEW, AuthorizationRuleDecision.ALLOW))))
420             .setSettings(new GeoServiceSettings()
421                 .layerSettings(Map.of(
422                     "BGT",
423                     new GeoServiceLayerSettings()
424                         .addAuthorizationRulesItem(new AuthorizationRule()
425                             .groupName("test-foo")
426                             .decisions(Map.of(
427                                 ACCESS_TYPE_VIEW, AuthorizationRuleDecision.DENY)))
428                         .addAuthorizationRulesItem(new AuthorizationRule()
429                             .groupName("test-baz")
430                             .decisions(Map.of(
431                                 ACCESS_TYPE_VIEW, AuthorizationRuleDecision.ALLOW))))))
432             .setPublished(true),
433         new GeoService()
434             .setId("snapshot-geoserver-proxied")
435             .setProtocol(WMS)
436             .setTitle("Test GeoServer (proxied)")
437             .setUrl("https://snapshot.tailormap.nl/geoserver/wms")
438             .setAuthorizationRules(ruleAnonymousRead)
439             .setSettings(new GeoServiceSettings().useProxy(true)),
440         new GeoService()
441             .setId("openbasiskaart")
442             .setProtocol(WMTS)
443             .setTitle("Openbasiskaart")
444             .setUrl("https://www.openbasiskaart.nl/mapcache/wmts")
445             .setAuthorizationRules(ruleAnonymousRead)
446             .setSettings(new GeoServiceSettings()
447                 .defaultLayerSettings(new GeoServiceDefaultLayerSettings().attribution(osmAttribution))
448                 .layerSettings(Map.of(
449                     "osm",
450                     new GeoServiceLayerSettings()
451                         .title("Openbasiskaart")
452                         .hiDpiDisabled(false)
453                         .hiDpiMode(TileLayerHiDpiMode.SUBSTITUTELAYERSHOWNEXTZOOMLEVEL)
454                         .hiDpiSubstituteLayer("osm-hq")))),
455         new GeoService()
456             .setId("openbasiskaart-proxied")
457             .setProtocol(WMTS)
458             .setTitle("Openbasiskaart (proxied)")
459             .setUrl("https://www.openbasiskaart.nl/mapcache/wmts")
460             .setAuthorizationRules(ruleAnonymousRead)
461             // The service actually doesn't require authentication, but also doesn't mind it
462             // Just for testing
463             .setAuthentication(new ServiceAuthentication()
464                 .method(ServiceAuthentication.MethodEnum.PASSWORD)
465                 .username("test")
466                 .password("test"))
467             .setSettings(new GeoServiceSettings()
468                 .useProxy(true)
469                 .defaultLayerSettings(new GeoServiceDefaultLayerSettings().attribution(osmAttribution))
470                 .layerSettings(Map.of(
471                     "osm",
472                     new GeoServiceLayerSettings()
473                         .hiDpiDisabled(false)
474                         .hiDpiMode(TileLayerHiDpiMode.SUBSTITUTELAYERSHOWNEXTZOOMLEVEL)
475                         .hiDpiSubstituteLayer("osm-hq")))),
476         new GeoService()
477             .setId("openbasiskaart-tms")
478             .setProtocol(XYZ)
479             .setTitle("Openbasiskaart (TMS)")
480             .setUrl("https://openbasiskaart.nl/mapcache/tms/1.0.0/osm@rd/{z}/{x}/{-y}.png")
481             .setAuthorizationRules(ruleAnonymousRead)
482             .setSettings(
483                 new GeoServiceSettings()
484                     .xyzCrs("EPSG:28992")
485                     .defaultLayerSettings(
486                         new GeoServiceDefaultLayerSettings().attribution(osmAttribution))
487                     .layerSettings(
488                         Map.of(
489                             "xyz",
490                             new GeoServiceLayerSettings()
491                                 .maxZoom(15)
492                                 .tileGridExtent(rdTileGridExtent)
493                                 .hiDpiDisabled(false)
494                                 .hiDpiMode(
495                                     TileLayerHiDpiMode
496                                         .SUBSTITUTELAYERTILEPIXELRATIOONLY)
497                                 .hiDpiSubstituteLayer(
498                                     "https://openbasiskaart.nl/mapcache/tms/1.0.0/osm-hq@rd-hq/{z}/{x}/{-y}.png")))),
499         new GeoService()
500             .setId("pdok-hwh-luchtfotorgb")
501             .setProtocol(WMTS)
502             .setTitle("PDOK HWH luchtfoto")
503             .setUrl("https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0")
504             .setAuthorizationRules(ruleAnonymousRead)
505             .setPublished(true)
506             .setSettings(new GeoServiceSettings()
507                 .defaultLayerSettings(new GeoServiceDefaultLayerSettings()
508                     .attribution("© [Beeldmateriaal.nl](https://beeldmateriaal.nl)")
509                     .hiDpiDisabled(false))
510                 .putLayerSettingsItem(
511                     "Actueel_orthoHR", new GeoServiceLayerSettings().title("Luchtfoto"))),
512         new GeoService()
513             .setId("b3p-mapproxy-luchtfoto")
514             .setProtocol(XYZ)
515             .setTitle("Luchtfoto (TMS)")
516             .setUrl("https://mapproxy.b3p.nl/tms/1.0.0/luchtfoto/EPSG28992/{z}/{x}/{-y}.jpeg")
517             .setAuthorizationRules(ruleAnonymousRead)
518             .setPublished(true)
519             .setSettings(new GeoServiceSettings()
520                 .xyzCrs("EPSG:28992")
521                 .defaultLayerSettings(new GeoServiceDefaultLayerSettings()
522                     .attribution("© [Beeldmateriaal.nl](https://beeldmateriaal.nl)")
523                     .hiDpiDisabled(false))
524                 .layerSettings(Map.of(
525                     "xyz",
526                     new GeoServiceLayerSettings()
527                         .maxZoom(14)
528                         .tileGridExtent(rdTileGridExtent)
529                         .hiDpiMode(TileLayerHiDpiMode.SHOWNEXTZOOMLEVEL)))),
530         new GeoService()
531             .setId("at-basemap")
532             .setProtocol(WMTS)
533             .setTitle("basemap.at")
534             .setUrl("https://mapsneu.wien.gv.at/basemapneu/1.0.0/WMTSCapabilities.xml")
535             .setAuthorizationRules(ruleAnonymousRead)
536             .setPublished(true)
537             .setSettings(new GeoServiceSettings()
538                 .defaultLayerSettings(new GeoServiceDefaultLayerSettings()
539                     .attribution("© [basemap.at](https://basemap.at)")
540                     .hiDpiDisabled(true))
541                 .layerSettings(Map.of(
542                     "geolandbasemap",
543                     new GeoServiceLayerSettings()
544                         .title("Basemap")
545                         .hiDpiDisabled(false)
546                         .hiDpiMode(TileLayerHiDpiMode.SUBSTITUTELAYERTILEPIXELRATIOONLY)
547                         .hiDpiSubstituteLayer("bmaphidpi"),
548                     "bmaporthofoto30cm",
549                     new GeoServiceLayerSettings()
550                         .title("Orthophoto")
551                         .hiDpiDisabled(false)))),
552         new GeoService()
553             .setId("pdok-kadaster-bestuurlijkegebieden")
554             .setProtocol(WMS)
555             .setUrl("https://service.pdok.nl/kadaster/brk-bestuurlijke-gebieden/wms/v1_0?service=WMS")
556             .setAuthorizationRules(ruleAnonymousRead)
557             .setSettings(new GeoServiceSettings()
558                 .defaultLayerSettings(new GeoServiceDefaultLayerSettings()
559                     .description("This layer shows an administrative boundary.\n\n[logo]("
560                         + UploadsService.UPLOAD_MARKDOWN_SCHEME + pdokLogo.getId() + ")"))
561                 // No attribution required: service is CC0
562                 .serverType(GeoServiceSettings.ServerTypeEnum.MAPSERVER)
563                 .useProxy(true)
564                 .putLayerSettingsItem(
565                     "Gemeentegebied",
566                     new GeoServiceLayerSettings()
567                         .legendImageId(legend.getId().toString())))
568             .setPublished(true)
569             .setTitle("PDOK Kadaster bestuurlijke gebieden"),
570         new GeoService()
571             .setId("bestuurlijkegebieden-proxied")
572             .setProtocol(WMS)
573             .setUrl("https://service.pdok.nl/kadaster/brk-bestuurlijke-gebieden/wms/v1_0?service=WMS")
574             .setAuthorizationRules(ruleAnonymousRead)
575             // The service actually doesn't require authentication, but also doesn't mind it
576             // Just for testing that proxied services with auth are not available in public
577             // apps (even when logged in), in any controllers (map, proxy, features)
578             .setAuthentication(new ServiceAuthentication()
579                 .method(ServiceAuthentication.MethodEnum.PASSWORD)
580                 .username("test")
581                 .password("test"))
582             .setSettings(new GeoServiceSettings()
583                 // No attribution required: service is CC0
584                 .serverType(GeoServiceSettings.ServerTypeEnum.MAPSERVER)
585                 .useProxy(true))
586             .setPublished(true)
587             .setTitle("Bestuurlijke gebieden (proxied met auth)"),
588         new GeoService()
589             .setId("pdok-rws-nwbwegen")
590             .setProtocol(WMS)
591             .setUrl("https://service.pdok.nl/rws/nwbwegen/wms/v1_0?service=WMS")
592             .setAuthorizationRules(ruleAnonymousRead)
593             .setSettings(new GeoServiceSettings()
594                 // No attribution required: service is CC0
595                 .serverType(GeoServiceSettings.ServerTypeEnum.MAPSERVER))
596             .setPublished(true)
597             .setTitle("PDOK RWS Nationaal Wegenbestand"),
598         // The same WMS services as above, with layers linked to a WFS feature source with an explicit
599         // VERSION=1.1.0 in the URL
600         new GeoService()
601             .setId("pdok-bestuurlijkegebieden-wfs11")
602             .setProtocol(WMS)
603             .setUrl("https://service.pdok.nl/kadaster/brk-bestuurlijke-gebieden/wms/v1_0?service=WMS")
604             .setAuthorizationRules(ruleAnonymousRead)
605             .setSettings(new GeoServiceSettings()
606                 // No attribution required: service is CC0
607                 .serverType(GeoServiceSettings.ServerTypeEnum.MAPSERVER))
608             .setPublished(true)
609             .setTitle("PDOK Kadaster bestuurlijke gebieden (WFS 1.1.0)"),
610         new GeoService()
611             .setId("geoserver-wfs11")
612             .setProtocol(WMS)
613             .setUrl("https://snapshot.tailormap.nl/geoserver/wms")
614             .setAuthorizationRules(ruleAnonymousRead)
615             .setPublished(true)
616             .setTitle("Test GeoServer (WFS 1.1.0)"),
617         new GeoService()
618             .setId("geoserver-wfs20")
619             .setProtocol(WMS)
620             .setUrl("https://snapshot.tailormap.nl/geoserver/wms")
621             .setAuthorizationRules(ruleAnonymousRead)
622             .setPublished(true)
623             .setTitle("Test GeoServer (WFS 2.0.0)"),
624         new GeoService()
625             .setId("3dbag_utrecht")
626             .setProtocol(TILES3D)
627             .setUrl("https://3dtilesnederland.nl/tiles/1.0/implicit/nederland/344.json")
628             .setTitle("3D BAG Utrecht")
629             .setPublished(true)
630             .setAuthorizationRules(ruleAnonymousRead),
631         new GeoService()
632             .setId("ahn_terrain_model")
633             .setProtocol(QUANTIZEDMESH)
634             .setUrl(
635                 "https://api.pdok.nl/kadaster/3d-basisvoorziening/ogc/v1/collections/digitaalterreinmodel")
636             .setTitle("AHN Terrain Model")
637             .setPublished(true)
638             .setAuthorizationRules(ruleAnonymousRead),
639         new GeoService()
640             .setId("3d_basisvoorziening_gebouwen_proxy")
641             .setProtocol(TILES3D)
642             .setUrl(
643                 "https://api.pdok.nl/kadaster/3d-basisvoorziening/ogc/v1_0/collections/gebouwen/3dtiles")
644             .setTitle("3D Basisvoorziening Gebouwen Proxy")
645             .setPublished(true)
646             .setAuthorizationRules(ruleAnonymousRead)
647             .setSettings(new GeoServiceSettings().useProxy(true)),
648         new GeoService()
649             .setId("3d_utrecht_proxied_auth")
650             .setProtocol(TILES3D)
651             .setUrl("https://snapshot.tailormap.nl/tiles3d-proxy/3dtiles")
652             .setTitle("3D Utrecht Proxied with Authorization")
653             .setPublished(true)
654             .setAuthorizationRules(ruleAnonymousRead)
655             .setAuthentication(new ServiceAuthentication()
656                 .method(ServiceAuthentication.MethodEnum.PASSWORD)
657                 .username(tiles3dProxyUsername)
658                 .password(tiles3dProxyPassword))
659             .setSettings(new GeoServiceSettings().useProxy(true))
660         // TODO MapServer WMS "https://wms.geonorge.no/skwms1/wms.adm_enheter_historisk"
661         );
662 
663     if (map5url != null) {
664       GeoServiceLayerSettings osmAttr = new GeoServiceLayerSettings().attribution(osmAttribution);
665       GeoServiceLayerSettings map5Attr = new GeoServiceLayerSettings()
666           .attribution("Kaarten: [Map5.nl](https://map5.nl), data: " + osmAttribution);
667       services = new ArrayList<>(services);
668       services.add(new GeoService()
669           .setId("map5")
670           .setProtocol(WMTS)
671           .setTitle("Map5")
672           .setUrl(map5url)
673           .setAuthorizationRules(ruleAnonymousRead)
674           .setSettings(new GeoServiceSettings()
675               .defaultLayerSettings(new GeoServiceDefaultLayerSettings().hiDpiDisabled(true))
676               .layerSettings(Map.of(
677                   "openlufo",
678                   new GeoServiceLayerSettings()
679                       .attribution("© [Beeldmateriaal.nl](https://beeldmateriaal.nl), "
680                           + osmAttribution),
681                   "luforoadslabels",
682                   osmAttr,
683                   "map5topo",
684                   new GeoServiceLayerSettings()
685                       .attribution(map5Attr.getAttribution())
686                       .hiDpiDisabled(false)
687                       .hiDpiMode(TileLayerHiDpiMode.SUBSTITUTELAYERSHOWNEXTZOOMLEVEL)
688                       .hiDpiSubstituteLayer("map5topo_hq"),
689                   "map5topo_gray",
690                   map5Attr,
691                   "map5topo_simple",
692                   map5Attr,
693                   "map5topo_simple_gray",
694                   map5Attr,
695                   "opensimpletopo",
696                   osmAttr,
697                   "opensimpletopo_gray",
698                   osmAttr,
699                   "opentopo",
700                   osmAttr,
701                   "opentopo_gray",
702                   osmAttr))));
703     }
704 
705     for (GeoService geoService : services) {
706       try {
707         geoServiceHelper.loadServiceCapabilities(geoService);
708       } catch (Exception e) {
709         logger.error(
710             "Error loading capabilities for {} service URL {}: {}, {}",
711             geoService.getProtocol().getValue(),
712             geoService.getUrl(),
713             e.getClass(),
714             e.getMessage());
715       }
716 
717       geoServiceRepository.save(geoService);
718       catalogNode.addItemsItem(new TailormapObjectRef()
719           .kind(TailormapObjectRef.KindEnum.GEO_SERVICE)
720           .id(geoService.getId()));
721     }
722 
723     TMFeatureSource bestuurlijkeGebiedenWfs = new TMFeatureSource()
724         .setProtocol(TMFeatureSource.Protocol.WFS)
725         .setUrl("https://service.pdok.nl/kadaster/brk-bestuurlijke-gebieden/wfs/v1_0?service=WFS&VERSION=2.0.0")
726         .setTitle("Bestuurlijke gebieden")
727         .setNotes(
728             "Overzicht van de bestuurlijke indeling van Nederland in gemeenten en provincies alsmede de rijksgrens. Gegevens zijn afgeleid uit de Basisregistratie Kadaster (BRK).");
729     // A large WFS (wegvakken has over 1.6 million features) for testing paging and counting. No VERSION in the
730     // URL, as configured by a user who reported an empty attribute list
731     TMFeatureSource nwbWfs = new TMFeatureSource()
732         .setProtocol(TMFeatureSource.Protocol.WFS)
733         .setUrl("https://service.pdok.nl/rws/nwbwegen/wfs/v1_0?service=WFS")
734         .setTitle("Nationaal Wegenbestand (NWB)");
735 
736     TMFeatureSource bestuurlijkeGebiedenWfs11 = new TMFeatureSource()
737         .setProtocol(TMFeatureSource.Protocol.WFS)
738         .setUrl("https://service.pdok.nl/kadaster/brk-bestuurlijke-gebieden/wfs/v1_0?service=WFS&VERSION=1.1.0")
739         .setTitle("Bestuurlijke gebieden (WFS 1.1.0)");
740     TMFeatureSource geoServerWfs11 = new TMFeatureSource()
741         .setProtocol(TMFeatureSource.Protocol.WFS)
742         .setUrl("https://snapshot.tailormap.nl/geoserver/wfs?VERSION=1.1.0")
743         .setTitle("Test GeoServer (WFS 1.1.0)");
744     TMFeatureSource geoServerWfs20 = new TMFeatureSource()
745         .setProtocol(TMFeatureSource.Protocol.WFS)
746         .setUrl("https://snapshot.tailormap.nl/geoserver/wfs?VERSION=2.0.0")
747         .setTitle("Test GeoServer (WFS 2.0.0)");
748 
749     List<TMFeatureSource> testWFS = List.of(
750         //            "demo",
751         new TMFeatureSource()
752             .setProtocol(TMFeatureSource.Protocol.WFS)
753             .setUrl("https://demo.tailormap.com/geoserver/geodata/wfs")
754             .setTitle("WFS for Demo")
755             .setLinkedService(geoServiceRepository.findById("demo").orElseThrow()),
756         //            "snapshot-geoserver",
757         new TMFeatureSource()
758             .setProtocol(TMFeatureSource.Protocol.WFS)
759             .setUrl("https://snapshot.tailormap.nl/geoserver/wfs?")
760             .setTitle("WFS for Test GeoServer")
761             .setLinkedService(geoServiceRepository
762                 .findById("snapshot-geoserver")
763                 .orElseThrow()),
764         bestuurlijkeGebiedenWfs,
765         nwbWfs,
766         bestuurlijkeGebiedenWfs11,
767         geoServerWfs11,
768         geoServerWfs20);
769     featureSourceRepository.saveAll(testWFS);
770 
771     CatalogNode wfsFeatureSourceCatalogNode =
772         new CatalogNode().id("wfs_feature_sources").title("WFS feature sources");
773     rootCatalogNode.addChildrenItem(wfsFeatureSourceCatalogNode.getId());
774     catalog.getNodes().add(wfsFeatureSourceCatalogNode);
775 
776     for (TMFeatureSource featureSource : testWFS) {
777       new WFSFeatureSourceHelper()
778           .loadCapabilities(
779               featureSource,
780               timeout,
781               (CapabilitiesLoadingProgressReporting) event -> {
782                 logger.debug("WFS loading: {}", event);
783               },
784               new CapabilitiesLoadingEvent()
785                   .id(featureSource.getId().toString())
786                   .title(featureSource.getTitle())
787                   .startedAt(OffsetDateTime.now(ZoneId.systemDefault()))
788                   .message("Loading capabilities for " + featureSource.getTitle()
789                       + " feature source"));
790       wfsFeatureSourceCatalogNode.addItemsItem(new TailormapObjectRef()
791           .kind(TailormapObjectRef.KindEnum.FEATURE_SOURCE)
792           .id(featureSource.getId().toString()));
793     }
794 
795     String geodataPassword = "980f1c8A-25933b2";
796 
797     Map<String, TMFeatureSource> featureSources = Map.of(
798         "postgis",
799         new TMFeatureSource()
800             .setProtocol(TMFeatureSource.Protocol.JDBC)
801             .setTitle("PostGIS")
802             .setJdbcConnection(new JDBCConnectionProperties()
803                 .dbtype(JDBCConnectionProperties.DbtypeEnum.POSTGIS)
804                 .host(connectToSpatialDbsAtLocalhost ? "127.0.0.1" : "postgis")
805                 .port(connectToSpatialDbsAtLocalhost ? 54322 : 5432)
806                 .database("geodata")
807                 .schema("public")
808                 .additionalProperties(Map.of("connectionOptions", "?ApplicationName=tailormap-api")))
809             .setAuthentication(new ServiceAuthentication()
810                 .method(ServiceAuthentication.MethodEnum.PASSWORD)
811                 .username("geodata")
812                 .password(geodataPassword)),
813         "postgis_osm",
814         new TMFeatureSource()
815             .setProtocol(TMFeatureSource.Protocol.JDBC)
816             .setTitle("PostGIS OSM")
817             .setJdbcConnection(new JDBCConnectionProperties()
818                 .dbtype(JDBCConnectionProperties.DbtypeEnum.POSTGIS)
819                 .host(connectToSpatialDbsAtLocalhost ? "127.0.0.1" : "postgis")
820                 .port(connectToSpatialDbsAtLocalhost ? 54322 : 5432)
821                 .database("geodata")
822                 .schema("osm")
823                 .additionalProperties(Map.of("connectionOptions", "?ApplicationName=tailormap-api")))
824             .setAuthentication(new ServiceAuthentication()
825                 .method(ServiceAuthentication.MethodEnum.PASSWORD)
826                 .username("geodata")
827                 .password(geodataPassword)),
828         "oracle",
829         new TMFeatureSource()
830             .setProtocol(TMFeatureSource.Protocol.JDBC)
831             .setTitle("Oracle")
832             .setJdbcConnection(new JDBCConnectionProperties()
833                 .dbtype(JDBCConnectionProperties.DbtypeEnum.ORACLE)
834                 .host(connectToSpatialDbsAtLocalhost ? "127.0.0.1" : "oracle")
835                 .database("/FREEPDB1")
836                 .schema("GEODATA")
837                 .additionalProperties(Map.of("connectionOptions", "?oracle.jdbc.J2EE13Compliant=true")))
838             .setAuthentication(new ServiceAuthentication()
839                 .method(ServiceAuthentication.MethodEnum.PASSWORD)
840                 .username("geodata")
841                 .password(geodataPassword)),
842         "sqlserver",
843         new TMFeatureSource()
844             .setProtocol(TMFeatureSource.Protocol.JDBC)
845             .setTitle("MS SQL Server")
846             .setJdbcConnection(new JDBCConnectionProperties()
847                 .dbtype(JDBCConnectionProperties.DbtypeEnum.SQLSERVER)
848                 .host(connectToSpatialDbsAtLocalhost ? "127.0.0.1" : "sqlserver")
849                 .database("geodata")
850                 .schema("dbo")
851                 .additionalProperties(Map.of("connectionOptions", ";encrypt=false")))
852             .setAuthentication(new ServiceAuthentication()
853                 .method(ServiceAuthentication.MethodEnum.PASSWORD)
854                 .username("geodata")
855                 .password(geodataPassword)));
856     featureSourceRepository.saveAll(featureSources.values());
857 
858     geoServiceRepository.findById("pdok-kadaster-bestuurlijkegebieden").ifPresent(geoService -> {
859       geoService
860           .getSettings()
861           .getLayerSettings()
862           .put(
863               "Provinciegebied",
864               new GeoServiceLayerSettings()
865                   .description("The administrative boundary of Dutch Provinces, connected to a WFS.")
866                   .descriptionInPopup(true)
867                   .featureType(new FeatureTypeRef()
868                       .featureSourceId(bestuurlijkeGebiedenWfs.getId())
869                       .featureTypeName(PROVINCIE_FEATURE_TYPE_NAME))
870                   .title("Provinciegebied (WFS)"));
871       // For testing paging: more features than fit on one page, and the WFS 2.0.0 server (MapServer) does not
872       // return numberMatched in a page, so the total comes from a separate hits request
873       geoService
874           .getSettings()
875           .getLayerSettings()
876           .get("Gemeentegebied")
877           .title("Gemeentegebied (WFS)")
878           .description("The administrative boundary of Dutch Municipalities, connected to a WFS 2.0.0 which"
879               + " does not return the total number of features.\n\n[logo]("
880               + UploadsService.UPLOAD_MARKDOWN_SCHEME + pdokLogo.getId() + ")")
881           .descriptionInPopup(true)
882           .featureType(new FeatureTypeRef()
883               .featureSourceId(bestuurlijkeGebiedenWfs.getId())
884               .featureTypeName(GEMEENTE_FEATURE_TYPE_NAME));
885       geoServiceRepository.save(geoService);
886     });
887 
888     geoServiceRepository.findById("bestuurlijkegebieden-proxied").ifPresent(geoService -> {
889       geoService
890           .getSettings()
891           .getLayerSettings()
892           .put(
893               "Provinciegebied",
894               new GeoServiceLayerSettings()
895                   .featureType(new FeatureTypeRef()
896                       .featureSourceId(bestuurlijkeGebiedenWfs.getId())
897                       .featureTypeName(PROVINCIE_FEATURE_TYPE_NAME))
898                   .title("Provinciegebied (WFS, proxied met auth)"));
899       geoServiceRepository.save(geoService);
900     });
901 
902     geoServiceRepository.findById("pdok-rws-nwbwegen").ifPresent(geoService -> {
903       geoService
904           .getSettings()
905           .putLayerSettingsItem(
906               "wegvakken",
907               new GeoServiceLayerSettings()
908                   .featureType(new FeatureTypeRef()
909                       .featureSourceId(nwbWfs.getId())
910                       .featureTypeName(NWB_WEGVAKKEN_FEATURE_TYPE_NAME))
911                   .title("Wegvakken (NWB, WFS)"));
912       geoServiceRepository.save(geoService);
913     });
914 
915     // For testing basic functionality such as paging with WFS 1.1.0, with both MapServer and GeoServer
916     geoServiceRepository.findById("pdok-bestuurlijkegebieden-wfs11").ifPresent(geoService -> {
917       geoService
918           .getSettings()
919           .putLayerSettingsItem(
920               "Gemeentegebied",
921               new GeoServiceLayerSettings()
922                   .featureType(new FeatureTypeRef()
923                       .featureSourceId(bestuurlijkeGebiedenWfs11.getId())
924                       .featureTypeName(GEMEENTE_FEATURE_TYPE_NAME))
925                   .title("Gemeentegebied (WFS 1.1.0)"));
926       geoServiceRepository.save(geoService);
927     });
928     geoServiceRepository.findById("geoserver-wfs11").ifPresent(geoService -> {
929       geoService
930           .getSettings()
931           .putLayerSettingsItem(
932               "postgis:begroeidterreindeel",
933               new GeoServiceLayerSettings()
934                   .featureType(new FeatureTypeRef()
935                       .featureSourceId(geoServerWfs11.getId())
936                       .featureTypeName("postgis:begroeidterreindeel"))
937                   .title("begroeidterreindeel (WFS 1.1.0)"));
938       geoServiceRepository.save(geoService);
939     });
940     // GeoServer outputs circular arcs from the PostGIS BGT data as gml:ArcString in GML 3 (WFS 1.1.0 and 2.0.0)
941     geoServiceRepository.findById("geoserver-wfs20").ifPresent(geoService -> {
942       geoService
943           .getSettings()
944           .putLayerSettingsItem(
945               "postgis:begroeidterreindeel",
946               new GeoServiceLayerSettings()
947                   .featureType(new FeatureTypeRef()
948                       .featureSourceId(geoServerWfs20.getId())
949                       .featureTypeName("postgis:begroeidterreindeel"))
950                   .title("begroeidterreindeel (WFS 2.0.0)"));
951       geoServiceRepository.save(geoService);
952     });
953 
954     CatalogNode featureSourceCatalogNode =
955         new CatalogNode().id("feature_sources").title("Test feature sources");
956     rootCatalogNode.addChildrenItem(featureSourceCatalogNode.getId());
957     catalog.getNodes().add(featureSourceCatalogNode);
958 
959     CatalogNode geoServiceAdminControllerNode =
960         new CatalogNode().id("GeoServiceAdminController").title("GeoServiceAdminController test node");
961     rootCatalogNode.addChildrenItem(geoServiceAdminControllerNode.getId());
962     catalog.getNodes().add(geoServiceAdminControllerNode);
963     CatalogNode featureSourceAdminControllerNode =
964         new CatalogNode().id("FeatureSourceAdminController").title("FeatureSourceAdminController test node");
965     rootCatalogNode.addChildrenItem(featureSourceAdminControllerNode.getId());
966     catalog.getNodes().add(featureSourceAdminControllerNode);
967 
968     for (TMFeatureSource featureSource : featureSources.values()) {
969       featureSourceCatalogNode.addItemsItem(new TailormapObjectRef()
970           .kind(TailormapObjectRef.KindEnum.FEATURE_SOURCE)
971           .id(featureSource.getId().toString()));
972     }
973     catalogRepository.save(catalog);
974 
975     if (connectToSpatialDbs) {
976       featureSources.values().forEach(fs -> {
977         try {
978           if (fs.getProtocol() == TMFeatureSource.Protocol.JDBC) {
979             new JDBCFeatureSourceHelper()
980                 .loadCapabilities(
981                     fs,
982                     timeout,
983                     (CapabilitiesLoadingProgressReporting) event -> {
984                       logger.debug("JDBC loading: {}", event);
985                     },
986                     new CapabilitiesLoadingEvent()
987                         .id(fs.getId().toString())
988                         .title(fs.getTitle())
989                         .message("Loading JDBC capabilities for " + fs.getTitle()
990                             + " feature source"));
991           }
992         } catch (Exception e) {
993           logger.error("Error loading capabilities for feature source {}", fs.getTitle(), e);
994         }
995       });
996 
997       services.stream()
998           // Set layer settings for both the proxied and non-proxied one, but don't overwrite the
999           // authorization rules for the "filtered-snapshot-geoserver" service
1000           .filter(s -> s.getId().startsWith("snapshot-geoserver"))
1001           .forEach(s -> s.getSettings()
1002               .layerSettings(Map.of(
1003                   "postgis:begroeidterreindeel",
1004                   new GeoServiceLayerSettings()
1005                       .description("""
1006 This layer shows data from https://www.postgis.net/
1007 
1008 https://postgis.net/brand.svg""")
1009                       .featureType(new FeatureTypeRef()
1010                           .featureSourceId(featureSources
1011                               .get("postgis")
1012                               .getId())
1013                           .featureTypeName("begroeidterreindeel")),
1014                   "postgis:bak",
1015                   new GeoServiceLayerSettings()
1016                       .featureType(new FeatureTypeRef()
1017                           .featureSourceId(featureSources
1018                               .get("postgis")
1019                               .getId())
1020                           .featureTypeName("bak")),
1021                   "postgis:kadastraal_perceel",
1022                   new GeoServiceLayerSettings()
1023                       .description("cadastral parcel label points")
1024                       .featureType(new FeatureTypeRef()
1025                           .featureSourceId(featureSources
1026                               .get("postgis")
1027                               .getId())
1028                           .featureTypeName("kadastraal_perceel")),
1029                   "sqlserver:wegdeel",
1030                   new GeoServiceLayerSettings()
1031                       .attribution(
1032                           "CC BY 4.0 [BGT/Kadaster](https://www.nationaalgeoregister.nl/geonetwork/srv/api/records/2cb4769c-b56e-48fa-8685-c48f61b9a319)")
1033                       .description("""
1034 This layer shows data from [MS SQL Server](https://learn.microsoft.com/en-us/sql/relational-databases/spatial/spatial-data-sql-server).
1035 
1036 https://upload.wikimedia.org/wikipedia/commons/6/69/Microsoft_SQL_Server_Logo.png""")
1037                       .featureType(new FeatureTypeRef()
1038                           .featureSourceId(featureSources
1039                               .get("sqlserver")
1040                               .getId())
1041                           .featureTypeName("wegdeel")),
1042                   "oracle:WATERDEEL",
1043                   new GeoServiceLayerSettings()
1044                       .description("This layer shows data from Oracle Spatial.")
1045                       .featureType(new FeatureTypeRef()
1046                           .featureSourceId(featureSources
1047                               .get("oracle")
1048                               .getId())
1049                           .featureTypeName("WATERDEEL")),
1050                   "postgis:osm_polygon",
1051                   new GeoServiceLayerSettings()
1052                       .description("This layer shows OSM data from postgis.")
1053                       .featureType(new FeatureTypeRef()
1054                           .featureSourceId(featureSources
1055                               .get("postgis_osm")
1056                               .getId())
1057                           .featureTypeName("osm_polygon")))));
1058     }
1059 
1060     bestuurlijkeGebiedenWfs.getFeatureTypes().stream()
1061         .filter(ft -> ft.getName().equals(PROVINCIE_FEATURE_TYPE_NAME))
1062         .findFirst()
1063         .ifPresent(ft -> {
1064           ft.getSettings().addHideAttributesItem("identificatie");
1065           ft.getSettings().addHideAttributesItem("ligtInLandCode");
1066           ft.getSettings().addHideAttributesItem("fuuid");
1067           ft.getSettings().putAttributeSettingsItem("naam", new AttributeSettings().title("Naam"));
1068           ft.getSettings()
1069               .setTemplate(new FeatureTypeTemplate()
1070                   .templateLanguage("simple")
1071                   .markupLanguage("markdown")
1072                   .template("""
1073 ### Provincie
1074 Deze provincie heet **{{naam}}** en ligt in _{{ligtInLandNaam}}_.
1075 
1076 | Attribuut | Waarde             |
1077 | --------- | ------------------ |
1078 | `code`    | {{code}}           |
1079 | `naam`    | {{naam}}           |
1080 | `ligt in` | {{ligtInLandNaam}} |"""));
1081         });
1082 
1083     featureSources.get("postgis").getFeatureTypes().stream()
1084         .filter(ft -> ft.getName().equals("begroeidterreindeel"))
1085         .findFirst()
1086         .ifPresent(ft -> {
1087           ft.getSettings().addHideAttributesItem("terminationdate");
1088           ft.getSettings().addHideAttributesItem("geom_kruinlijn");
1089           ft.getSettings().putAttributeSettingsItem("gmlid", new AttributeSettings().title("GML ID"));
1090           ft.getSettings()
1091               .putAttributeSettingsItem("identificatie", new AttributeSettings().title("Identificatie"));
1092           ft.getSettings()
1093               .putAttributeSettingsItem(
1094                   "tijdstipregistratie", new AttributeSettings().title("Registratie"));
1095           ft.getSettings()
1096               .putAttributeSettingsItem(
1097                   "eindregistratie", new AttributeSettings().title("Eind registratie"));
1098           ft.getSettings().putAttributeSettingsItem("class", new AttributeSettings().title("Klasse"));
1099           ft.getSettings()
1100               .putAttributeSettingsItem("bronhouder", new AttributeSettings().title("Bronhouder"));
1101           ft.getSettings()
1102               .putAttributeSettingsItem("inonderzoek", new AttributeSettings().title("In onderzoek"));
1103           ft.getSettings()
1104               .putAttributeSettingsItem(
1105                   "relatievehoogteligging", new AttributeSettings().title("Relatieve hoogteligging"));
1106           ft.getSettings()
1107               .putAttributeSettingsItem("bgt_status", new AttributeSettings().title("BGT status"));
1108           ft.getSettings()
1109               .putAttributeSettingsItem("plus_status", new AttributeSettings().title("Plus-status"));
1110           ft.getSettings()
1111               .putAttributeSettingsItem(
1112                   "plus_fysiekvoorkomen", new AttributeSettings().title("Plus-fysiek voorkomen"));
1113           ft.getSettings()
1114               .putAttributeSettingsItem(
1115                   "begroeidterreindeeloptalud", new AttributeSettings().title("Op talud"));
1116           ft.getSettings().addAttributeOrderItem("identificatie");
1117           ft.getSettings().addAttributeOrderItem("bronhouder");
1118           ft.getSettings().addAttributeOrderItem("class");
1119           ft.getSettings()
1120               .addAttachmentAttributesItem(new AttachmentAttributeType()
1121                   .attributeName("bijlage")
1122                   .maxAttachmentSize(4_000_000L)
1123                   .mimeType("image/jpeg, image/svg+xml, .png, image/*"));
1124           try {
1125             AttachmentsHelper.createAttachmentTableForFeatureType(ft);
1126           } catch (IOException | SQLException e) {
1127             throw new RuntimeException("Failed to create attachments table", e);
1128           }
1129           ft.getSettings().addEditableAttributesItem("identificatie");
1130           ft.getSettings().addEditableAttributesItem("bronhouder");
1131           ft.getSettings().addEditableAttributesItem("class");
1132           ft.getSettings().addEditableAttributesItem("gmlid");
1133           ft.getSettings().addEditableAttributesItem("lv_publicatiedatum");
1134           ft.getSettings().addEditableAttributesItem("creationdate");
1135           ft.getSettings().addEditableAttributesItem("tijdstipregistratie");
1136           ft.getSettings().addEditableAttributesItem("eindregistratie");
1137           ft.getSettings().addEditableAttributesItem("terminationdate");
1138           ft.getSettings().addEditableAttributesItem("inonderzoek");
1139           ft.getSettings().addEditableAttributesItem("relatievehoogteligging");
1140           ft.getSettings().addEditableAttributesItem("bgt_status");
1141           ft.getSettings().addEditableAttributesItem("plus_status");
1142           ft.getSettings().addEditableAttributesItem("plus_fysiekvoorkomen");
1143           ft.getSettings().addEditableAttributesItem("begroeidterreindeeloptalud");
1144         });
1145 
1146     featureSources.get("postgis").getFeatureTypes().stream()
1147         .filter(ft -> ft.getName().equals("bak"))
1148         .findFirst()
1149         .ifPresent(ft -> {
1150           ft.getSettings().addHideAttributesItem("gmlid");
1151           ft.getSettings().addHideAttributesItem("lv_publicatiedatum");
1152           ft.getSettings().addHideAttributesItem("creationdate");
1153           ft.getSettings().addHideAttributesItem("tijdstipregistratie");
1154           ft.getSettings().addHideAttributesItem("eindregistratie");
1155           ft.getSettings().addHideAttributesItem("terminationdate");
1156           ft.getSettings().addHideAttributesItem("inonderzoek");
1157           ft.getSettings().addHideAttributesItem("relatievehoogteligging");
1158           ft.getSettings().addHideAttributesItem("bgt_status");
1159           ft.getSettings().addHideAttributesItem("plus_status");
1160           ft.getSettings().addHideAttributesItem("function_");
1161           ft.getSettings().addHideAttributesItem("plus_type");
1162         });
1163 
1164     featureSources.get("oracle").getFeatureTypes().stream()
1165         .filter(ft -> ft.getName().equals("WATERDEEL"))
1166         .findFirst()
1167         .ifPresent(ft -> {
1168           ft.getSettings()
1169               .addAttachmentAttributesItem(new AttachmentAttributeType()
1170                   .attributeName("bijlage")
1171                   .maxAttachmentSize(4_000_000L)
1172                   .mimeType("image/jpeg, image/svg+xml, .png, image/*"));
1173           try {
1174             AttachmentsHelper.createAttachmentTableForFeatureType(ft);
1175           } catch (IOException | SQLException e) {
1176             throw new RuntimeException("Failed to create attachments table", e);
1177           }
1178           ft.getSettings().addEditableAttributesItem("GMLID");
1179           ft.getSettings().addEditableAttributesItem("IDENTIFICATIE");
1180           ft.getSettings().addEditableAttributesItem("LV_PUBLICATIEDATUM");
1181           ft.getSettings().addEditableAttributesItem("CREATIONDATE");
1182           ft.getSettings().addEditableAttributesItem("TIJDSTIPREGISTRATIE");
1183           ft.getSettings().addEditableAttributesItem("EINDREGISTRATIE");
1184           ft.getSettings().addEditableAttributesItem("TERMINATIONDATE");
1185           ft.getSettings().addEditableAttributesItem("BRONHOUDER");
1186           ft.getSettings().addEditableAttributesItem("INONDERZOEK");
1187           ft.getSettings().addEditableAttributesItem("RELATIEVEHOOGTELIGGING");
1188           ft.getSettings().addEditableAttributesItem("BGT_STATUS");
1189           ft.getSettings().addEditableAttributesItem("PLUS_STATUS");
1190           ft.getSettings().addEditableAttributesItem("CLASS");
1191           ft.getSettings().addEditableAttributesItem("PLUS_TYPE");
1192         });
1193     featureSources.get("sqlserver").getFeatureTypes().stream()
1194         .filter(ft -> ft.getName().equals("wegdeel"))
1195         .findFirst()
1196         .ifPresent(ft -> {
1197           ft.getSettings()
1198               .addAttachmentAttributesItem(new AttachmentAttributeType()
1199                   .attributeName("bijlage")
1200                   .maxAttachmentSize(4_000_000L)
1201                   .mimeType("image/jpeg, image/svg+xml, .png, image/*"));
1202           try {
1203             AttachmentsHelper.createAttachmentTableForFeatureType(ft);
1204           } catch (IOException | SQLException e) {
1205             throw new RuntimeException("Failed to create attachments table", e);
1206           }
1207           ft.getSettings().addEditableAttributesItem("gmlid");
1208           ft.getSettings().addEditableAttributesItem("identificatie");
1209           ft.getSettings().addEditableAttributesItem("lv_publicatiedatum");
1210           ft.getSettings().addEditableAttributesItem("creationdate");
1211           ft.getSettings().addEditableAttributesItem("tijdstipregistratie");
1212           ft.getSettings().addEditableAttributesItem("eindregistratie");
1213           ft.getSettings().addEditableAttributesItem("terminationdate");
1214           ft.getSettings().addEditableAttributesItem("bronhouder");
1215           ft.getSettings().addEditableAttributesItem("inonderzoek");
1216           ft.getSettings().addEditableAttributesItem("relatievehoogteligging");
1217           ft.getSettings().addEditableAttributesItem("bgt_status");
1218           ft.getSettings().addEditableAttributesItem("plus_status");
1219           ft.getSettings().addEditableAttributesItem("function_");
1220           ft.getSettings().addEditableAttributesItem("plus_functiewegdeel");
1221           ft.getSettings().addEditableAttributesItem("plus_fysiekvoorkomenwegdeel");
1222           ft.getSettings().addEditableAttributesItem("surfacematerial");
1223           ft.getSettings().addEditableAttributesItem("wegdeeloptalud");
1224         });
1225 
1226     featureSources.get("postgis").getFeatureTypes().stream()
1227         .filter(ft -> ft.getName().equals("kadastraal_perceel"))
1228         .findFirst()
1229         .ifPresent(ft -> {
1230           ft.getSettings()
1231               .addAttachmentAttributesItem(new AttachmentAttributeType()
1232                   .attributeName("bijlage")
1233                   .maxAttachmentSize(4_000_000L)
1234                   .mimeType("image/jpeg, image/svg+xml, .png, image/*"));
1235           try {
1236             AttachmentsHelper.createAttachmentTableForFeatureType(ft);
1237           } catch (IOException | SQLException e) {
1238             throw new RuntimeException("Failed to create attachments table for kadastraal_perceel", e);
1239           }
1240           // hide primary key
1241           ft.getSettings().addHideAttributesItem("gml_id");
1242           // make some attributes editable
1243           ft.getSettings().addEditableAttributesItem("begin_geldigheid");
1244           ft.getSettings().addEditableAttributesItem("tijdstip_registratie");
1245         });
1246 
1247     featureSources.get("postgis_osm").getFeatureTypes().stream()
1248         .filter(ft -> ft.getName().equals("osm_polygon"))
1249         .findFirst()
1250         .ifPresent(ft -> {
1251           ft.getSettings().addEditableAttributesItem("osm_id");
1252           ft.getSettings().addEditableAttributesItem("building");
1253           ft.getSettings().addEditableAttributesItem("z_order");
1254         });
1255   }
1256 
1257   public void createAppTestData() throws Exception {
1258     Upload logo = new Upload()
1259         .setCategory(UploadCategory.APP_LOGO)
1260         .setFilename("gradient.svg")
1261         .setMimeType("image/svg+xml")
1262         .setContent(new ClassPathResource("test/gradient-logo.svg").getContentAsByteArray())
1263         .setLastModified(OffsetDateTime.now(ZoneId.systemDefault()));
1264     uploadRepository.save(logo);
1265 
1266     List<AppTreeNode> baseNodes = List.of(
1267         new AppTreeLayerNode()
1268             .objectType("AppTreeLayerNode")
1269             .id("lyr:openbasiskaart:osm")
1270             .serviceId("openbasiskaart")
1271             .layerName("osm")
1272             .visible(true),
1273         new AppTreeLayerNode()
1274             .objectType("AppTreeLayerNode")
1275             .id("lyr:pdok-hwh-luchtfotorgb:Actueel_orthoHR")
1276             .serviceId("pdok-hwh-luchtfotorgb")
1277             .layerName("Actueel_orthoHR")
1278             .visible(false));
1279 
1280     Application app = new Application()
1281         .setName("default")
1282         .setTitle("Tailormap demo")
1283         .setCrs("EPSG:28992")
1284         .setAuthorizationRules(ruleAnonymousRead)
1285         .setComponents(List.of(
1286             new Component()
1287                 .type("SIMPLE_SEARCH")
1288                 .config(new ComponentConfig()
1289                     .enabled(true)
1290                     .putAdditionalProperty("municipalities", List.of("0344"))),
1291             new Component().type("EDIT").config(new ComponentConfig().enabled(true)),
1292             new Component()
1293                 .type("TOC")
1294                 .config(new ComponentConfig()
1295                     .enabled(true)
1296                     .putAdditionalProperty("showEditLayerIcon", true)),
1297             new Component()
1298                 .type("COORDINATE_LINK_WINDOW")
1299                 .config(new ComponentConfig()
1300                     .enabled(true)
1301                     .putAdditionalProperty(
1302                         "urls",
1303                         List.of(
1304                             Map.of(
1305                                 "id",
1306                                 "google-maps",
1307                                 "url",
1308                                 "https://www.google.com/maps/@[lat],[lon],18z",
1309                                 "alias",
1310                                 "Google Maps",
1311                                 "projection",
1312                                 "EPSG:4326"),
1313                             Map.of(
1314                                 "id",
1315                                 "tm-demo",
1316                                 "url",
1317                                 "https://demo.tailormap.com/#@[X],[Y],18",
1318                                 "alias",
1319                                 "Tailormap demo",
1320                                 "projection",
1321                                 "EPSG:28992"))))))
1322         .setContentRoot(new AppContent()
1323             .addBaseLayerNodesItem(new AppTreeLevelNode()
1324                 .objectType("AppTreeLevelNode")
1325                 .id("root-base-layers")
1326                 .root(true)
1327                 .title("Base layers")
1328                 .childrenIds(List.of(
1329                     "lyr:openbasiskaart:osm",
1330                     "lyr:pdok-hwh-luchtfotorgb:Actueel_orthoHR",
1331                     "lyr:openbasiskaart-proxied:osm",
1332                     "lyr:openbasiskaart-tms:xyz",
1333                     "lyr:b3p-mapproxy-luchtfoto:xyz")))
1334             .addBaseLayerNodesItem(
1335                 // This layer from a secured proxied service should not be proxyable in a
1336                 // public app, see test_wms_secured_proxy_not_in_public_app() testcase
1337                 new AppTreeLayerNode()
1338                     .objectType("AppTreeLayerNode")
1339                     .id("lyr:openbasiskaart-proxied:osm")
1340                     .serviceId("openbasiskaart-proxied")
1341                     .layerName("osm")
1342                     .visible(false))
1343             .addBaseLayerNodesItem(new AppTreeLayerNode()
1344                 .objectType("AppTreeLayerNode")
1345                 .id("lyr:openbasiskaart-tms:xyz")
1346                 .serviceId("openbasiskaart-tms")
1347                 .layerName("xyz")
1348                 .visible(false))
1349             .addBaseLayerNodesItem(new AppTreeLayerNode()
1350                 .objectType("AppTreeLayerNode")
1351                 .id("lyr:b3p-mapproxy-luchtfoto:xyz")
1352                 .serviceId("b3p-mapproxy-luchtfoto")
1353                 .layerName("xyz")
1354                 .visible(false))
1355             .addLayerNodesItem(new AppTreeLevelNode()
1356                 .objectType("AppTreeLevelNode")
1357                 .id("root")
1358                 .root(true)
1359                 .title("Layers")
1360                 .childrenIds(List.of("lvl:wfs", "lvl:jdbc", "lvl:proxied", "lvl:archeo")))
1361             // WFS feature sources for testing paging, counting and sorting
1362             .addLayerNodesItem(new AppTreeLevelNode()
1363                 .objectType("AppTreeLevelNode")
1364                 .id("lvl:wfs")
1365                 .title("WFS")
1366                 .description(
1367                     "Layers with a WFS feature source, from MapServer (PDOK) and GeoServer, with WFS 1.1.0 and 2.0.0.")
1368                 .childrenIds(List.of(
1369                     "lyr:pdok-kadaster-bestuurlijkegebieden:Provinciegebied",
1370                     "lyr:pdok-kadaster-bestuurlijkegebieden:Gemeentegebied",
1371                     "lyr:pdok-rws-nwbwegen:wegvakken",
1372                     "lyr:pdok-bestuurlijkegebieden-wfs11:Gemeentegebied",
1373                     "lyr:geoserver-wfs11:postgis:begroeidterreindeel",
1374                     "lyr:geoserver-wfs20:postgis:begroeidterreindeel")))
1375             // WFS 2.0.0 (MapServer), for testing hidden functionality: feature info, attribute list and
1376             // export are hidden in this app (see the app layer settings)
1377             .addLayerNodesItem(new AppTreeLayerNode()
1378                 .objectType("AppTreeLayerNode")
1379                 .id("lyr:pdok-kadaster-bestuurlijkegebieden:Provinciegebied")
1380                 .serviceId("pdok-kadaster-bestuurlijkegebieden")
1381                 .layerName("Provinciegebied")
1382                 .visible(true))
1383             // WFS 2.0.0 (MapServer) which does not return numberMatched, for testing paging with an
1384             // unknown total
1385             .addLayerNodesItem(new AppTreeLayerNode()
1386                 .objectType("AppTreeLayerNode")
1387                 .id("lyr:pdok-kadaster-bestuurlijkegebieden:Gemeentegebied")
1388                 .serviceId("pdok-kadaster-bestuurlijkegebieden")
1389                 .layerName("Gemeentegebied")
1390                 .visible(true))
1391             .addLayerNodesItem(new AppTreeLayerNode()
1392                 .objectType("AppTreeLayerNode")
1393                 .id("lyr:pdok-rws-nwbwegen:wegvakken")
1394                 .serviceId("pdok-rws-nwbwegen")
1395                 .layerName("wegvakken")
1396                 .visible(false))
1397             // WFS 1.1.0 (MapServer)
1398             .addLayerNodesItem(new AppTreeLayerNode()
1399                 .objectType("AppTreeLayerNode")
1400                 .id("lyr:pdok-bestuurlijkegebieden-wfs11:Gemeentegebied")
1401                 .serviceId("pdok-bestuurlijkegebieden-wfs11")
1402                 .layerName("Gemeentegebied")
1403                 .visible(false))
1404             // WFS 1.1.0 (GeoServer)
1405             .addLayerNodesItem(new AppTreeLayerNode()
1406                 .objectType("AppTreeLayerNode")
1407                 .id("lyr:geoserver-wfs11:postgis:begroeidterreindeel")
1408                 .serviceId("geoserver-wfs11")
1409                 .layerName("postgis:begroeidterreindeel")
1410                 .visible(false))
1411             .addLayerNodesItem(new AppTreeLayerNode()
1412                 .objectType("AppTreeLayerNode")
1413                 .id("lyr:geoserver-wfs20:postgis:begroeidterreindeel")
1414                 .serviceId("geoserver-wfs20")
1415                 .layerName("postgis:begroeidterreindeel")
1416                 .visible(false))
1417             // JDBC feature sources for testing the different spatial databases
1418             .addLayerNodesItem(new AppTreeLevelNode()
1419                 .objectType("AppTreeLevelNode")
1420                 .id("lvl:jdbc")
1421                 .title("JDBC")
1422                 .description("Layers with a JDBC feature source, from PostGIS, SQL Server and Oracle.")
1423                 .childrenIds(List.of(
1424                     "lyr:snapshot-geoserver:postgis:begroeidterreindeel",
1425                     "lyr:snapshot-geoserver:postgis:bak",
1426                     "lyr:snapshot-geoserver:postgis:kadastraal_perceel",
1427                     "lyr:snapshot-geoserver:postgis:osm_polygon",
1428                     "lyr:snapshot-geoserver:sqlserver:wegdeel",
1429                     "lyr:snapshot-geoserver:oracle:WATERDEEL",
1430                     "lyr:snapshot-geoserver:BGT")))
1431             // PostGIS: editing, preset filters, selected styles, hidden and read-only attributes, search
1432             .addLayerNodesItem(new AppTreeLayerNode()
1433                 .objectType("AppTreeLayerNode")
1434                 .id("lyr:snapshot-geoserver:postgis:begroeidterreindeel")
1435                 .serviceId("snapshot-geoserver")
1436                 .layerName("postgis:begroeidterreindeel")
1437                 .visible(true))
1438             // PostGIS: description from the WMS layer abstract, attributes hidden in the feature type
1439             // settings, not editable
1440             .addLayerNodesItem(new AppTreeLayerNode()
1441                 .objectType("AppTreeLayerNode")
1442                 .id("lyr:snapshot-geoserver:postgis:bak")
1443                 .serviceId("snapshot-geoserver")
1444                 .layerName("postgis:bak")
1445                 .visible(false))
1446             // PostGIS points: attachments, read-only attribute, slider filter, search
1447             .addLayerNodesItem(new AppTreeLayerNode()
1448                 .objectType("AppTreeLayerNode")
1449                 .id("lyr:snapshot-geoserver:postgis:kadastraal_perceel")
1450                 .serviceId("snapshot-geoserver")
1451                 .layerName("postgis:kadastraal_perceel")
1452                 .visible(false))
1453             // PostGIS in EPSG:3857: layer bounds reprojection, editable without attachment attributes
1454             .addLayerNodesItem(new AppTreeLayerNode()
1455                 .objectType("AppTreeLayerNode")
1456                 .id("lyr:snapshot-geoserver:postgis:osm_polygon")
1457                 .serviceId("snapshot-geoserver")
1458                 .layerName("postgis:osm_polygon")
1459                 .visible(false))
1460             // SQL Server: editing, search
1461             .addLayerNodesItem(new AppTreeLayerNode()
1462                 .objectType("AppTreeLayerNode")
1463                 .id("lyr:snapshot-geoserver:sqlserver:wegdeel")
1464                 .serviceId("snapshot-geoserver")
1465                 .layerName("sqlserver:wegdeel")
1466                 .visible(true))
1467             // Oracle: editing, title, description, opacity and attribution from the app layer settings
1468             .addLayerNodesItem(new AppTreeLayerNode()
1469                 .objectType("AppTreeLayerNode")
1470                 .id("lyr:snapshot-geoserver:oracle:WATERDEEL")
1471                 .serviceId("snapshot-geoserver")
1472                 .layerName("oracle:WATERDEEL")
1473                 .visible(true))
1474             // WMS layer group combining the layers above, with authorization rules
1475             .addLayerNodesItem(new AppTreeLayerNode()
1476                 .objectType("AppTreeLayerNode")
1477                 .id("lyr:snapshot-geoserver:BGT")
1478                 .serviceId("snapshot-geoserver")
1479                 .layerName("BGT")
1480                 .visible(false))
1481             .addLayerNodesItem(new AppTreeLevelNode()
1482                 .objectType("AppTreeLevelNode")
1483                 .id("lvl:proxied")
1484                 .title("Proxied")
1485                 .description("Layers from services which are proxied by Tailormap.")
1486                 .childrenIds(List.of(
1487                     "lyr:snapshot-geoserver-proxied:postgis:begroeidterreindeel",
1488                     "lyr:bestuurlijkegebieden-proxied:Provinciegebied")))
1489             .addLayerNodesItem(new AppTreeLayerNode()
1490                 .objectType("AppTreeLayerNode")
1491                 .id("lyr:snapshot-geoserver-proxied:postgis:begroeidterreindeel")
1492                 .serviceId("snapshot-geoserver-proxied")
1493                 .layerName("postgis:begroeidterreindeel")
1494                 .visible(false))
1495             // This is a layer from proxied service with auth that should also not be
1496             // visible, but it has a feature source attached, should also be denied for
1497             // features access and not be included in TOC
1498             .addLayerNodesItem(new AppTreeLayerNode()
1499                 .objectType("AppTreeLayerNode")
1500                 .id("lyr:bestuurlijkegebieden-proxied:Provinciegebied")
1501                 .serviceId("bestuurlijkegebieden-proxied")
1502                 .layerName("Provinciegebied")
1503                 .visible(false))
1504             .addLayerNodesItem(new AppTreeLevelNode()
1505                 .objectType("AppTreeLevelNode")
1506                 .id("lvl:archeo")
1507                 .title("Archeology")
1508                 .childrenIds(List.of("lyr:demo:geomorfologie")))
1509             .addLayerNodesItem(new AppTreeLayerNode()
1510                 .objectType("AppTreeLayerNode")
1511                 .id("lyr:demo:geomorfologie")
1512                 .serviceId("demo")
1513                 .layerName("geomorfologie")
1514                 .visible(true)))
1515         .setStyling(new AppStyling().logo(logo.getId().toString()))
1516         .setSettings(new AppSettings()
1517             .putLayerSettingsItem("lyr:openbasiskaart:osm", new AppLayerSettings().title("Openbasiskaart"))
1518             .putLayerSettingsItem(
1519                 "lyr:pdok-hwh-luchtfotorgb:Actueel_orthoHR", new AppLayerSettings().title("Luchtfoto"))
1520             .putLayerSettingsItem(
1521                 "lyr:openbasiskaart-proxied:osm",
1522                 new AppLayerSettings().title("Openbasiskaart (proxied)"))
1523             .putLayerSettingsItem(
1524                 "lyr:snapshot-geoserver:oracle:WATERDEEL",
1525                 new AppLayerSettings()
1526                     .opacity(50)
1527                     .title("Waterdeel overridden title")
1528                     .editable(true)
1529                     .description("This is the layer description from the app layer setting.")
1530                     .attribution(
1531                         "CC BY 4.0 [BGT/Kadaster](https://www.nationaalgeoregister.nl/geonetwork/srv/api/records/2cb4769c-b56e-48fa-8685-c48f61b9a319)"))
1532             .putLayerSettingsItem(
1533                 "lyr:snapshot-geoserver:postgis:osm_polygon",
1534                 new AppLayerSettings()
1535                     .description("OpenStreetMap polygon data in EPSG:3857")
1536                     .opacity(60)
1537                     .editable(true)
1538                     .title("OSM Polygon (EPSG:3857)")
1539                     .attribution(
1540                         "© [OpenStreetMap](https://www.openstreetmap.org/copyright) contributors"))
1541             .putLayerSettingsItem(
1542                 "lyr:snapshot-geoserver:postgis:begroeidterreindeel",
1543                 new AppLayerSettings()
1544                     .editable(true)
1545                     .addHideAttributesItem("begroeidterreindeeloptalud")
1546                     .addReadOnlyAttributesItem("eindregistratie")
1547                     .selectedStyles(
1548                         List.of(
1549                             new WMSStyle()
1550                                 .name("begroeidterreindeel")
1551                                 .title("Visualisatie van de begroeide terreindelen")
1552                                 .abstractText(
1553                                     "Deze stylesheet bevat de regels voor de visualisatie van het objecttype Begroeid Terreindeel")
1554                                 .legendUrl(
1555                                     URI.create(
1556                                         "https://snapshot.tailormap.nl/geoserver/ows?service=WMS&version=1.3.0&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=test%3Apostgis_begroeidterreindeel")),
1557                             new WMSStyle()
1558                                 .name("purple_polygon")
1559                                 .title("purple_polygon")
1560                                 .abstractText(null)
1561                                 .legendUrl(
1562                                     URI.create(
1563                                         "https://snapshot.tailormap.nl/geoserver/ows?service=WMS&version=1.3.0&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=test%3Apostgis_begroeidterreindeel&style=purple_polygon")))))
1564             .putLayerSettingsItem(
1565                 "lyr:snapshot-geoserver:postgis:kadastraal_perceel",
1566                 new AppLayerSettings().editable(true).addReadOnlyAttributesItem("aanduiding"))
1567             .putLayerSettingsItem(
1568                 "lyr:snapshot-geoserver:sqlserver:wegdeel",
1569                 new AppLayerSettings()
1570                     .editable(true)
1571                     // The wegdeel feature type has no hidden attributes, only the app layer hides
1572                     // this attribute
1573                     .addHideAttributesItem("eindregistratie"))
1574             .putLayerSettingsItem(
1575                 "lyr:snapshot-geoserver-proxied:postgis:begroeidterreindeel",
1576                 new AppLayerSettings().editable(false))
1577             .putLayerSettingsItem(
1578                 "lyr:pdok-kadaster-bestuurlijkegebieden:Provinciegebied",
1579                 // Overrides the WFS title and description of the service layer settings, because WFS
1580                 // functionality is hidden in this app
1581                 new AppLayerSettings()
1582                     .title("Provinciegebied (reference layer)")
1583                     .description(
1584                         "The administrative boundary of Dutch Provinces, connected to a WFS. Feature"
1585                             + " info, the attribute list and export are hidden for this layer, but it can still be"
1586                             + " used as reference layer for spatial filtering, for snapping and for copying"
1587                             + " geometries when drawing or editing.")
1588                     .hiddenFunctionality(Set.of(FEATURE_INFO, ATTRIBUTE_LIST, EXPORT)))
1589             .addFilterGroupsItem(new FilterGroup()
1590                 .id("filtergroup1")
1591                 .source("PRESET")
1592                 .type(FilterGroup.TypeEnum.ATTRIBUTE)
1593                 .layerIds(List.of("lyr:snapshot-geoserver:postgis:begroeidterreindeel"))
1594                 .operator(FilterGroup.OperatorEnum.AND)
1595                 .addFiltersItem(new Filter()
1596                     .id("filter1")
1597                     .type(Filter.TypeEnum.ATTRIBUTE)
1598                     .condition(Filter.ConditionEnum.BEFORE)
1599                     .addValueItem("2025-06-05")
1600                     .attribute("creationdate")
1601                     .attributeType(Filter.AttributeTypeEnum.DATE))
1602                 .addFiltersItem(new Filter()
1603                     .id("filter2")
1604                     .type(Filter.TypeEnum.ATTRIBUTE)
1605                     .condition(Filter.ConditionEnum.UNIQUE_VALUES)
1606                     .addValueItem("bodembedekkers")
1607                     .addValueItem("bosplantsoen")
1608                     .addValueItem("gras- en kruidachtigen")
1609                     .attribute("plus_fysiekvoorkomen")
1610                     .attributeType(Filter.AttributeTypeEnum.STRING)
1611                     .editConfiguration(new FilterEditConfiguration()
1612                         .filterTool(FilterEditConfiguration.FilterToolEnum.CHECKBOX)
1613                         .attributeValuesSettings(List.of(
1614                             new AttributeValueSettings()
1615                                 .value("bodembedekkers")
1616                                 .initiallySelected(true)
1617                                 .selectable(true)
1618                                 .alias("Bodembedekkers"),
1619                             new AttributeValueSettings()
1620                                 .value("bosplantsoen")
1621                                 .initiallySelected(true)
1622                                 .selectable(true)
1623                                 .alias("Bosplantsoen"),
1624                             new AttributeValueSettings()
1625                                 .value("gras- en kruidachtigen")
1626                                 .initiallySelected(true)
1627                                 .selectable(true)
1628                                 .alias("Gras- en kruidachtigen"),
1629                             new AttributeValueSettings()
1630                                 .value("griend en hakhout")
1631                                 .initiallySelected(false)
1632                                 .selectable(true),
1633                             new AttributeValueSettings()
1634                                 .value("heesters")
1635                                 .initiallySelected(false)
1636                                 .selectable(true),
1637                             new AttributeValueSettings()
1638                                 .value("planten")
1639                                 .initiallySelected(false)
1640                                 .selectable(true),
1641                             new AttributeValueSettings()
1642                                 .value("struikrozen")
1643                                 .initiallySelected(false)
1644                                 .selectable(true),
1645                             new AttributeValueSettings()
1646                                 .value("waardeOnbekend")
1647                                 .initiallySelected(false)
1648                                 .selectable(true))))))
1649             .addFilterGroupsItem(new FilterGroup()
1650                 .id("filtergroup2")
1651                 .source("PRESET")
1652                 .type(FilterGroup.TypeEnum.ATTRIBUTE)
1653                 .layerIds(List.of("lyr:snapshot-geoserver:postgis:kadastraal_perceel"))
1654                 .operator(FilterGroup.OperatorEnum.AND)
1655                 .addFiltersItem(new Filter()
1656                     .id("filter3")
1657                     .type(Filter.TypeEnum.ATTRIBUTE)
1658                     .condition(Filter.ConditionEnum.u)
1659                     .addValueItem("1")
1660                     .addValueItem("12419")
1661                     .attribute("perceelnummer")
1662                     .attributeType(Filter.AttributeTypeEnum.DOUBLE)
1663                     .editConfiguration(new FilterEditConfiguration()
1664                         .filterTool(FilterEditConfiguration.FilterToolEnum.SLIDER)
1665                         .initialLowerValue(1d)
1666                         .initialUpperValue(12419d)
1667                         .minimumValue(1d)
1668                         .maximumValue(12419d)))));
1669 
1670     app.getContentRoot().getBaseLayerNodes().addAll(baseNodes);
1671     app.setInitialExtent(
1672         new Bounds().minx(130011d).miny(458031d).maxx(132703d).maxy(459995d));
1673     app.setMaxExtent(new Bounds().minx(-285401d).miny(22598d).maxx(595401d).maxy(903401d));
1674 
1675     if (map5url != null) {
1676       AppTreeLevelNode root =
1677           (AppTreeLevelNode) app.getContentRoot().getBaseLayerNodes().getFirst();
1678       List<String> childrenIds = new ArrayList<>(root.getChildrenIds());
1679       childrenIds.add("lyr:map5:map5topo");
1680       childrenIds.add("lyr:map5:map5topo_simple");
1681       childrenIds.add("lvl:luchtfoto-labels");
1682       root.setChildrenIds(childrenIds);
1683       app.getSettings()
1684           .putLayerSettingsItem("lyr:map5:map5topo", new AppLayerSettings().title("Map5"))
1685           .putLayerSettingsItem("lyr:map5:map5topo_simple", new AppLayerSettings().title("Map5 simple"));
1686       app.getContentRoot()
1687           .addBaseLayerNodesItem(new AppTreeLayerNode()
1688               .objectType("AppTreeLayerNode")
1689               .id("lyr:map5:map5topo")
1690               .serviceId("map5")
1691               .layerName("map5topo")
1692               .visible(false))
1693           .addBaseLayerNodesItem(new AppTreeLayerNode()
1694               .objectType("AppTreeLayerNode")
1695               .id("lyr:map5:map5topo_simple")
1696               .serviceId("map5")
1697               .layerName("map5topo_simple")
1698               .visible(false))
1699           .addBaseLayerNodesItem(new AppTreeLevelNode()
1700               .objectType("AppTreeLevelNode")
1701               .id("lvl:luchtfoto-labels")
1702               .title("Luchtfoto met labels")
1703               .addChildrenIdsItem("lyr:map5:luforoadslabels")
1704               .addChildrenIdsItem("lyr:pdok-hwh-luchtfotorgb:Actueel_orthoHR2"))
1705           .addBaseLayerNodesItem(new AppTreeLayerNode()
1706               .objectType("AppTreeLayerNode")
1707               .id("lyr:map5:luforoadslabels")
1708               .serviceId("map5")
1709               .layerName("luforoadslabels")
1710               .visible(false))
1711           .addBaseLayerNodesItem(new AppTreeLayerNode()
1712               .objectType("AppTreeLayerNode")
1713               .id("lyr:pdok-hwh-luchtfotorgb:Actueel_orthoHR2")
1714               .serviceId("pdok-hwh-luchtfotorgb")
1715               .layerName("Actueel_orthoHR")
1716               .visible(false));
1717     }
1718 
1719     applicationRepository.save(app);
1720 
1721     app = new Application()
1722         .setName("base")
1723         .setTitle("Service base app")
1724         .setCrs("EPSG:28992")
1725         .setAuthorizationRules(ruleAnonymousRead)
1726         .setContentRoot(new AppContent()
1727             .addBaseLayerNodesItem(new AppTreeLevelNode()
1728                 .objectType("AppTreeLevelNode")
1729                 .id("root-base-layers")
1730                 .root(true)
1731                 .title("Base layers")
1732                 .childrenIds(List.of(
1733                     "lyr:openbasiskaart:osm", "lyr:pdok-hwh-luchtfotorgb:Actueel_orthoHR"))));
1734     app.getContentRoot().getBaseLayerNodes().addAll(baseNodes);
1735     applicationRepository.save(app);
1736 
1737     app = new Application()
1738         .setName("secured")
1739         .setTitle("secured app")
1740         .setCrs("EPSG:28992")
1741         .setAuthorizationRules(ruleLoggedIn)
1742         .setContentRoot(new AppContent()
1743             .addBaseLayerNodesItem(new AppTreeLevelNode()
1744                 .objectType("AppTreeLevelNode")
1745                 .id("root-base-layers")
1746                 .root(true)
1747                 .title("Base layers")
1748                 .childrenIds(List.of(
1749                     "lyr:openbasiskaart:osm",
1750                     "lyr:pdok-hwh-luchtfotorgb:Actueel_orthoHR",
1751                     "lyr:openbasiskaart-proxied:osm")))
1752             .addBaseLayerNodesItem(new AppTreeLayerNode()
1753                 .objectType("AppTreeLayerNode")
1754                 .id("lyr:openbasiskaart-proxied:osm")
1755                 .serviceId("openbasiskaart-proxied")
1756                 .layerName("osm")
1757                 .visible(false))
1758             .addLayerNodesItem(new AppTreeLevelNode()
1759                 .objectType("AppTreeLevelNode")
1760                 .id("root")
1761                 .root(true)
1762                 .title("Layers")
1763                 .childrenIds(List.of(
1764                     "lyr:pdok-kadaster-bestuurlijkegebieden:Provinciegebied",
1765                     "lyr:pdok-kadaster-bestuurlijkegebieden:Gemeentegebied",
1766                     "lvl:proxied")))
1767             .addLayerNodesItem(new AppTreeLayerNode()
1768                 .objectType("AppTreeLayerNode")
1769                 .id("lyr:pdok-kadaster-bestuurlijkegebieden:Gemeentegebied")
1770                 .serviceId("pdok-kadaster-bestuurlijkegebieden")
1771                 .layerName("Gemeentegebied")
1772                 .visible(true))
1773             .addLayerNodesItem(new AppTreeLayerNode()
1774                 .objectType("AppTreeLayerNode")
1775                 .id("lyr:pdok-kadaster-bestuurlijkegebieden:Provinciegebied")
1776                 .serviceId("pdok-kadaster-bestuurlijkegebieden")
1777                 .layerName("Provinciegebied")
1778                 .visible(false))
1779             .addLayerNodesItem(new AppTreeLevelNode()
1780                 .objectType("AppTreeLevelNode")
1781                 .id("lvl:proxied")
1782                 .title("Proxied")
1783                 .childrenIds(List.of("lyr:snapshot-geoserver-proxied:postgis:begroeidterreindeel")))
1784             .addLayerNodesItem(new AppTreeLayerNode()
1785                 .objectType("AppTreeLayerNode")
1786                 .id("lyr:snapshot-geoserver-proxied:postgis:begroeidterreindeel")
1787                 .serviceId("snapshot-geoserver-proxied")
1788                 .layerName("postgis:begroeidterreindeel")
1789                 .visible(false)))
1790         .setSettings(
1791             new AppSettings()
1792                 .putLayerSettingsItem(
1793                     "lyr:openbasiskaart-proxied:osm",
1794                     new AppLayerSettings().title("Openbasiskaart (proxied)"))
1795                 .putLayerSettingsItem(
1796                     "lyr:snapshot-geoserver-proxied:postgis:begroeidterreindeel",
1797                     new AppLayerSettings()
1798                         .description("This layer should render using purple polygons")
1799                         .selectedStyles(
1800                             List.of(
1801                                 new WMSStyle()
1802                                     .name("purple_polygon")
1803                                     .title("purple_polygon")
1804                                     .abstractText(null)
1805                                     .legendUrl(
1806                                         URI.create(
1807                                             "https://snapshot.tailormap.nl/geoserver/ows?service=WMS&version=1.3.0&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=test%3Apostgis_begroeidterreindeel&style=purple_polygon"))))));
1808 
1809     app.getContentRoot().getBaseLayerNodes().addAll(baseNodes);
1810     applicationRepository.save(app);
1811 
1812     app = new Application()
1813         .setName("secured-auth")
1814         .setTitle("secured (with authorizations)")
1815         .setCrs("EPSG:28992")
1816         .setAuthorizationRules(List.of(
1817             new AuthorizationRule()
1818                 .groupName("test-foo")
1819                 .decisions(Map.of(ACCESS_TYPE_VIEW, AuthorizationRuleDecision.ALLOW)),
1820             new AuthorizationRule()
1821                 .groupName("test-bar")
1822                 .decisions(Map.of(ACCESS_TYPE_VIEW, AuthorizationRuleDecision.ALLOW))))
1823         .setContentRoot(new AppContent()
1824             .addLayerNodesItem(new AppTreeLevelNode()
1825                 .objectType("AppTreeLevelNode")
1826                 .id("root")
1827                 .root(true)
1828                 .title("Layers")
1829                 .childrenIds(List.of("lvl:needs-auth", "lvl:public")))
1830             .addLayerNodesItem(new AppTreeLevelNode()
1831                 .objectType("AppTreeLevelNode")
1832                 .id("lvl:public")
1833                 .title("Public")
1834                 .childrenIds(List.of("lyr:snapshot-geoserver:BGT")))
1835             .addLayerNodesItem(new AppTreeLevelNode()
1836                 .objectType("AppTreeLevelNode")
1837                 .id("lvl:needs-auth")
1838                 .title("Needs auth")
1839                 .childrenIds(List.of(
1840                     "lyr:filtered-snapshot-geoserver:BGT",
1841                     "lyr:filtered-snapshot-geoserver:postgis:begroeidterreindeel")))
1842             .addLayerNodesItem(new AppTreeLayerNode()
1843                 .objectType("AppTreeLayerNode")
1844                 .id("lyr:filtered-snapshot-geoserver:BGT")
1845                 .serviceId("filtered-snapshot-geoserver")
1846                 .layerName("BGT")
1847                 .visible(true))
1848             .addLayerNodesItem(new AppTreeLayerNode()
1849                 .objectType("AppTreeLayerNode")
1850                 .id("lyr:filtered-snapshot-geoserver:postgis:begroeidterreindeel")
1851                 .serviceId("filtered-snapshot-geoserver")
1852                 .layerName("postgis:begroeidterreindeel")
1853                 .visible(true))
1854             .addLayerNodesItem(new AppTreeLayerNode()
1855                 .objectType("AppTreeLayerNode")
1856                 .id("lyr:snapshot-geoserver:BGT")
1857                 .serviceId("snapshot-geoserver")
1858                 .layerName("BGT")
1859                 .visible(true)));
1860 
1861     applicationRepository.save(app);
1862 
1863     app = new Application()
1864         .setName("austria")
1865         .setCrs("EPSG:3857")
1866         .setAuthorizationRules(ruleAnonymousRead)
1867         .setTitle("Austria")
1868         .setInitialExtent(
1869             new Bounds().minx(987982d).miny(5799551d).maxx(1963423d).maxy(6320708d))
1870         .setMaxExtent(
1871             new Bounds().minx(206516d).miny(5095461d).maxx(3146930d).maxy(7096232d))
1872         .setContentRoot(new AppContent()
1873             .addBaseLayerNodesItem(new AppTreeLevelNode()
1874                 .objectType("AppTreeLevelNode")
1875                 .id("root-base-layers")
1876                 .root(true)
1877                 .title("Base layers")
1878                 .childrenIds(List.of(
1879                     "lyr:at-basemap:geolandbasemap",
1880                     "lyr:at-basemap:orthofoto",
1881                     "lvl:orthofoto-labels",
1882                     "lyr:osm:xyz")))
1883             .addBaseLayerNodesItem(new AppTreeLayerNode()
1884                 .objectType("AppTreeLayerNode")
1885                 .id("lyr:at-basemap:geolandbasemap")
1886                 .serviceId("at-basemap")
1887                 .layerName("geolandbasemap")
1888                 .visible(true))
1889             .addBaseLayerNodesItem(new AppTreeLayerNode()
1890                 .objectType("AppTreeLayerNode")
1891                 .id("lyr:at-basemap:orthofoto")
1892                 .serviceId("at-basemap")
1893                 .layerName("bmaporthofoto30cm")
1894                 .visible(false))
1895             .addBaseLayerNodesItem(new AppTreeLevelNode()
1896                 .objectType("AppTreeLevelNode")
1897                 .id("lvl:orthofoto-labels")
1898                 .title("Orthophoto with labels")
1899                 .childrenIds(List.of("lyr:at-basemap:bmapoverlay", "lyr:at-basemap:orthofoto_2")))
1900             .addBaseLayerNodesItem(new AppTreeLayerNode()
1901                 .objectType("AppTreeLayerNode")
1902                 .id("lyr:at-basemap:bmapoverlay")
1903                 .serviceId("at-basemap")
1904                 .layerName("bmapoverlay")
1905                 .visible(false))
1906             .addBaseLayerNodesItem(new AppTreeLayerNode()
1907                 .objectType("AppTreeLayerNode")
1908                 .id("lyr:at-basemap:orthofoto_2")
1909                 .serviceId("at-basemap")
1910                 .layerName("bmaporthofoto30cm")
1911                 .visible(false))
1912             .addBaseLayerNodesItem(new AppTreeLayerNode()
1913                 .objectType("AppTreeLayerNode")
1914                 .id("lyr:osm:xyz")
1915                 .serviceId("osm")
1916                 .layerName("xyz")
1917                 .visible(false)));
1918 
1919     applicationRepository.save(app);
1920 
1921     app = new Application()
1922         .setName("3d_utrecht")
1923         .setCrs("EPSG:3857")
1924         .setAuthorizationRules(ruleLoggedIn)
1925         .setTitle("3D Utrecht")
1926         .setInitialExtent(
1927             new Bounds().minx(558390d).miny(6818485d).maxx(566751d).maxy(6824036d))
1928         .setMaxExtent(
1929             new Bounds().minx(91467d).miny(6496479d).maxx(1037043d).maxy(7147453d))
1930         .setSettings(new AppSettings().uiSettings(new AppUiSettings().enable3D(true)))
1931         .setContentRoot(new AppContent()
1932             .addBaseLayerNodesItem(new AppTreeLevelNode()
1933                 .objectType("AppTreeLevelNode")
1934                 .id("root-base-layers")
1935                 .root(true)
1936                 .title("Base layers")
1937                 .childrenIds(List.of("lyr:pdok-hwh-luchtfotorgb:Actueel_orthoHR", "lyr:osm:xyz")))
1938             .addBaseLayerNodesItem(new AppTreeLayerNode()
1939                 .objectType("AppTreeLayerNode")
1940                 .id("lyr:pdok-hwh-luchtfotorgb:Actueel_orthoHR")
1941                 .serviceId("pdok-hwh-luchtfotorgb")
1942                 .layerName("Actueel_orthoHR")
1943                 .visible(true))
1944             .addBaseLayerNodesItem(new AppTreeLayerNode()
1945                 .objectType("AppTreeLayerNode")
1946                 .id("lyr:osm:xyz")
1947                 .serviceId("osm")
1948                 .layerName("xyz")
1949                 .visible(false))
1950             .addLayerNodesItem(new AppTreeLevelNode()
1951                 .objectType("AppTreeLevelNode")
1952                 .id("root")
1953                 .root(true)
1954                 .title("Layers")
1955                 .childrenIds(List.of(
1956                     "lyr:3dbag_utrecht:tiles3d",
1957                     "lyr:snapshot-geoserver:postgis:begroeidterreindeel",
1958                     "lyr:3d_basisvoorziening_gebouwen_proxy:tiles3d",
1959                     "lyr:3d_utrecht_proxied_auth:tiles3d")))
1960             .addLayerNodesItem(new AppTreeLayerNode()
1961                 .objectType("AppTreeLayerNode")
1962                 .id("lyr:3dbag_utrecht:tiles3d")
1963                 .serviceId("3dbag_utrecht")
1964                 .layerName("tiles3d")
1965                 .visible(true))
1966             .addLayerNodesItem(new AppTreeLayerNode()
1967                 .objectType("AppTreeLayerNode")
1968                 .id("lyr:3d_basisvoorziening_gebouwen_proxy:tiles3d")
1969                 .serviceId("3d_basisvoorziening_gebouwen_proxy")
1970                 .layerName("tiles3d")
1971                 .visible(false))
1972             .addLayerNodesItem(new AppTreeLayerNode()
1973                 .objectType("AppTreeLayerNode")
1974                 .id("lyr:3d_utrecht_proxied_auth:tiles3d")
1975                 .serviceId("3d_utrecht_proxied_auth")
1976                 .layerName("tiles3d")
1977                 .visible(false))
1978             .addLayerNodesItem(new AppTreeLayerNode()
1979                 .objectType("AppTreeLayerNode")
1980                 .id("lyr:snapshot-geoserver:postgis:begroeidterreindeel")
1981                 .serviceId("snapshot-geoserver")
1982                 .layerName("postgis:begroeidterreindeel")
1983                 .visible(true))
1984             .addTerrainLayerNodesItem(new AppTreeLevelNode()
1985                 .objectType("AppTreeLevelNode")
1986                 .id("root-terrain-layers")
1987                 .root(true)
1988                 .title("Terrain Layers")
1989                 .childrenIds(List.of("lyr:ahn_terrain_model:quantizedmesh")))
1990             .addTerrainLayerNodesItem(new AppTreeLayerNode()
1991                 .objectType("AppTreeLayerNode")
1992                 .id("lyr:ahn_terrain_model:quantizedmesh")
1993                 .serviceId("ahn_terrain_model")
1994                 .layerName("quantizedmesh")
1995                 .visible(false)));
1996 
1997     applicationRepository.save(app);
1998 
1999     app = new Application()
2000         .setName("public-with-auth")
2001         .setTitle("Public app with one restricted layer in a group")
2002         .setCrs("EPSG:28992")
2003         .setAuthorizationRules(ruleAnonymousRead)
2004         .setInitialExtent(
2005             new Bounds().minx(130011d).miny(458031d).maxx(132703d).maxy(459995d))
2006         .setMaxExtent(
2007             new Bounds().minx(-285401d).miny(22598d).maxx(595401d).maxy(903401d))
2008         .setStyling(new AppStyling().logo(logo.getId().toString()))
2009         .setContentRoot(new AppContent()
2010             .addBaseLayerNodesItem(new AppTreeLevelNode()
2011                 .objectType("AppTreeLevelNode")
2012                 .id("root")
2013                 .root(true)
2014                 .title("Basemaps")
2015                 .childrenIds(List.of("lyr:openbasiskaart:osm")))
2016             .addBaseLayerNodesItem(new AppTreeLayerNode()
2017                 .objectType("AppTreeLayerNode")
2018                 .id("lyr:openbasiskaart:osm")
2019                 .serviceId("openbasiskaart")
2020                 .layerName("osm")
2021                 .visible(true))
2022             .addLayerNodesItem(new AppTreeLevelNode()
2023                 .objectType("AppTreeLevelNode")
2024                 .id("root")
2025                 .root(true)
2026                 .title("Application layers")
2027                 .childrenIds(List.of(
2028                     "lyr:snapshot-geoserver:postgis:kadastraal_perceel", "xpfhl34VmghkU12nP9Jer")))
2029             .addLayerNodesItem(new AppTreeLayerNode()
2030                 .objectType("AppTreeLayerNode")
2031                 .id("lyr:snapshot-geoserver:postgis:kadastraal_perceel")
2032                 .serviceId("snapshot-geoserver")
2033                 .layerName("postgis:kadastraal_perceel")
2034                 .visible(true))
2035             .addLayerNodesItem(new AppTreeLevelNode()
2036                 .id("xpfhl34VmghkU12nP9Jer")
2037                 .root(false)
2038                 .title("restricted")
2039                 .objectType("AppTreeLevelNode")
2040                 .childrenIds(List.of("lyr:filtered-snapshot-geoserver:postgis:begroeidterreindeel")))
2041             .addLayerNodesItem(new AppTreeLayerNode()
2042                 .objectType("AppTreeLayerNode")
2043                 .id("lyr:filtered-snapshot-geoserver:postgis:begroeidterreindeel")
2044                 .visible(true)
2045                 .serviceId("filtered-snapshot-geoserver")
2046                 .layerName("postgis:begroeidterreindeel")))
2047         .setSettings(new AppSettings());
2048 
2049     applicationRepository.save(app);
2050 
2051     Configuration config = new Configuration();
2052     config.setKey(Configuration.DEFAULT_APP);
2053     config.setValue("default");
2054     configurationRepository.save(config);
2055     config = new Configuration();
2056     config.setKey(Configuration.DEFAULT_BASE_APP);
2057     config.setValue("base");
2058     configurationRepository.save(config);
2059   }
2060 
2061   private void createConfigurationTestData() throws JacksonException {
2062     Configuration config = new Configuration();
2063     config.setKey("test");
2064     config.setAvailableForViewer(true);
2065     config.setValue("test value");
2066     config.setJsonValue(new JsonMapper().readTree("{ \"someProperty\": 1, \"nestedObject\": { \"num\": 42 } }"));
2067     configurationRepository.save(config);
2068   }
2069 
2070   @Transactional
2071   public void createSolrIndex() throws Exception {
2072     if (connectToSpatialDbs) {
2073       // flush() the repo because we need to make sure feature type testdata is fully stored
2074       // before creating the Solr index (which requires access to the feature type settings)
2075       featureSourceRepository.flush();
2076 
2077       logger.info("Creating Solr index");
2078       @SuppressWarnings("PMD.AvoidUsingHardCodedIP")
2079       final String solrUrl = "http://" + (connectToSpatialDbsAtLocalhost ? "127.0.0.1" : "solr") + ":8983/solr/";
2080       this.solrService.setSolrUrl(solrUrl);
2081       SolrHelper solrHelper = new SolrHelper(this.solrService.getSolrClientForIndexing())
2082           .withBatchSize(solrBatchSize)
2083           .withGeometryValidationRule(solrGeometryValidationRule);
2084       GeoService geoService =
2085           geoServiceRepository.findById("snapshot-geoserver").orElseThrow();
2086       Application defaultApp = applicationRepository.findByName("default");
2087 
2088       TMFeatureType begroeidterreindeelFT = geoService.findFeatureTypeForLayer(
2089           geoService.findLayer("postgis:begroeidterreindeel"), featureSourceRepository);
2090 
2091       TMFeatureType wegdeelFT = geoService.findFeatureTypeForLayer(
2092           geoService.findLayer("sqlserver:wegdeel"), featureSourceRepository);
2093 
2094       TMFeatureType kadastraalPerceelFT = geoService.findFeatureTypeForLayer(
2095           geoService.findLayer("postgis:kadastraal_perceel"), featureSourceRepository);
2096 
2097       try (solrHelper) {
2098         SearchIndex begroeidterreindeelIndex = null;
2099         if (begroeidterreindeelFT != null) {
2100           begroeidterreindeelIndex = new SearchIndex()
2101               .setName("Begroeidterreindeel")
2102               .setFeatureTypeId(begroeidterreindeelFT.getId())
2103               .setSearchFieldsUsed(List.of("class", "plus_fysiekvoorkomen", "bronhouder"))
2104               .setSearchDisplayFieldsUsed(List.of("class", "plus_fysiekvoorkomen"));
2105           begroeidterreindeelIndex = searchIndexRepository.save(begroeidterreindeelIndex);
2106           begroeidterreindeelIndex = solrHelper.addFeatureTypeIndex(
2107               begroeidterreindeelIndex,
2108               begroeidterreindeelFT,
2109               featureSourceFactoryHelper,
2110               searchIndexRepository);
2111           begroeidterreindeelIndex = searchIndexRepository.save(begroeidterreindeelIndex);
2112         }
2113 
2114         SearchIndex kadastraalPerceelIndex = null;
2115         if (kadastraalPerceelFT != null) {
2116           kadastraalPerceelIndex = new SearchIndex()
2117               .setName("kadastraal_perceel")
2118               .setFeatureTypeId(kadastraalPerceelFT.getId())
2119               .setSearchFieldsUsed(List.of("aanduiding"))
2120               .setSearchDisplayFieldsUsed(List.of("aanduiding"));
2121           kadastraalPerceelIndex = searchIndexRepository.save(kadastraalPerceelIndex);
2122           kadastraalPerceelIndex = solrHelper.addFeatureTypeIndex(
2123               kadastraalPerceelIndex,
2124               kadastraalPerceelFT,
2125               featureSourceFactoryHelper,
2126               searchIndexRepository);
2127           kadastraalPerceelIndex = searchIndexRepository.save(kadastraalPerceelIndex);
2128         }
2129 
2130         SearchIndex wegdeelIndex = null;
2131         if (wegdeelFT != null) {
2132           wegdeelIndex = new SearchIndex()
2133               .setName("Wegdeel")
2134               .setFeatureTypeId(wegdeelFT.getId())
2135               .setSearchFieldsUsed(List.of(
2136                   "function_", "plus_fysiekvoorkomenwegdeel", "surfacematerial", "bronhouder"))
2137               .setSearchDisplayFieldsUsed(List.of("function_", "plus_fysiekvoorkomenwegdeel"));
2138           wegdeelIndex = searchIndexRepository.save(wegdeelIndex);
2139           wegdeelIndex = solrHelper.addFeatureTypeIndex(
2140               wegdeelIndex, wegdeelFT, featureSourceFactoryHelper, searchIndexRepository);
2141           wegdeelIndex = searchIndexRepository.save(wegdeelIndex);
2142         }
2143 
2144         featureSourceRepository
2145             .getByTitle("PostGIS")
2146             .flatMap(fs -> fs.getFeatureTypes().stream()
2147                 .filter(ft -> ft.getName().equals("bak"))
2148                 .findFirst())
2149             .ifPresent(ft -> {
2150               SearchIndex bak = new SearchIndex()
2151                   .setName("bak")
2152                   .setFeatureTypeId(ft.getId())
2153                   .setSearchFieldsUsed(List.of("gmlid", "identificatie", "plus_type"))
2154                   .setSearchDisplayFieldsUsed(List.of("gmlid", "plus_type", "bronhouder"));
2155               searchIndexRepository.save(bak);
2156               try {
2157                 bak = solrHelper.addFeatureTypeIndex(
2158                     bak, ft, featureSourceFactoryHelper, searchIndexRepository);
2159                 searchIndexRepository.save(bak);
2160               } catch (IOException | SolrServerException e) {
2161                 throw new RuntimeException(e);
2162               }
2163             });
2164 
2165         // creating a solr index of config this will/should fail because there is no primary key in
2166         // the FT
2167         featureSourceRepository
2168             .getByTitle("PostGIS OSM")
2169             .flatMap(fs -> fs.getFeatureTypes().stream()
2170                 .filter(ft -> ft.getName().equals("osm_roads"))
2171                 .findFirst())
2172             .ifPresent(ft -> {
2173               SearchIndex osm_no_pk = new SearchIndex()
2174                   .setName("osm_no_pk")
2175                   .setFeatureTypeId(ft.getId())
2176                   .setSearchFieldsUsed(List.of("landuse", "osm_id", "natural", "boundary"))
2177                   .setSearchDisplayFieldsUsed(
2178                       List.of("landuse", "osm_id", "natural", "amenity", "boundary"));
2179               searchIndexRepository.save(osm_no_pk);
2180             });
2181 
2182         AppTreeLayerNode begroeidTerreindeelLayerNode = defaultApp
2183             .getAllAppTreeLayerNode()
2184             .filter(node -> node.getId().equals("lyr:snapshot-geoserver:postgis:begroeidterreindeel"))
2185             .findFirst()
2186             .orElse(null);
2187 
2188         if (begroeidTerreindeelLayerNode != null && begroeidterreindeelIndex != null) {
2189           defaultApp
2190               .getAppLayerSettings(begroeidTerreindeelLayerNode)
2191               .setSearchIndexId(begroeidterreindeelIndex.getId());
2192         }
2193 
2194         AppTreeLayerNode kadastraalPerceelLayerNode = defaultApp
2195             .getAllAppTreeLayerNode()
2196             .filter(node -> node.getId().equals("lyr:snapshot-geoserver:postgis:kadastraal_perceel"))
2197             .findFirst()
2198             .orElse(null);
2199 
2200         if (kadastraalPerceelLayerNode != null && kadastraalPerceelIndex != null) {
2201           defaultApp
2202               .getAppLayerSettings(kadastraalPerceelLayerNode)
2203               .setSearchIndexId(kadastraalPerceelIndex.getId());
2204         }
2205 
2206         AppTreeLayerNode wegdeel = defaultApp
2207             .getAllAppTreeLayerNode()
2208             .filter(node -> node.getId().equals("lyr:snapshot-geoserver:sqlserver:wegdeel"))
2209             .findFirst()
2210             .orElse(null);
2211 
2212         if (wegdeel != null && wegdeelIndex != null) {
2213           defaultApp.getAppLayerSettings(wegdeel).setSearchIndexId(wegdeelIndex.getId());
2214         }
2215 
2216         applicationRepository.save(defaultApp);
2217       }
2218     }
2219   }
2220 
2221   private void createSearchIndexTasks() {
2222     logger.info("Creating search index tasks");
2223     List.of("Begroeidterreindeel", "kadastraal_perceel")
2224         .forEach(name -> searchIndexRepository.findByName(name).ifPresent(index -> {
2225           index.setSchedule(new TaskSchedule()
2226               /* hour */
2227               .cronExpression("0 0 0/1 1/1 * ? *")
2228               // /* 15 min */
2229               // .cronExpression("0 0/15 * 1/1 * ? *")
2230               .description("Update Solr index \"" + name + "\" every hour"));
2231           try {
2232             final UUID uuid = taskManagerService.createTask(
2233                 IndexTask.class,
2234                 new TMJobDataMap(Map.of(
2235                     Task.TYPE_KEY,
2236                     TaskType.INDEX,
2237                     Task.DESCRIPTION_KEY,
2238                     index.getSchedule().getDescription(),
2239                     IndexTask.INDEX_KEY,
2240                     index.getId().toString(),
2241                     Task.PRIORITY_KEY,
2242                     10)),
2243                 index.getSchedule().getCronExpression());
2244 
2245             index.getSchedule().setUuid(uuid);
2246             searchIndexRepository.save(index);
2247 
2248             logger.info("Created task to update Solr index with key: {}", uuid);
2249           } catch (SchedulerException e) {
2250             logger.error("Error creating scheduled solr index task", e);
2251           }
2252         }));
2253   }
2254 
2255   private void createUploads() throws IOException {
2256     for (int i = 0; i < 4; i++) {
2257       // hash b0c2a7e5059c831c289505750defcf53edac5461 will be deleted at the end of the testsuite
2258       uploadRepository.save(new Upload()
2259           .setCategory(UploadCategory.UNRESTRICTED)
2260           .setFilename("upload" + i + ".png")
2261           .setMimeType("image/png")
2262           .setContent(new ClassPathResource("test/upload.png").getContentAsByteArray())
2263           .setLastModified(OffsetDateTime.now(ZoneId.systemDefault())));
2264     }
2265   }
2266 
2267   private void createPages() throws IOException {
2268     Upload logo = new Upload()
2269         .setCategory(UploadCategory.PORTAL_IMAGE)
2270         .setFilename("gradient-portal.svg")
2271         .setMimeType("image/svg+xml")
2272         .setContent(new ClassPathResource("test/gradient-logo.svg").getContentAsByteArray())
2273         .setLastModified(OffsetDateTime.now(ZoneId.systemDefault()));
2274     uploadRepository.save(logo);
2275 
2276     Page loggedIn = new Page();
2277     loggedIn.setAuthorizationRules(ruleLoggedIn);
2278     loggedIn.setName("loggedIn");
2279     loggedIn.setType("page");
2280     loggedIn.setContent("About Tailormap");
2281     loggedIn.setContent("""
2282 # About Tailormap
2283 This is a page for logged in users.
2284 """);
2285     pageRepository.save(loggedIn);
2286 
2287     Page about = new Page();
2288     about.setAuthorizationRules(ruleAnonymousRead);
2289     about.setName("about");
2290     about.setType("page");
2291     about.setContent("About Tailormap");
2292     about.setContent("""
2293 # About Tailormap
2294 
2295 This is a page about *Tailormap*. It doesn't say much yet.
2296 """);
2297     pageRepository.save(about);
2298 
2299     Page page = new Page();
2300     page.setAuthorizationRules(ruleAnonymousRead);
2301     page.setName("home");
2302     page.setType("page");
2303     page.setTitle("Tailormap - Home");
2304     page.setContent("""
2305 # Welcome to Tailormap!
2306 
2307 This page is only visible when you implement a frontend to display pages, or get it (including a simple CMS)
2308 from [B3Partners](https://www.b3partners.nl)!
2309 """);
2310     page.setClassName(null);
2311     page.setTiles(List.of(
2312         new PageTile()
2313             .authorizationRules(ruleAnonymousRead)
2314             .id(UUID.randomUUID().toString())
2315             .title("Default app")
2316             .tileType(PageTile.TileTypeEnum.APPLICATION)
2317             .applicationId(Optional.ofNullable(applicationRepository.findByName("default"))
2318                 .map(Application::getId)
2319                 .orElse(null))
2320             .image(logo.getId().toString())
2321             .content("*Default app* tile content")
2322             .filterRequireAuthorization(false)
2323             .openInNewWindow(false),
2324         new PageTile()
2325             .authorizationRules(ruleAnonymousRead)
2326             .id(UUID.randomUUID().toString())
2327             .title("Secured app")
2328             .tileType(PageTile.TileTypeEnum.APPLICATION)
2329             .applicationId(Optional.ofNullable(applicationRepository.findByName("secured"))
2330                 .map(Application::getId)
2331                 .orElse(null))
2332             .filterRequireAuthorization(true)
2333             .content("Secure app, only shown if user has authorization")
2334             .openInNewWindow(false),
2335         new PageTile()
2336             .authorizationRules(ruleAnonymousRead)
2337             .id(UUID.randomUUID().toString())
2338             .title("Secured app (unfiltered)")
2339             .tileType(PageTile.TileTypeEnum.APPLICATION)
2340             .applicationId(Optional.ofNullable(applicationRepository.findByName("secured"))
2341                 .map(Application::getId)
2342                 .orElse(null))
2343             .filterRequireAuthorization(false)
2344             .content("Secure app, tile shown to everyone")
2345             .openInNewWindow(false),
2346         new PageTile()
2347             .authorizationRules(ruleAnonymousRead)
2348             .id(UUID.randomUUID().toString())
2349             .title("About")
2350             .tileType(PageTile.TileTypeEnum.PAGE)
2351             .pageId(about.getId())
2352             .openInNewWindow(false),
2353         new PageTile()
2354             .authorizationRules(ruleAnonymousRead)
2355             .id(UUID.randomUUID().toString())
2356             .title("B3Partners")
2357             .tileType(PageTile.TileTypeEnum.URL)
2358             .url("https://www.b3partners.nl/")
2359             .openInNewWindow(true),
2360         new PageTile()
2361             .authorizationRules(ruleLoggedIn)
2362             .id(UUID.randomUUID().toString())
2363             .title("Github repository")
2364             .tileType(PageTile.TileTypeEnum.URL)
2365             .url("https://github.com/Tailormap/tailormap-viewer")
2366             .openInNewWindow(true),
2367         new PageTile()
2368             .authorizationRules(ruleAnonymousRead)
2369             .id(UUID.randomUUID().toString())
2370             .tileType(PageTile.TileTypeEnum.PAGE)
2371             .title("Secured page")
2372             .pageId(loggedIn.getId())
2373             .filterRequireAuthorization(true)
2374             .openInNewWindow(true),
2375         new PageTile()
2376             .authorizationRules(ruleAnonymousRead)
2377             .id(UUID.randomUUID().toString())
2378             .tileType(PageTile.TileTypeEnum.PAGE)
2379             .title("Secured page (unfiltered)")
2380             .pageId(loggedIn.getId())
2381             .filterRequireAuthorization(false)
2382             .openInNewWindow(true)));
2383     pageRepository.save(page);
2384 
2385     Configuration c = new Configuration();
2386     c.setKey(HOME_PAGE);
2387     c.setValue(page.getId().toString());
2388     configurationRepository.save(c);
2389 
2390     List<MenuItem> globalMenuItems = List.of(
2391         new MenuItem().pageId(about.getId()).label("About").openInNewWindow(false),
2392         new MenuItem()
2393             .label("B3Partners website")
2394             .url("https://www.b3partners.nl/")
2395             .openInNewWindow(true)
2396             .exclusiveOnPageId(about.getId()));
2397     c = new Configuration();
2398     c.setKey(PORTAL_MENU);
2399     c.setJsonValue(new JsonMapper().valueToTree(globalMenuItems));
2400     configurationRepository.save(c);
2401   }
2402 
2403   private void insertTestDrawing() {
2404     // note that the drawing uuid is hardcoded and used in the DrawingControllerIntegrationTest
2405     try {
2406       this.jdbcClient.sql("""
2407 INSERT INTO data.drawing (id,name,description,domain_data,created_by,created_at,updated_by,updated_at,srid,"version") VALUES
2408 ('38faa008-013e-49d4-9528-8f58c94d8791'::uuid,'Testcase','A drawing that is inserted as part of the testdata','{"items": 1, "domain": "test drawings"}','tm-admin','2025-02-27 17:53:36.095164+01','tm-admin','2025-02-27 17:54:19.384961+01',28992,1);
2409 """).update();
2410 
2411       this.jdbcClient.sql("""
2412 INSERT INTO data.drawing_feature (drawing_id,id,geometry,properties) VALUES
2413 ('38faa008-013e-49d4-9528-8f58c94d8791'::uuid, '394e0d4a-b374-4d00-94c8-1758ea70e9d9'::uuid, 'SRID=28992;POLYGON ((131982.01 458929.27, 131957.31 458755.45, 132072.39 458736.69, 132099.06 458910.51, 131982.01 458929.27))'::public.geometry, '{"type": "POLYGON", "style": {"label": "", "marker": "circle", "fillColor": "rgb(117, 117, 117)", "labelSize": 15, "labelColor": "rgb(0, 0, 0)", "markerSize": 5, "fillOpacity": 30, "strokeColor": "rgb(98, 54, 255)", "strokeWidth": 3, "strokeOpacity": 100, "markerRotation": 0, "markerFillColor": "rgb(98, 54, 255)", "labelOutlineColor": "rgb(189, 189, 189)", "markerStrokeColor": "rgb(98, 54, 255)", "markerStrokeWidth": 1}}'::jsonb),
2414 ('38faa008-013e-49d4-9528-8f58c94d8791'::uuid, '89fc320c-41a3-4635-8d98-39d822339692'::uuid, 'SRID=28992;POINT (131897.55 458971.24)'::public.geometry, '{"type": "CIRCLE", "style": {"label": "CIRCLE", "marker": "circle", "fillColor": "rgb(117, 117, 117)", "labelSize": 15, "labelColor": "rgb(0, 0, 0)", "markerSize": 5, "fillOpacity": 30, "strokeColor": "rgb(98, 54, 255)", "strokeWidth": 3, "strokeOpacity": 100, "markerRotation": 0, "markerFillColor": "rgb(98, 54, 255)", "labelOutlineColor": "rgb(189, 189, 189)", "markerStrokeColor": "rgb(98, 54, 255)", "markerStrokeWidth": 1}, "radius": 14.989999999990687}'::jsonb),
2415 ('38faa008-013e-49d4-9528-8f58c94d8791'::uuid, '5d6252cc-25b6-4a43-9053-0779b86895a7'::uuid, 'SRID=28992;LINESTRING (131920.76 458754.96, 131923.73 458783.1, 131930.15 458793.97, 131945.95 458912.98, 131967.68 458946.06)'::public.geometry, '{"type": "LINE", "style": {"label": "", "marker": "circle", "fillColor": "rgb(255, 82, 82)", "labelSize": 15, "labelColor": "rgb(0, 0, 0)", "markerSize": 5, "fillOpacity": 30, "strokeColor": "rgb(255, 82, 82)", "strokeWidth": 13, "strokeOpacity": 100, "markerRotation": 0, "markerFillColor": "rgb(98, 54, 255)", "labelOutlineColor": "rgb(189, 189, 189)", "markerStrokeColor": "rgb(98, 54, 255)", "markerStrokeWidth": 1}}'::jsonb)
2416 """).update();
2417     } catch (Exception any) {
2418       logger.error("Error inserting test drawing in data schema, some tests may fail", any);
2419     }
2420   }
2421 
2422   private void insertDrawingStyle() throws IOException {
2423     Upload upload = new Upload()
2424         .setCategory(UploadCategory.DRAWING_STYLE_IMAGE)
2425         .setMimeType("image/svg+xml")
2426         .setFilename("ISO_7001_PI_PF_007.svg")
2427         .setContent(new ClassPathResource("test/ISO_7001_PI_PF_007.svg").getContentAsByteArray())
2428         .setLastModified(OffsetDateTime.now(ZoneId.systemDefault()));
2429     upload = uploadRepository.save(upload);
2430     UUID drinkwaterImageId = upload.getId();
2431 
2432     upload = new Upload()
2433         .setCategory(UploadCategory.DRAWING_STYLE_IMAGE)
2434         .setMimeType("image/svg+xml")
2435         .setFilename("lichtpunt.svg")
2436         .setContent(new ClassPathResource("test/lichtpunt.svg").getContentAsByteArray())
2437         .setLastModified(OffsetDateTime.now(ZoneId.systemDefault()));
2438     upload = uploadRepository.save(upload);
2439     UUID lichtpuntImageId = upload.getId();
2440 
2441     upload = new Upload()
2442         .setCategory(UploadCategory.DRAWING_STYLE_IMAGE)
2443         .setMimeType("image/svg+xml")
2444         .setFilename("ISO_7010_E003_-_First_aid_sign.svg")
2445         .setContent(new ClassPathResource("test/ISO_7010_E003_-_First_aid_sign.svg").getContentAsByteArray())
2446         .setLastModified(OffsetDateTime.now(ZoneId.systemDefault()));
2447     upload = uploadRepository.save(upload);
2448     UUID firstAidImageId = upload.getId();
2449 
2450     Properties props = new Properties();
2451     props.putAll(Map.of(
2452         "water-uuid", drinkwaterImageId.toString(),
2453         "lichtpunt-uuid", lichtpuntImageId.toString(),
2454         "first-aid-uuid", firstAidImageId.toString()));
2455 
2456     String drawingStyles =
2457         new ClassPathResource("test/object-drawing-style.json").getContentAsString(StandardCharsets.UTF_8);
2458     drawingStyles = new PropertyPlaceholderHelper("${", "}").replacePlaceholders(drawingStyles, props);
2459 
2460     // save the updated drawing style
2461     upload = new Upload()
2462         .setCategory(UploadCategory.DRAWING_STYLE)
2463         .setMimeType("application/json")
2464         .setFilename("object-drawing-style.json")
2465         .setContent(drawingStyles.getBytes(StandardCharsets.UTF_8))
2466         .setLastModified(OffsetDateTime.now(ZoneId.systemDefault()));
2467     uploadRepository.save(upload);
2468   }
2469 }