diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..cb28b0e3 Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/model/enumeration/CQLFieldsInterface.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/enumeration/CQLFieldsInterface.java index ffcfdcca..6a502cf4 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/model/enumeration/CQLFieldsInterface.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/enumeration/CQLFieldsInterface.java @@ -1,6 +1,7 @@ package au.org.aodn.ogcapi.server.core.model.enumeration; -import co.elastic.clients.elasticsearch._types.SortOptions; +import co.elastic.clients.elasticsearch._types + .SortOptions; import co.elastic.clients.elasticsearch._types.SortOrder; import co.elastic.clients.elasticsearch._types.TopLeftBottomRightGeoBounds; import co.elastic.clients.elasticsearch._types.query_dsl.Query; diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/model/enumeration/FeatureId.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/enumeration/FeatureId.java index 740e0448..d82754fc 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/model/enumeration/FeatureId.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/enumeration/FeatureId.java @@ -8,6 +8,7 @@ public enum FeatureId { wave_buoy_first_data_available("wave_buoy_first_data_available"), wave_buoy_latest_date("wave_buoy_latest_date"), wave_buoy_timeseries("wave_buoy_timeseries"), + wave_buoy_all("wave_buoy_all"), wms_map_tile("wms_map_tile"), wms_map_feature("wms_map_feature"), wms_layers("wms_layers"), // Get all available layers from WMS GetCapabilities diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/service/DasService.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/service/DasService.java index 314587cf..38676654 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/service/DasService.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/service/DasService.java @@ -71,6 +71,14 @@ public byte[] getWaveBuoyData(String from, String to, String buoy){ return httpClient.exchange(waveBuoyDataUrlTemplate, HttpMethod.GET,httpEntity,byte[].class,params).getBody(); } + public byte[] getLatestWaveBuoySites(){ + String waveBuoysUrlTemplate = UriComponentsBuilder.fromUriString(dasConfig.host + "/api/v1/das/data/feature-collection/wave-buoy/all") + .encode() + .toUriString(); + + return httpClient.exchange(waveBuoysUrlTemplate, HttpMethod.GET,httpEntity,byte[].class).getBody(); + } + public boolean isCollectionSupported(String collectionId){ final String waveBuoyRealtimeCollectionID = "b299cdcd-3dee-48aa-abdd-e0fcdbb9cadc"; return waveBuoyRealtimeCollectionID.contentEquals(collectionId); diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/features/RestApi.java b/server/src/main/java/au/org/aodn/ogcapi/server/features/RestApi.java index e6ba917d..86af810c 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/features/RestApi.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/features/RestApi.java @@ -124,6 +124,9 @@ public ResponseEntity getFeature( case wave_buoy_timeseries -> { return featuresService.getWaveBuoyData(collectionId, request.getDatetime(), request.getWaveBuoy()); } + case wave_buoy_all -> { + return featuresService.getLatestWaveBuoySites(collectionId); + } case wfs_fields -> { return featuresService.getWfsFields(collectionId, request); } diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java b/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java index 35242eef..c1aa04a1 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java @@ -298,4 +298,26 @@ public ResponseEntity getWaveBuoyData(String collectionID, String datetime, S return ResponseEntity.internalServerError().build(); } } + + /** + * This is to get all buoy sites with their latest available observation + * + * @param collectionID - uuid + * @return - + */ + public ResponseEntity getLatestWaveBuoySites(String collectionID) { + if (!dasService.isCollectionSupported(collectionID)) { + return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build(); + } + try { + return ResponseEntity + .ok() + .header("Content-Type", MediaType.APPLICATION_JSON_VALUE) + .body(dasService.getLatestWaveBuoySites()); + + } catch (Exception e) { + log.error("Error fetching wave buoy all unique sites date: {}", e.getMessage()); + return ResponseEntity.internalServerError().build(); + } + } } diff --git a/server/src/test/java/au/org/aodn/ogcapi/server/features/RestServicesTest.java b/server/src/test/java/au/org/aodn/ogcapi/server/features/RestServicesTest.java index 5afb0fd8..b256e586 100644 --- a/server/src/test/java/au/org/aodn/ogcapi/server/features/RestServicesTest.java +++ b/server/src/test/java/au/org/aodn/ogcapi/server/features/RestServicesTest.java @@ -83,6 +83,37 @@ public void testGetWaveBuoysLatestDateServiceError() { assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); } + @Test + public void testGetLatestWaveBuoySitesSuccess() { + byte[] mockResponse = "[{\"site_code\":\"SITE1\"}]".getBytes(); + when(dasService.isCollectionSupported(SUPPORTED_COLLECTION_ID)).thenReturn(true); + when(dasService.getLatestWaveBuoySites()).thenReturn(mockResponse); + + ResponseEntity response = restServices.getLatestWaveBuoySites(SUPPORTED_COLLECTION_ID); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(mockResponse, response.getBody()); + } + + @Test + public void testGetLatestWaveBuoySitesUnsupportedCollection() { + when(dasService.isCollectionSupported("unsupported-id")).thenReturn(false); + + ResponseEntity response = restServices.getLatestWaveBuoySites("unsupported-id"); + + assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode()); + } + + @Test + public void testGetLatestWaveBuoySitesServiceError() { + when(dasService.isCollectionSupported(SUPPORTED_COLLECTION_ID)).thenReturn(true); + when(dasService.getLatestWaveBuoySites()).thenThrow(new RuntimeException("Connection refused")); + + ResponseEntity response = restServices.getLatestWaveBuoySites(SUPPORTED_COLLECTION_ID); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + } + @Test public void testGetWfsTimeFieldWorks() { when(wfsServer.getFieldValues(anyString(), any(WfsServer.WfsFeatureRequest.class), any(ParameterizedTypeReference.class)))