View Javadoc
1   /*
2    * Copyright (C) 2022 B3Partners B.V.
3    *
4    * SPDX-License-Identifier: MIT
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)
26        throws IOException {
27      FeatureSourceHelper sh = getHelper(tmft.getFeatureSource());
28      return sh.openGeoToolsFeatureSource(tmft, timeout);
29    }
30  
31    private FeatureSourceHelper getHelper(TMFeatureSource fs) {
32      return switch (fs.getProtocol()) {
33        case JDBC -> new JDBCFeatureSourceHelper();
34        case WFS -> new WFSFeatureSourceHelper();
35        default -> throw new IllegalArgumentException("Invalid protocol: " + fs.getProtocol());
36      };
37    }
38  }