Skip to content

Commit 7a17c28

Browse files
First approach not work
1 parent 803c4f3 commit 7a17c28

6 files changed

Lines changed: 35 additions & 487 deletions

File tree

server/src/main/java/au/org/aodn/ogcapi/server/core/configuration/GeoServerConfig.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import au.org.aodn.ogcapi.server.core.service.geoserver.wfs.WfsDefaultParam;
55
import au.org.aodn.ogcapi.server.core.service.geoserver.wfs.WfsServer;
66
import au.org.aodn.ogcapi.server.core.service.geoserver.wms.WmsServer;
7-
import au.org.aodn.ogcapi.server.core.service.geoserver.wps.WpsServer;
87
import au.org.aodn.ogcapi.server.core.util.RestTemplateUtils;
98
import org.springframework.beans.factory.annotation.Qualifier;
109
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -41,12 +40,4 @@ public WfsServer createWfsServer(Search search,
4140
public WmsServer createWmsServer(Search search, @Lazy WfsServer wfsServer, @Qualifier("pretendUserEntity") HttpEntity<?> entity) {
4241
return new WmsServer(search, wfsServer, entity);
4342
}
44-
45-
@Bean
46-
public WpsServer createWpsServer(WmsServer wmsServer,
47-
WfsServer wfsServer,
48-
RestTemplate restTemplate,
49-
@Qualifier("pretendUserEntity") HttpEntity<?> entity) {
50-
return new WpsServer(wmsServer, wfsServer, restTemplate, entity);
51-
}
5243
}

server/src/main/java/au/org/aodn/ogcapi/server/core/model/enumeration/DatasetDownloadEnums.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package au.org.aodn.ogcapi.server.core.model.enumeration;
22

3+
import au.org.aodn.ogcapi.processes.model.Execute;
34
import lombok.Getter;
45

6+
import java.util.List;
7+
58
/**
69
* the values are used for aws batch's environment variables
710
*/
@@ -28,6 +31,25 @@ public enum Parameter {
2831
Parameter(String value) {
2932
this.value = value;
3033
}
34+
35+
public String getStringInput(Execute input) {
36+
Object value = input.getInputs().get(getValue());
37+
return value == null ? null : value.toString();
38+
}
39+
40+
public Object getObjectInput(Execute input) {
41+
return input.getInputs().get(getValue());
42+
}
43+
44+
public List<String> getListInput(Execute input) {
45+
Object value = input.getInputs().get(getValue());
46+
if(value instanceof List<?> list) {
47+
return list.stream().map(String::valueOf).toList();
48+
}
49+
else {
50+
return null;
51+
}
52+
}
3153
}
3254

3355
@Getter

server/src/main/java/au/org/aodn/ogcapi/server/core/service/geoserver/wps/WpsServer.java

Lines changed: 0 additions & 212 deletions
This file was deleted.

