From 97786f3d0ace2bdc49bec6a5e7f63cc35aeb50af Mon Sep 17 00:00:00 2001 From: Yuxuan HU Date: Wed, 29 Oct 2025 13:55:44 +1100 Subject: [PATCH 1/2] update AssetModel and getAssets --- .../ogcapi/server/core/mapper/Converter.java | 43 ++++++++++++++++--- .../core/model/StacCollectionModel.java | 2 +- .../core/mapper/StacToCollectionTest.java | 16 ++++--- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/mapper/Converter.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/mapper/Converter.java index c6096360..926382fd 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/mapper/Converter.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/mapper/Converter.java @@ -2,6 +2,7 @@ import au.org.aodn.ogcapi.features.model.*; import au.org.aodn.ogcapi.server.core.model.CitationModel; +import au.org.aodn.ogcapi.server.core.model.AssetModel; import au.org.aodn.ogcapi.server.core.model.ExtendedCollection; import au.org.aodn.ogcapi.server.core.model.ExtendedLink; import au.org.aodn.ogcapi.server.core.model.StacCollectionModel; @@ -10,7 +11,7 @@ import au.org.aodn.ogcapi.server.core.parser.stac.GeometryVisitor; import au.org.aodn.ogcapi.server.core.util.ConstructUtils; import au.org.aodn.ogcapi.server.core.util.GeometryUtils; -import au.org.aodn.ogcapi.server.core.util.LinkUtils; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -21,6 +22,7 @@ import org.springframework.http.MediaType; import java.util.ArrayList; +import java.util.List; import java.util.Map; import static au.org.aodn.ogcapi.server.core.util.GeometryUtils.createCentroid; @@ -125,12 +127,39 @@ default Collection getCollection(D m, Filter fil } if (m.getAssets() != null) { - m.getAssets().values().forEach(i -> collection.getLinks().add(new Link() - .title(i.getTitle()) - .href(host + "/api/v1/ogc" + i.getHref()) - .type(i.getType()) - .rel(i.getRole().toString().toLowerCase()) - )); + ObjectMapper objectMapper = new ObjectMapper(); + m.getAssets().values().forEach(value -> { + List assetList = new ArrayList<>(); + + // to handle summary list + if (value instanceof List) { + @SuppressWarnings("unchecked") + List list = (List) value; + list.forEach(item -> { + if (item instanceof AssetModel) { + assetList.add((AssetModel) item); + } else { + assetList.add(objectMapper.convertValue(item, AssetModel.class)); + } + }); + } + // to handle other asset + else if (value instanceof AssetModel) { + assetList.add((AssetModel) value); + } + else { + assetList.add(objectMapper.convertValue(value, AssetModel.class)); + } + + assetList.forEach(asset -> + collection.getLinks().add(new Link() + .title(asset.getTitle()) + .href(host + "/api/v1/ogc" + asset.getHref()) + .type(asset.getType()) + .rel(asset.getRole().toString().toLowerCase()) + ) + ); + }); } } diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/model/StacCollectionModel.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/StacCollectionModel.java index f69fb996..b5ce4144 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/model/StacCollectionModel.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/StacCollectionModel.java @@ -23,7 +23,7 @@ public class StacCollectionModel { protected List contacts; protected List themes; protected String license; - protected Map assets; + protected Map assets; @JsonProperty("sci:citation") protected String citation; diff --git a/server/src/test/java/au/org/aodn/ogcapi/server/core/mapper/StacToCollectionTest.java b/server/src/test/java/au/org/aodn/ogcapi/server/core/mapper/StacToCollectionTest.java index 26ec9290..29f234f6 100644 --- a/server/src/test/java/au/org/aodn/ogcapi/server/core/mapper/StacToCollectionTest.java +++ b/server/src/test/java/au/org/aodn/ogcapi/server/core/mapper/StacToCollectionTest.java @@ -19,10 +19,7 @@ import org.springframework.boot.test.context.SpringBootTest; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; import static au.org.aodn.ogcapi.server.BaseTestClass.readResourceFile; @@ -97,6 +94,14 @@ public void verifyAddingPropertyWorks() { ConceptModel.builder().id("id").url("url").description("description").title("title").build() )) .build(); + var asset = AssetModel.builder() + .role(AssetModel.Role.SUMMARY) + .href("/collections/test-uuid/items/summary") + .type("application/x-zarr") + .title("vessel_satellite_radiance_derived_product.zarr") + .build(); + Map assets = new HashMap<>(); + assets.put("summary", Arrays.asList(asset)); var citationString = "{\"suggestedCitation\":\"this is suggested Citation\",\"useLimitations\":[\"this is useLimitations1\",\"this is useLimitations2\"],\"otherConstraints\":[\"this is otherConstraints1\",\"this is otherConstraints2\"]}"; var statement = "This is the statement of this record"; var datasetGroup = "group_test"; @@ -119,6 +124,7 @@ public void verifyAddingPropertyWorks() { ) .license("Attribution 4.0") .contacts(Collections.singletonList(contact)) + .assets(assets) .links(Arrays.asList(link1, link2)) .themes(Collections.singletonList(theme)) .citation(citationString) @@ -142,7 +148,7 @@ public void verifyAddingPropertyWorks() { Assertions.assertEquals(datasetGroup, collection.getProperties().get(CollectionProperty.datasetGroup)); Assertions.assertEquals(aiDescription, collection.getProperties().get(CollectionProperty.aiDescription)); Assertions.assertNotNull(collection.getLinks()); - Assertions.assertEquals(2, collection.getLinks().size()); + Assertions.assertEquals(3, collection.getLinks().size()); } @Test From fc0f3dc3098bd8c2dcb40e7fb8967ef043b05379 Mon Sep 17 00:00:00 2001 From: Yuxuan HU Date: Wed, 29 Oct 2025 16:16:07 +1100 Subject: [PATCH 2/2] update test case for getAssets --- .../ogcapi/server/core/mapper/Converter.java | 41 +++---------------- .../core/model/StacCollectionModel.java | 2 +- .../core/mapper/StacToCollectionTest.java | 4 +- 3 files changed, 9 insertions(+), 38 deletions(-) diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/mapper/Converter.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/mapper/Converter.java index 926382fd..7cc89cc7 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/mapper/Converter.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/mapper/Converter.java @@ -11,7 +11,6 @@ import au.org.aodn.ogcapi.server.core.parser.stac.GeometryVisitor; import au.org.aodn.ogcapi.server.core.util.ConstructUtils; import au.org.aodn.ogcapi.server.core.util.GeometryUtils; -import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -22,7 +21,6 @@ import org.springframework.http.MediaType; import java.util.ArrayList; -import java.util.List; import java.util.Map; import static au.org.aodn.ogcapi.server.core.util.GeometryUtils.createCentroid; @@ -127,39 +125,12 @@ default Collection getCollection(D m, Filter fil } if (m.getAssets() != null) { - ObjectMapper objectMapper = new ObjectMapper(); - m.getAssets().values().forEach(value -> { - List assetList = new ArrayList<>(); - - // to handle summary list - if (value instanceof List) { - @SuppressWarnings("unchecked") - List list = (List) value; - list.forEach(item -> { - if (item instanceof AssetModel) { - assetList.add((AssetModel) item); - } else { - assetList.add(objectMapper.convertValue(item, AssetModel.class)); - } - }); - } - // to handle other asset - else if (value instanceof AssetModel) { - assetList.add((AssetModel) value); - } - else { - assetList.add(objectMapper.convertValue(value, AssetModel.class)); - } - - assetList.forEach(asset -> - collection.getLinks().add(new Link() - .title(asset.getTitle()) - .href(host + "/api/v1/ogc" + asset.getHref()) - .type(asset.getType()) - .rel(asset.getRole().toString().toLowerCase()) - ) - ); - }); + m.getAssets().values().forEach(i -> collection.getLinks().add(new Link() + .title(i.getTitle()) + .href(host + "/api/v1/ogc" + i.getHref()) + .type(i.getType()) + .rel(i.getRole().toString().toLowerCase()) + )); } } diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/model/StacCollectionModel.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/StacCollectionModel.java index b5ce4144..f69fb996 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/model/StacCollectionModel.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/StacCollectionModel.java @@ -23,7 +23,7 @@ public class StacCollectionModel { protected List contacts; protected List themes; protected String license; - protected Map assets; + protected Map assets; @JsonProperty("sci:citation") protected String citation; diff --git a/server/src/test/java/au/org/aodn/ogcapi/server/core/mapper/StacToCollectionTest.java b/server/src/test/java/au/org/aodn/ogcapi/server/core/mapper/StacToCollectionTest.java index 29f234f6..8251b319 100644 --- a/server/src/test/java/au/org/aodn/ogcapi/server/core/mapper/StacToCollectionTest.java +++ b/server/src/test/java/au/org/aodn/ogcapi/server/core/mapper/StacToCollectionTest.java @@ -100,8 +100,8 @@ public void verifyAddingPropertyWorks() { .type("application/x-zarr") .title("vessel_satellite_radiance_derived_product.zarr") .build(); - Map assets = new HashMap<>(); - assets.put("summary", Arrays.asList(asset)); + Map assets = new HashMap<>(); + assets.put("vessel_satellite_radiance_derived_product.zarr", asset); var citationString = "{\"suggestedCitation\":\"this is suggested Citation\",\"useLimitations\":[\"this is useLimitations1\",\"this is useLimitations2\"],\"otherConstraints\":[\"this is otherConstraints1\",\"this is otherConstraints2\"]}"; var statement = "This is the statement of this record"; var datasetGroup = "group_test";