Skip to content
Merged
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 @@ -9,6 +9,7 @@
import au.org.aodn.ogcapi.features.model.Exception;
import au.org.aodn.ogcapi.server.core.mapper.StacToCollections;
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLCrsType;
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFields;
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFilterType;
import au.org.aodn.ogcapi.server.core.model.enumeration.OGCMediaTypeMapper;
import au.org.aodn.ogcapi.server.core.service.OGCApiService;
Expand Down Expand Up @@ -154,7 +155,10 @@ public ResponseEntity<?> getCollections(
// TODO: Support other CRS.
if (CQLFilterType.convert(filterLang) == CQLFilterType.CQL && CQLCrsType.convertFromUrl(crs) == CQLCrsType.EPSG4326) {
if (datetime != null) {
filter = OGCApiService.processDatetimeParameter(datetime, filter);
filter = OGCApiService.processDatetimeParameter(CQLFields.temporal.name(), datetime, filter);
}
if (bbox != null) {
filter = OGCApiService.processBBoxParameter(CQLFields.geometry.name(), bbox, filter);
}
return commonService.getCollectionList(
q,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import au.org.aodn.ogcapi.features.model.Collection;
import au.org.aodn.ogcapi.features.model.Collections;
import au.org.aodn.ogcapi.server.core.model.ExtendedCollections;
import au.org.aodn.ogcapi.server.core.model.StacCollectionModel;
import au.org.aodn.ogcapi.server.core.service.ElasticSearch;
import org.mapstruct.Mapper;
import org.opengis.filter.Filter;
Expand All @@ -14,15 +15,15 @@

@Service
@Mapper(componentModel = "spring")
public abstract class StacToCollections implements Converter<ElasticSearch.SearchResult, Collections> {
public abstract class StacToCollections implements Converter<ElasticSearch.SearchResult<StacCollectionModel>, Collections> {

@Value("${api.host}")
protected String hostname;

@Override
public Collections convert(ElasticSearch.SearchResult model, Filter filter) {
public Collections convert(ElasticSearch.SearchResult<StacCollectionModel> model, Filter filter) {

List<Collection> collections = model.getCollections().parallelStream()
List<Collection> collections = model.getCollections().stream()
.map(m -> getCollection(m, filter, hostname))
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package au.org.aodn.ogcapi.server.core.mapper;

import au.org.aodn.ogcapi.features.model.FeatureCollectionGeoJSON;
import au.org.aodn.ogcapi.features.model.FeatureGeoJSON;
import au.org.aodn.ogcapi.features.model.PointGeoJSON;
import au.org.aodn.ogcapi.server.core.model.StacItemModel;
import au.org.aodn.ogcapi.server.core.service.ElasticSearch;
import org.mapstruct.Mapper;
import org.opengis.filter.Filter;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Service
@Mapper(componentModel = "spring")
public abstract class StacToFeatureCollection implements Converter<ElasticSearch.SearchResult<StacItemModel>, FeatureCollectionGeoJSON> {

@Override
public FeatureCollectionGeoJSON convert(ElasticSearch.SearchResult<StacItemModel> model, Filter filter) {
FeatureCollectionGeoJSON f = new FeatureCollectionGeoJSON();
f.setType(FeatureCollectionGeoJSON.TypeEnum.FEATURECOLLECTION);

List<FeatureGeoJSON> features = model.getCollections().stream()
.map(i -> {
FeatureGeoJSON feature = new FeatureGeoJSON();
feature.setType(FeatureGeoJSON.TypeEnum.FEATURE);

if(i.getGeometry().get("geometry") instanceof Map<?, ?> map) {
if(map.get("coordinates") instanceof List<?> coords) {
List<BigDecimal> c = coords.stream()
.filter(item -> item instanceof BigDecimal)
.map(item -> (BigDecimal)item)
.toList();

feature.setGeometry(new PointGeoJSON().coordinates(c));
}
}
feature.setProperties(i.getProperties());

return feature;
})
.filter(i -> i.getGeometry() != null)
.toList();

f.setFeatures(features);
return f;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package au.org.aodn.ogcapi.server.core.mapper;

import au.org.aodn.ogcapi.server.core.model.StacCollectionModel;
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLCrsType;
import au.org.aodn.ogcapi.server.core.service.ElasticSearch;
import au.org.aodn.ogcapi.tile.model.InlineResponse2002;
Expand All @@ -14,13 +15,13 @@

@Service
@Mapper(componentModel = "spring")
public abstract class StacToInlineResponse2002 implements Converter<ElasticSearch.SearchResult, InlineResponse2002> {
public abstract class StacToInlineResponse2002 implements Converter<ElasticSearch.SearchResult<StacCollectionModel>, InlineResponse2002> {

@Value("${api.host}")
protected String hostname;

@Override
public InlineResponse2002 convert(ElasticSearch.SearchResult model, Filter noUse) {
public InlineResponse2002 convert(ElasticSearch.SearchResult<StacCollectionModel> model, Filter noUse) {
List<TileSetItem> items = model.getCollections().stream()
.map(m -> {
TileSetItem item = new TileSetItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Service
@Mapper(componentModel = "spring")
public abstract class StacToTileSetWmWGS84Q implements Converter<ElasticSearch.SearchResult, TileSet> {
public abstract class StacToTileSetWmWGS84Q implements Converter<ElasticSearch.SearchResult<StacCollectionModel>, TileSet> {

@Value("${api.host}")
protected String hostname;
Expand All @@ -27,7 +27,7 @@ protected static class TileSetWorldMercatorWGS84Quad extends TileSet {
}

@Override
public TileSet convert(ElasticSearch.SearchResult from, Filter noUse) {
public TileSet convert(ElasticSearch.SearchResult<StacCollectionModel> from, Filter noUse) {
TileSetWorldMercatorWGS84Quad tileSet = new TileSetWorldMercatorWGS84Quad();

tileSet.setTileMatrixSetURI("http://www.opengis.net/def/tilematrixset/OGC/1.0/WorldMercatorWGS84Quad");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package au.org.aodn.ogcapi.server.core.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AssetModel {
// https://github.com/radiantearth/stac-spec/blob/master/best-practices.md#list-of-asset-roles
public enum Role {
DATA("data"),
METADATA("metadata"),
THUMBNAIL("thumbnail"),
OVERVIEW("overview"),
VISUAL("visual"),
DATE("date"),
GRAPHIC("graphic"),
DATA_MASK("data-mask"),
SNOW_ICE("snow-ice"),
LAND_WATER("land-water"),
WATER_MASK("water-mask"),
ISO_19115("iso-19115");

private final String role;

Role(String role) {
this.role = role;
}

@Override
public String toString() {
return role;
}
}
/**
* REQUIRED. URI to the asset object. Relative and absolute URI are both allowed. Trailing slashes are significant.
*/
protected String href;
protected String title;
protected String description;
protected String type;
/**
* The semantic roles of the asset, similar to the use of rel in links.
*/
protected Role role;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DatasetSearchResult {
import static au.org.aodn.ogcapi.server.core.util.CommonUtils.safeGet;

public class DataSearchResult {

private final FeatureCollectionGeoJSON dataset;

public DatasetSearchResult() {
public DataSearchResult() {
this.dataset = new FeatureCollectionGeoJSON();
initDataset();
}
Expand All @@ -31,31 +34,48 @@ public FeatureCollectionGeoJSON getSummarizedDataset() {
return summarizer.getSummarizedDataset();
}

public void addDatum(DatumModel datum) {
public void addDatum(StacItemModel datum) {

if (datum == null) {
throw new IllegalArgumentException("Datum cannot be null");
}

var feature = new FeatureGeoJSON();
FeatureGeoJSON feature = new FeatureGeoJSON();
feature.setType(FeatureGeoJSON.TypeEnum.FEATURE);

var geometry = new PointGeoJSON();
geometry.setType(PointGeoJSON.TypeEnum.POINT);
var coordinates = new ArrayList<BigDecimal>();

List<BigDecimal> coordinates = new ArrayList<>();

// Don't use null checks here because it is a list and even if it is null,
// it still needs "null" to occupy the space
coordinates.add(datum.getLongitude());
coordinates.add(datum.getLatitude());
safeGet(() -> ((Map<?,?>)datum.getGeometry().get("geometry")).get("coordinates"))
.filter(item -> item instanceof List)
.map(item -> (List<?>)item)
.ifPresent(item -> {
if(item.size() == 2) {
coordinates.add(new BigDecimal(item.get(0).toString()));
coordinates.add(new BigDecimal(item.get(1).toString()));
}
});


geometry.setCoordinates(coordinates);
feature.setGeometry(geometry);

// Please add more properties if needed
Map<String, Object> properties = new HashMap<>();
properties.put(FeatureProperty.TIME.getValue(), datum.getTime());
properties.put(FeatureProperty.DEPTH.getValue(), datum.getDepth());
properties.put(FeatureProperty.COUNT.getValue(), datum.getCount());

safeGet(() -> ((Map<?,?>)datum.getGeometry().get("properties")).get("depth"))
.ifPresent(val -> properties.put(FeatureProperty.DEPTH.getValue(), val));

safeGet(() -> (datum.getProperties().get("time")))
.ifPresent(val -> properties.put(FeatureProperty.TIME.getValue(), val));

safeGet(() -> (datum.getProperties().get("count")))
.ifPresent(val -> properties.put(FeatureProperty.COUNT.getValue(), val));


feature.setProperties(properties);
dataset.getFeatures().add(feature);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package au.org.aodn.ogcapi.server.core.model;

import au.org.aodn.ogcapi.features.model.FeatureCollectionGeoJSON;
import au.org.aodn.ogcapi.features.model.FeatureGeoJSON;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StacItemModel {

@JsonProperty("type")
protected String type;
/**
* REQUIRED. Provider identifier. The ID should be unique within the Collection that contains the Item.
*/
@JsonProperty("id")
protected String uuid;
/**
* REQUIRED. Defines the full footprint of the asset represented by this item, formatted according to RFC 7946,
* section 3.1 if a geometry is provided or section 3.2 if no geometry is provided.
* Use to generate the vector tile, the STAC format is not optimized and hard to work with for Elastic search
*/
@JsonProperty("geometry")
protected Map<?,?> geometry;
/**
* REQUIRED if geometry is not null, prohibited if geometry is null. Bounding Box of the asset represented by
* this Item, formatted according to RFC 7946, section 5.
*/
@JsonProperty("bbox")
protected List<List<BigDecimal>> bbox;
/**
* REQUIRED. A dictionary of additional metadata for the Item.
*/
@JsonProperty("properties")
protected Map<?, ?> properties;
/**
* REQUIRED. List of link objects to resources and related URLs. See the best practices for details on when the
* use self links is strongly recommended.
*/
protected List<LinkModel> links;

protected Map<String, AssetModel> assets;
/**
* The id of the STAC Collection this Item references to. This field is required if a link with a collection relation type is present and is not allowed otherwise.
*/
@JsonProperty("collection")
protected String collection;

@JsonProperty("stac_version")
protected String stacVersion;

@JsonProperty("stac_extensions")
public String[] getStacExtension() {
return new String[] {
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
"https://stac-extensions.github.io/contacts/v0.1.1/schema.json",
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"https://stac-extensions.github.io/language/v1.0.0/schema.json",
"https://stac-extensions.github.io/themes/v1.0.0/schema.json",
"https://stac-extensions.github.io/web-map-links/v1.2.0/schema.json"
};
}

}
Loading
Loading