Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -36,7 +37,7 @@ public WfsServer createWfsServer(Search search,
}

@Bean
public WmsServer createWmsServer(@Qualifier("pretendUserEntity") HttpEntity<?> entity) {
return new WmsServer(entity);
public WmsServer createWmsServer(Search search, @Lazy WfsServer wfsServer, @Qualifier("pretendUserEntity") HttpEntity<?> entity) {
return new WmsServer(search, wfsServer, entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import org.springframework.web.util.UriComponentsBuilder;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
Expand All @@ -26,20 +25,17 @@ public class DownloadWfsDataService {
private final WmsServer wmsServer;
private final WfsServer wfsServer;
private final RestTemplate restTemplate;
private final WfsDefaultParam wfsDefaultParam;
private final HttpEntity<?> pretendUserEntity;

public DownloadWfsDataService(
WmsServer wmsServer,
WfsServer wfsServer,
RestTemplate restTemplate,
WfsDefaultParam wfsDefaultParam,
@Qualifier("pretendUserEntity") HttpEntity<?> pretendUserEntity
) {
this.wmsServer = wmsServer;
this.wfsServer = wfsServer;
this.restTemplate = restTemplate;
this.wfsDefaultParam = wfsDefaultParam;
this.pretendUserEntity = pretendUserEntity;
}

Expand Down Expand Up @@ -95,33 +91,6 @@ private String buildCqlFilter(String startDate, String endDate, Object multiPoly

return cqlFilter.toString();
}

/**
* Build WFS GetFeature URL
*/
private String buildWfsRequestUrl(String wfsUrl, String layerName, String cqlFilter) {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(wfsUrl)
.scheme("https"); // Force HTTPS to fix redirect

Map<String, String> param = new HashMap<>(wfsDefaultParam.getDownload());
param.put("typeName", layerName);
param.put("outputFormat", "text/csv");

// Add general query parameters
param.forEach((key, value) -> {
if (value != null) {
builder.queryParam(key, value);
}
});

// Add CQL filter if present
if (cqlFilter != null && !cqlFilter.isEmpty()) {
builder.queryParam("cql_filter", cqlFilter);
}

return builder.build().toUriString();
}

/**
* Does collection lookup, WFS validation, field retrieval, and URL building
*/
Expand All @@ -130,7 +99,7 @@ public String prepareWfsRequestUrl(
String startDate,
String endDate,
Object multiPolygon,
List<String> fields,// TODO: currently not used
List<String> fields,
String layerName) {

DescribeLayerResponse describeLayerResponse = wmsServer.describeLayer(uuid, FeatureRequest.builder().layerName(layerName).build());
Expand Down Expand Up @@ -167,12 +136,11 @@ public String prepareWfsRequestUrl(
String cqlFilter = buildCqlFilter(validStartDate, validEndDate, multiPolygon, wfsFieldModel);

// Build final WFS request URL
String wfsRequestUrl = buildWfsRequestUrl(wfsServerUrl, wfsTypeName, cqlFilter);
String wfsRequestUrl = wfsServer.createWfsRequestUrl(wfsServerUrl, wfsTypeName, fields, cqlFilter, null);

log.info("Prepared WFS request URL: {}", wfsRequestUrl);
return wfsRequestUrl;
}

/**
* Execute WFS request with SSE support
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,34 @@ public WfsServer(Search search,
this.pretendUserEntity = entity;
this.wfsDefaultParam = wfsDefaultParam;
}
/**
* Build WFS GetFeature URL
*/
protected String createWfsRequestUrl(String wfsUrl, String layerName, List<String> fields, String cqlFilter, String outputFormat) {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(wfsUrl)
.scheme("https"); // Force HTTPS to fix redirect

Map<String, String> param = new HashMap<>(wfsDefaultParam.getDownload());
param.put("typeName", layerName);
param.put("outputFormat", outputFormat == null ? "text/csv" : outputFormat);

if(fields != null) {
param.put("propertyName", String.join(",", fields));
}
// Add general query parameters
param.forEach((key, value) -> {
if (value != null) {
builder.queryParam(key, value);
}
});

// Add CQL filter if present
if (cqlFilter != null && !cqlFilter.isEmpty()) {
builder.queryParam("cql_filter", cqlFilter);
}

return builder.build().toUriString();
}
/**
* Get all WFS links from a collection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ public class WmsServer {
@Autowired
protected RestTemplateUtils restTemplateUtils;

@Lazy
@Autowired
protected WfsServer wfsServer;

@Autowired
protected Search search;

@Autowired
protected WmsDefaultParam wmsDefaultParam;

Expand All @@ -67,13 +60,17 @@ public class WmsServer {
protected WmsServer self;

protected final HttpEntity<?> pretendUserEntity;
protected WfsServer wfsServer;
protected Search search;

public WmsServer(HttpEntity<?> entity) {
public WmsServer(Search search, WfsServer wfsServer, HttpEntity<?> entity) {
xmlMapper = new XmlMapper();
xmlMapper.registerModule(new JavaTimeModule()); // Add JavaTimeModule
xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

pretendUserEntity = entity;
this.pretendUserEntity = entity;
this.wfsServer = wfsServer;
this.search = search;
}

/**
Expand Down Expand Up @@ -447,7 +444,7 @@ protected List<String> createMapFeatureQueryUrl(String url, String uuid, Feature
protected Optional<String> getMapServerUrl(String collectionId, FeatureRequest request) {
// Get the record contains the map feature, given one uuid , 1 result expected
ElasticSearchBase.SearchResult<StacCollectionModel> result = search.searchCollections(collectionId);
if (!result.getCollections().isEmpty()) {
if (result != null && result.getCollections() != null && !result.getCollections().isEmpty()) {
StacCollectionModel model = result.getCollections().get(0);

String layerName = request != null ? request.getLayerName() : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import au.org.aodn.ogcapi.processes.model.InlineResponse200;
import au.org.aodn.ogcapi.processes.model.ProcessList;
import au.org.aodn.ogcapi.processes.model.Results;
import au.org.aodn.ogcapi.server.core.exception.wfs.WfsErrorHandler;
import au.org.aodn.ogcapi.server.core.model.InlineValue;
import au.org.aodn.ogcapi.server.core.model.enumeration.DatasetDownloadEnums;
import au.org.aodn.ogcapi.server.core.model.enumeration.InlineResponseKeyEnum;
Expand Down Expand Up @@ -122,12 +121,15 @@ public SseEmitter downloadWfsSse(
final SseEmitter emitter = new SseEmitter(0L);

try {
var uuid = (String) body.getInputs().get(DatasetDownloadEnums.Parameter.UUID.getValue());
var startDate = (String) body.getInputs().get(DatasetDownloadEnums.Parameter.START_DATE.getValue());
var endDate = (String) body.getInputs().get(DatasetDownloadEnums.Parameter.END_DATE.getValue());
String uuid = body.getInputs().get(DatasetDownloadEnums.Parameter.UUID.getValue()).toString();
String startDate = body.getInputs().get(DatasetDownloadEnums.Parameter.START_DATE.getValue()).toString();
String endDate = body.getInputs().get(DatasetDownloadEnums.Parameter.END_DATE.getValue()).toString();
String layerName = body.getInputs().get(DatasetDownloadEnums.Parameter.LAYER_NAME.getValue()).toString();
var multiPolygon = body.getInputs().get(DatasetDownloadEnums.Parameter.MULTI_POLYGON.getValue());
var fields = (List<String>) body.getInputs().get(DatasetDownloadEnums.Parameter.FIELDS.getValue());
var layerName = (String) body.getInputs().get(DatasetDownloadEnums.Parameter.LAYER_NAME.getValue());

List<String> fields = body.getInputs().get(DatasetDownloadEnums.Parameter.FIELDS.getValue()) instanceof List<?> list
? list.stream().map(String::valueOf).toList()
: null;

return restServices.downloadWfsDataWithSse(
uuid, startDate, endDate, multiPolygon, fields, layerName, emitter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import au.org.aodn.ogcapi.server.core.exception.wfs.WfsErrorHandler;
import au.org.aodn.ogcapi.server.core.model.enumeration.DatasetDownloadEnums;
import au.org.aodn.ogcapi.server.core.service.wfs.DownloadWfsDataService;
import au.org.aodn.ogcapi.server.core.util.DatetimeUtils;
import au.org.aodn.ogcapi.server.core.util.EmailUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Loading
Loading