Skip to content
Open
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 @@ -650,7 +650,40 @@ public SearchResult<FeatureGeoJSON> searchFeatureSummary(String collectionId, Li
for (var hit : response.hits().hits()) {
EsFeatureCollectionModel hitFeatureCollection = hit.source();
if (hitFeatureCollection != null && hitFeatureCollection.getFeatures() != null) {
features.addAll(hitFeatureCollection.toFeatureCollectionGeoJSON().getFeatures());
// A collectionID may map to several dataset key. So we need to identify features with dataset keys. TO get a dataset key which sits in hit.properties.key. For example:
// "properties": {
// "date": "2011-04",
// "collection": "4d3d4aca-472e-4616-88a5-df0f5ab401ba",
// "key": "mooring_acidification_realtime_qc.parquet"
// }
String datasetKey = null;
if (hitFeatureCollection.getProperties() != null) {
Object keyObj = hitFeatureCollection.getProperties().get("key");
if (keyObj != null) {
datasetKey = keyObj.toString();
}
}

List<FeatureGeoJSON> documentFeatures =
hitFeatureCollection.toFeatureCollectionGeoJSON().getFeatures();

for (FeatureGeoJSON feature : documentFeatures) {
// add key in property field for each feature
if (datasetKey != null) {
Object featurePropsObj = feature.getProperties();

if (featurePropsObj instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> featurePropsMap = (Map<String, Object>) featurePropsObj;
featurePropsMap.put("key", datasetKey);
} else {
Map<String, Object> newPropsMap = new HashMap<>();
newPropsMap.put("key", datasetKey);
feature.setProperties(newPropsMap);
}
}
features.add(feature);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*;

public class ElasticSearchTest {
Expand Down Expand Up @@ -61,10 +62,22 @@ public void searchFeatureSummaryTest() throws IOException {
featureCollectionProperties.put("key", "satellite_ghrsst_l4_gamssa_1day_multi_sensor_world.zarr");
esFeatureCollection.setProperties(featureCollectionProperties);
var coords = new ArrayList<List<List<BigDecimal>>>();
var esFeature = new EsFeatureModel();

// mock a single point [147.338884, -43.190779]
List<List<BigDecimal>> ring = new ArrayList<>();
List<BigDecimal> point = List.of(
new BigDecimal("147.338884"),
new BigDecimal("-43.190779")
);
ring.add(point);
coords.add(ring);

var polygon = new EsPolygonModel();
polygon.setCoordinates(coords);
var esFeature = new EsFeatureModel();

esFeature.setGeometry(polygon);

esFeatureCollection.setFeatures(List.of(esFeature));

when(hit.source()).thenReturn(esFeatureCollection);
Expand All @@ -88,7 +101,18 @@ public void searchFeatureSummaryTest() throws IOException {
assertNotNull(result);
assertEquals(1, result.getCollections().size());
assertEquals(1L, result.getTotal());
assertEquals(esFeature.toFeatureGeoJSON(), result.getCollections().get(0));
// validate geometry keeps same after adding key property
assertEquals(esFeature.toFeatureGeoJSON().getGeometry(),
result.getCollections().get(0).getGeometry());

// validate key is in properties
FeatureGeoJSON returnedFeature = result.getCollections().get(0);
@SuppressWarnings("unchecked")
Map<String, Object> featureProps = (Map<String, Object>) returnedFeature.getProperties();

assertTrue(featureProps.containsKey("key"));
assertEquals("satellite_ghrsst_l4_gamssa_1day_multi_sensor_world.zarr",
featureProps.get("key"));
}


Expand Down
Loading