From 3e4d35228160a21c441c92a479ff9b14ae1c08af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Rodr=C3=ADguez?= <36035218+grojeda@users.noreply.github.com> Date: Thu, 29 Oct 2026 14:03:00 +1100 Subject: [PATCH] feat: expose optional latest glider mission images --- docs/GLIDERS_MISSION_CATALOGUE.md | 37 +++++++++++++++++-- .../model/gliders/GliderMission.java | 11 +++++- .../service/GlidersCatalogueService.java | 8 ++++ .../GlidersMissionControllerTest.java | 37 +++++++++++++++++++ .../service/GlidersCatalogueServiceTest.java | 5 ++- 5 files changed, 92 insertions(+), 6 deletions(-) diff --git a/docs/GLIDERS_MISSION_CATALOGUE.md b/docs/GLIDERS_MISSION_CATALOGUE.md index 4d2e577..9c52390 100644 --- a/docs/GLIDERS_MISSION_CATALOGUE.md +++ b/docs/GLIDERS_MISSION_CATALOGUE.md @@ -3,10 +3,10 @@ The API reads the version 1 catalogue produced by [aodn/data-services PR #1276](https://github.com/aodn/data-services/pull/1276). It uses `REMOTE_BASE_URL` + `REMOTE_RESOURCE_PATH` + -`gliders/gliders-catalogue.json`. The caller cannot override the source URL. +`api/gliders-catalogue.json`. The caller cannot override the source URL. This catalogue is independent of image inventories and Elasticsearch. -Merging the upstream generator does not run or schedule it: an upstream operator -must generate and publish the JSON before the API can serve catalogue data. +The generator uses the existing publication pipeline and schedule. This extension +does not introduce another endpoint or scheduler. ## Endpoints and parameters @@ -52,7 +52,12 @@ Illustrative response (fixture data, not a statement of current availability): "glider_id": "Slocum-1", "visualisations": { "details": [{"label": "4", "url": "https://oceancurrent.aodn.org.au/gliders/TwoRocks20260327/4.html"}], - "animations": [] + "animations": [], + "latest_images": { + "4d": "/gliders/TwoRocks20260327_4d/2026041300.gif", + "12d": null, + "30d": null + } }, "temperature_salinity_url": null, "scientific_data_url": null @@ -145,3 +150,27 @@ Local isolated checks: The fixture in `src/test/resources/gliders/catalogue-v1.json` follows the merged generator's schema and includes multiple versions, NRT, null optional values and orders with different membership. These tests require no Elasticsearch or Docker. + +## Latest image rollout and resource contract + +Deploy API optional-field support first, then the updated catalogue generator. +The catalogue stays at schema version 1. Older catalogues without +`visualisations.latest_images`, and windows with absent/null URLs, remain valid; +both existing endpoints serialize all three keys with null defaults. Missing +images alone never cause HTTP 503. The API does not probe GIF resources. + +Non-null values are website-root-relative resource paths. A browser prepends +`/resource`, for example `/resource/gliders/TwoRocks20260327_4d/2026041300.gif`. +The catalogue generator only exposes the displayed GIF verified in the linked +mission-window's legacy page, not a guessed most-recent filename. + +After deployment, wait for publication and the configured API cache refresh, +compare `latest_images` on `/api/v1/gliders/missions` and an exact ID lookup with +`/resource/api/gliders-catalogue.json`, then GET each non-null path through +`/resource` and confirm HTTP 200 with GIF content. Include missions with missing +windows and NRT records. Do this through the normal deployment process; this +implementation does not deploy automatically. + +NRT freshness depends on the upstream legacy frame selection and file transfer, +the unchanged publication schedule, API refresh and HTTP caches. A latest frame +may be old; no recency guarantee, image-date inference or new polling is added. diff --git a/src/main/java/au/org/aodn/oceancurrent/model/gliders/GliderMission.java b/src/main/java/au/org/aodn/oceancurrent/model/gliders/GliderMission.java index 6d252e8..58f3b43 100644 --- a/src/main/java/au/org/aodn/oceancurrent/model/gliders/GliderMission.java +++ b/src/main/java/au/org/aodn/oceancurrent/model/gliders/GliderMission.java @@ -1,5 +1,6 @@ package au.org.aodn.oceancurrent.model.gliders; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; @@ -12,6 +13,14 @@ public record GliderMission( Double latitude, Double longitude, Double durationDays, Double distanceTravelledKm, String gliderId, Visualisations visualisations, String temperatureSalinityUrl, String scientificDataUrl) { - public record Visualisations(List details, List animations) {} + @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) + public record Visualisations(List details, List animations, LatestImages latestImages) { + public Visualisations { + if (latestImages == null) latestImages = new LatestImages(null, null, null); + } + } + public record LatestImages(@JsonProperty("4d") String fourDay, + @JsonProperty("12d") String twelveDay, + @JsonProperty("30d") String thirtyDay) {} public record Link(String label, String url) {} } diff --git a/src/main/java/au/org/aodn/oceancurrent/service/GlidersCatalogueService.java b/src/main/java/au/org/aodn/oceancurrent/service/GlidersCatalogueService.java index c235ebc..8b8b14f 100644 --- a/src/main/java/au/org/aodn/oceancurrent/service/GlidersCatalogueService.java +++ b/src/main/java/au/org/aodn/oceancurrent/service/GlidersCatalogueService.java @@ -144,6 +144,14 @@ private void validateMission(JsonNode node) { require(node.has(field) && (node.get(field).isNull() || node.get(field).isNumber()), "Invalid mission " + field); } + JsonNode latest = node.path("visualisations").path("latest_images"); + require(latest.isMissingNode() || latest.isNull() || latest.isObject(), "Invalid latest_images"); + if (latest.isObject()) { + for (String window : List.of("4d", "12d", "30d")) { + JsonNode image = latest.path(window); + require(image.isMissingNode() || image.isNull() || text(image), "Invalid latest image"); + } + } for (String kind : List.of("details", "animations")) { JsonNode links = node.path("visualisations").path(kind); require(links.isArray(), "Missing visualisations " + kind); diff --git a/src/test/java/au/org/aodn/oceancurrent/controller/GlidersMissionControllerTest.java b/src/test/java/au/org/aodn/oceancurrent/controller/GlidersMissionControllerTest.java index 14756a2..5740690 100644 --- a/src/test/java/au/org/aodn/oceancurrent/controller/GlidersMissionControllerTest.java +++ b/src/test/java/au/org/aodn/oceancurrent/controller/GlidersMissionControllerTest.java @@ -51,6 +51,43 @@ void defaultsAndResponseContract() throws Exception { .andExpect(jsonPath("$.missions[0].is_nrt").value(false)); } + @ParameterizedTest + @ValueSource(strings = {"old", "new", "missing", "partial"}) + void serializesLatestImagesOnBothEndpoints(String format) throws Exception { + var mapper = new ObjectMapper(); + var root = mapper.readTree(new ClassPathResource("gliders/catalogue-v1.json") + .getContentAsString(java.nio.charset.StandardCharsets.UTF_8)); + for (var mission : root.path("missions")) { + if (!format.equals("old")) { + var latest = ((com.fasterxml.jackson.databind.node.ObjectNode) mission.path("visualisations")) + .putObject("latest_images"); + if (format.equals("new")) { + latest.put("4d", "/gliders/TwoRocks20260327_4d/2026041300.gif"); + } else { + latest.putNull("4d"); + } + if (!format.equals("partial")) { + latest.putNull("12d"); + latest.putNull("30d"); + } + } + } + when(remote.getForEntity(URL, String.class)).thenReturn(ResponseEntity.ok(root.toString())); + for (String endpoint : new String[]{"/gliders/missions", "/gliders/missions/TwoRocks20260327@5.00"}) { + String path = endpoint.endsWith("missions") ? "$.missions[0]" : "$"; + var result = mvc.perform(get(endpoint)).andExpect(status().isOk()) + .andExpect(jsonPath(path + ".visualisations.latest_images").isMap()) + .andExpect(jsonPath(path + ".visualisations.latest_images['12d']").value(org.hamcrest.Matchers.nullValue())) + .andExpect(jsonPath(path + ".visualisations.latest_images['30d']").value(org.hamcrest.Matchers.nullValue())); + if (format.equals("new")) { + result.andExpect(jsonPath(path + ".visualisations.latest_images['4d']") + .value("/gliders/TwoRocks20260327_4d/2026041300.gif")); + } else { + result.andExpect(jsonPath(path + ".visualisations.latest_images['4d']").value(org.hamcrest.Matchers.nullValue())); + } + } + } + @Test void filtersOrdersAndPages() throws Exception { mvc.perform(get("/gliders/missions").param("order", "mission_name") diff --git a/src/test/java/au/org/aodn/oceancurrent/service/GlidersCatalogueServiceTest.java b/src/test/java/au/org/aodn/oceancurrent/service/GlidersCatalogueServiceTest.java index 273ff48..77ee71b 100644 --- a/src/test/java/au/org/aodn/oceancurrent/service/GlidersCatalogueServiceTest.java +++ b/src/test/java/au/org/aodn/oceancurrent/service/GlidersCatalogueServiceTest.java @@ -99,7 +99,7 @@ void filtersBeforePaginationAndHandlesEmptyAndDistantPages() { } @ParameterizedTest - @ValueSource(strings = {"version", "overflow-version", "missing-missions", "missing-orders", "bad-order", "unknown-reference", "duplicate-reference", "missing-id", "duplicate-id", "unstable-id", "numeric-version", "bad-visualisations", "missing-nrt"}) + @ValueSource(strings = {"version", "overflow-version", "missing-missions", "missing-orders", "bad-order", "unknown-reference", "duplicate-reference", "missing-id", "duplicate-id", "unstable-id", "numeric-version", "bad-visualisations", "missing-nrt", "bad-latest", "bad-image"}) void rejectsInvalidSchema(String problem) throws Exception { ObjectNode root = (ObjectNode) mapper.readTree(json); ObjectNode mission = (ObjectNode) root.path("missions").get(0); @@ -117,6 +117,9 @@ void rejectsInvalidSchema(String problem) throws Exception { case "numeric-version" -> mission.put("processing_version", 3.0); case "bad-visualisations" -> mission.remove("visualisations"); case "missing-nrt" -> mission.remove("is_nrt"); + case "bad-latest" -> ((ObjectNode) mission.path("visualisations")).put("latest_images", "wrong"); + case "bad-image" -> ((ObjectNode) mission.path("visualisations")) + .putObject("latest_images").put("4d", 123); } respond(root.toString()); assertThatThrownBy(() -> service.mission(ID)).isInstanceOf(GlidersCatalogueUnavailableException.class);