server/src/main/java/au/org/aodn/ogcapi/server/processes/RestApi.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,35 +128,31 @@ public SseEmitter executeSse(
128128
@RequestBody Execute body) {
129129

130130
try {
131-
String uuid = body.getInputs().get(DatasetDownloadEnums.Parameter.UUID.getValue()).toString();
132-
String startDate = body.getInputs().get(DatasetDownloadEnums.Parameter.START_DATE.getValue()).toString();
133-
String endDate = body.getInputs().get(DatasetDownloadEnums.Parameter.END_DATE.getValue()).toString();
134-
String layerName = body.getInputs().get(DatasetDownloadEnums.Parameter.LAYER_NAME.getValue()).toString();
135-
String outputFormat = body.getInputs().get(DatasetDownloadEnums.Parameter.OUTPUT_FORMAT.getValue()).toString();
136-
var multiPolygon = body.getInputs().get(DatasetDownloadEnums.Parameter.MULTI_POLYGON.getValue());
137-
138-
List<String> fields = body.getInputs().get(DatasetDownloadEnums.Parameter.FIELDS.getValue()) instanceof List<?> list
139-
? list.stream().map(String::valueOf).toList()
140-
: null;
141-
142-
if(FeatureRequest.GeoServerOutputFormat.fromString(outputFormat) == FeatureRequest.GeoServerOutputFormat.UNKNOWN) {
143-
throw new IllegalArgumentException(String.format("Output format %s not supported", outputFormat));
131+
String uuid = DatasetDownloadEnums.Parameter.UUID.getStringInput(body);
132+
String layerName = DatasetDownloadEnums.Parameter.LAYER_NAME.getStringInput(body);
133+
String startDate = DatasetDownloadEnums.Parameter.START_DATE.getStringInput(body);
134+
String endDate = DatasetDownloadEnums.Parameter.END_DATE.getStringInput(body);
135+
String outputFormat = DatasetDownloadEnums.Parameter.OUTPUT_FORMAT.getStringInput(body);
136+
Object multiPolygon = DatasetDownloadEnums.Parameter.MULTI_POLYGON.getObjectInput(body);
137+
List<String> fields = DatasetDownloadEnums.Parameter.FIELDS.getListInput(body);
138+
139+
if(uuid == null || layerName == null) {
140+
throw new IllegalArgumentException("UUID and LayerName cannot null");
144141
}
145142

146143
ProcessIdEnum id = ProcessIdEnum.fromString(processId);
147144
SseEmitter emitter;
148145

149146
switch (id) {
150147
case DOWNLOAD_WFS_SSE: {
148+
if(FeatureRequest.GeoServerOutputFormat.fromString(outputFormat) == FeatureRequest.GeoServerOutputFormat.UNKNOWN) {
149+
throw new IllegalArgumentException(String.format("Output format %s not supported", outputFormat));
150+
}
151151
emitter = restServices.downloadWfsDataWithSse(
152152
uuid, startDate, endDate, multiPolygon, fields, layerName, outputFormat
153153
);
154154
break;
155155
}
156-
case DOWNLOAD_WFS_SIZE: {
157-
emitter = restServices.downloadWfsSizeWithSse(uuid, layerName, startDate, endDate, multiPolygon, fields);
158-
break;
159-
}
160156
default: {
161157
emitter = new SseEmitter(0L);
162158
emitter.completeWithError(new BadRequestException(

server/src/main/java/au/org/aodn/ogcapi/server/processes/RestServices.java

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import au.org.aodn.ogcapi.server.core.exception.wfs.WfsErrorHandler;
44
import au.org.aodn.ogcapi.server.core.model.enumeration.DatasetDownloadEnums;
55
import au.org.aodn.ogcapi.server.core.service.geoserver.wfs.DownloadWfsDataService;
6-
import au.org.aodn.ogcapi.server.core.service.geoserver.wps.WpsServer;
7-
import au.org.aodn.ogcapi.server.core.util.DatetimeUtils;
86
import au.org.aodn.ogcapi.server.core.util.EmailUtils;
97
import com.fasterxml.jackson.core.JsonProcessingException;
108
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -37,9 +35,6 @@ public class RestServices {
3735
@Autowired
3836
private DownloadWfsDataService downloadWfsDataService;
3937

40-
@Autowired
41-
protected WpsServer wpsServer;
42-
4338
public RestServices(BatchClient batchClient, ObjectMapper objectMapper) {
4439
this.batchClient = batchClient;
4540
this.objectMapper = objectMapper;
@@ -300,59 +295,4 @@ public SseEmitter downloadWfsDataWithSse(String uuid,
300295
});
301296
return emitter;
302297
}
303-
304-
public SseEmitter downloadWfsSizeWithSse(String uuid,
305-
String layerName,
306-
String startDate,
307-
String endDate,
308-
Object multiPolygon,
309-
List<String> fields) {
310-
311-
312-
final SseEmitter emitter = new SseEmitter(0L);
313-
314-
CompletableFuture.runAsync(() -> {
315-
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
316-
CountDownLatch done = new CountDownLatch(1);
317-
318-
// Send keep-alive every 20 seconds
319-
executor.execute(() -> {
320-
try {
321-
while (done.await(20, TimeUnit.SECONDS)) {
322-
emitter.send(SseEmitter.event()
323-
.name("keep-alive")
324-
.data(Map.of(
325-
"timestamp", System.currentTimeMillis(),
326-
"message", "Waiting for WFS server response..."
327-
)));
328-
}
329-
}
330-
catch(Exception e) {
331-
done.countDown();
332-
}
333-
});
334-
335-
WpsServer.WpsProcessRequest request = WpsServer.WpsProcessRequest.builder()
336-
.layerName(layerName)
337-
.datetime(DatetimeUtils.formatOGCDateTime(startDate, endDate))
338-
.properties(fields)
339-
.multiPolygon(multiPolygon)
340-
.build();
341-
342-
try {
343-
emitter.send(wpsServer.getEstimateDownloadSize(
344-
uuid,
345-
request
346-
));
347-
}
348-
catch(Exception e) {
349-
emitter.completeWithError(e);
350-
}
351-
finally {
352-
done.countDown();
353-
emitter.complete();
354-
}
355-
});
356-
return emitter;
357-
}
358298
}

0 commit comments

Comments
 (0)