1
2
3
4
5
6 package org.tailormap.api.geotools.featuresources;
7
8 import java.io.IOException;
9 import org.geotools.api.data.SimpleFeatureSource;
10 import org.springframework.beans.factory.annotation.Value;
11 import org.springframework.stereotype.Service;
12 import org.tailormap.api.persistence.TMFeatureSource;
13 import org.tailormap.api.persistence.TMFeatureType;
14
15 @Service
16 public class FeatureSourceFactoryHelper {
17
18 @Value("${tailormap-api.timeout}")
19 private int timeout;
20
21 public SimpleFeatureSource openGeoToolsFeatureSource(TMFeatureType tmft) throws IOException {
22 return openGeoToolsFeatureSource(tmft, timeout);
23 }
24
25 public SimpleFeatureSource openGeoToolsFeatureSource(TMFeatureType tmft, int timeout) throws IOException {
26 FeatureSourceHelper sh = getHelper(tmft.getFeatureSource());
27 return sh.openGeoToolsFeatureSource(tmft, timeout);
28 }
29
30 private FeatureSourceHelper getHelper(TMFeatureSource fs) {
31 return switch (fs.getProtocol()) {
32 case JDBC -> new JDBCFeatureSourceHelper();
33 case WFS -> new WFSFeatureSourceHelper();
34 default -> throw new IllegalArgumentException("Invalid protocol: " + fs.getProtocol());
35 };
36 }
37 }