Skip to content

Commit

Permalink
Merge pull request #92 from aodn/features/6008-remove-centroid-with-cal
Browse files Browse the repository at this point in the history
Features/6008 remove centroid with cal
  • Loading branch information
HavierD authored Nov 14, 2024
2 parents 0b4cf55 + 2aef8c1 commit a267991
Show file tree
Hide file tree
Showing 53 changed files with 19,011 additions and 111 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package au.org.aodn.ogcapi.server.configuration;
package au.org.aodn.ogcapi.server.core.configuration;

import io.swagger.v3.oas.annotations.Hidden;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package au.org.aodn.ogcapi.server.configuration;
package au.org.aodn.ogcapi.server.core.configuration;

import au.org.aodn.ogcapi.tile.model.TileMatrixSets;
import org.springframework.format.FormatterRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public RestClientTransport restClientTransport() {
// Create the low-level client
RestClient restClient = RestClient
.builder(HttpHost.create(serverUrl))
.setCompressionEnabled(true)
.setDefaultHeaders(new Header[]{
new BasicHeader("Authorization", "ApiKey " + apiKey)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class BinaryResponseToBytes implements Converter<BinaryResponse,
protected Logger logger = LoggerFactory.getLogger(BinaryResponseToBytes.class);

@Override
public byte[] convert(BinaryResponse from) {
public byte[] convert(BinaryResponse from, Param noUse) {
logger.debug("Incoming BinaryResponse type is {}", from.contentType());

try (InputStream s = from.content()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,48 @@
import au.org.aodn.ogcapi.server.core.model.CitationModel;
import au.org.aodn.ogcapi.server.core.model.ExtendedCollection;
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.model.enumeration.CollectionProperty;
import au.org.aodn.ogcapi.server.core.parser.stac.CQLToStacFilterFactory;
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 lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.geotools.filter.text.commons.CompilerUtil;
import org.geotools.filter.text.commons.Language;
import org.geotools.filter.text.cql2.CQLException;
import org.geotools.geojson.geom.GeometryJSON;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryCollection;
import org.opengis.filter.Filter;
import org.opengis.filter.expression.Expression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;

import java.lang.Exception;
import java.util.stream.Collectors;

import static au.org.aodn.ogcapi.server.core.util.GeometryUtils.createCentroid;

@FunctionalInterface
public interface Converter<F, T> {

Logger logger = LoggerFactory.getLogger(Converter.class);
GeometryVisitor visitor = GeometryVisitor.builder()
.build();

@Builder
@Getter
@Setter
class Param {
CQLCrsType coordinationSystem;
String filter;
}

T convert(F from);
T convert(F from, Param param);

default au.org.aodn.ogcapi.features.model.Link getSelfCollectionLink(String hostname, String id) {
au.org.aodn.ogcapi.features.model.Link self = new au.org.aodn.ogcapi.features.model.Link();
Expand Down Expand Up @@ -52,7 +80,7 @@ default au.org.aodn.ogcapi.tile.model.Link getTileSchema(String hostname) {
* @param m - Income object to be transformed
* @return A mapped JSON which match the St
*/
default <D extends StacCollectionModel> Collection getCollection(D m, String host) {
default <D extends StacCollectionModel> Collection getCollection(D m, Filter filter, String host) {

ExtendedCollection collection = new ExtendedCollection();
collection.setId(m.getUuid());
Expand Down Expand Up @@ -113,8 +141,15 @@ default <D extends StacCollectionModel> Collection getCollection(D m, String hos
}

if(m.getSummaries() != null ) {
if (m.getSummaries().getCentroid() != null) {
collection.getProperties().put(CollectionProperty.centroid, m.getSummaries().getCentroid());
if (m.getSummaries().getGeometryNoLand() != null) {
GeometryUtils.readGeometry(m.getSummaries().getGeometryNoLand())
.ifPresent(input -> {
Geometry g = filter != null ? (Geometry)filter.accept(visitor, input) : input;
collection.getProperties().put(
CollectionProperty.centroid,
createCentroid(g)
);
});
}

if (m.getSummaries().getStatus() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@Mapper(componentModel = "spring")
public abstract class StacToCollection implements Converter<StacCollectionModel, Collection> {
Expand All @@ -14,7 +16,7 @@ public abstract class StacToCollection implements Converter<StacCollectionModel,
protected String hostname;

@Override
public Collection convert(StacCollectionModel model) {
return getCollection(model, hostname);
public Collection convert(StacCollectionModel model, Param param) {
return getCollection(model, null, hostname);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
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.parser.stac.CQLToStacFilterFactory;
import au.org.aodn.ogcapi.server.core.service.ElasticSearch;
import org.geotools.filter.text.commons.CompilerUtil;
import org.geotools.filter.text.commons.Language;
import org.mapstruct.Mapper;
import org.opengis.filter.Filter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

Expand All @@ -19,13 +23,27 @@ public abstract class StacToCollections implements Converter<ElasticSearch.Searc
protected String hostname;

@Override
public Collections convert(ElasticSearch.SearchResult model) {
List<Collection> collections = model.getCollections().stream()
.map(m -> getCollection(m, hostname))
public Collections convert(ElasticSearch.SearchResult model, Param param) {
CQLToStacFilterFactory factory = CQLToStacFilterFactory.builder()
.cqlCrsType(param.getCoordinationSystem())
.build();

Filter f = null;
try {
f = param.getFilter() != null ? CompilerUtil.parseFilter(Language.CQL, param.getFilter(), factory) : null;
}
catch(Exception ex) {
// Do nothing
}
final Filter filter = f;

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

ExtendedCollections result = new ExtendedCollections();
result.setTotal(model.getTotal());

if(model.getSortValues() != null) {
result.setSearchAfter(model.getSortValues().stream().map(String::valueOf).toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class StacToInlineResponse2002 implements Converter<ElasticSearc
protected String hostname;

@Override
public InlineResponse2002 convert(ElasticSearch.SearchResult model) {
public InlineResponse2002 convert(ElasticSearch.SearchResult model, Param 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 @@ -28,7 +28,7 @@ protected class TileSetWorldMercatorWGS84Quad extends TileSet {
}

@Override
public TileSet convert(ElasticSearch.SearchResult from) {
public TileSet convert(ElasticSearch.SearchResult from, Param 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
@@ -1,16 +1,15 @@
package au.org.aodn.ogcapi.server.core.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ConceptModel {
protected String id;
protected String url;

public ConceptModel(String id, String url) {
this.id = id;
this.url = url;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package au.org.aodn.ogcapi.server.core.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ContactModel {

// Not include all fields according to this: https://github.com/stac-extensions/contacts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package au.org.aodn.ogcapi.server.core.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class LinkModel {
protected String rel;
protected String href;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package au.org.aodn.ogcapi.server.core.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.*;

import java.util.List;

Expand All @@ -12,6 +10,8 @@
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StacCollectionModel {

protected String description;
Expand All @@ -22,6 +22,7 @@ public class StacCollectionModel {
protected List<ContactModel> contacts;
protected List<ThemeModel> themes;
protected String license;

@JsonProperty("sci:citation")
protected String citation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

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 org.locationtech.jts.geom.GeometryCollection;

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

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SummariesModel {
// Do not create constructor, it will create by lombook, you can use builder() to create object.
Expand All @@ -19,11 +24,13 @@ public class SummariesModel {
protected List<String> credits;
protected String creation;
protected String revision;
protected List<List<BigDecimal>> centroid;

@JsonProperty("proj:geometry")
protected Map<?,?> geometry;

@JsonProperty("proj:geometry_noland")
protected Map<?,?> geometryNoLand;

@JsonProperty("temporal")
protected List<Map<String, String>> temporal;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package au.org.aodn.ogcapi.server.core.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ThemeModel {
protected String scheme;
protected String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public enum CQLFields implements CQLFieldsInterface {
null
),
centroid(
StacSummeries.Centroid.searchField,
StacSummeries.Centroid.displayField,
StacSummeries.GeometryNoLand.searchField,
StacSummeries.GeometryNoLand.displayField,
null,
null
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.util.List;

public enum StacSummeries {
Centroid("summaries.centroid","summaries.centroid"),
Score("summaries.score", "summaries.score", "summaries.score", null),
Geometry("summaries.proj:geometry","extent.bbox"),
GeometryNoLand("summaries.proj:geometry_noland","summaries.proj:geometry_noland"),
TemporalStart("summaries.temporal.start", ""),
TemporalEnd("summaries.temporal.end", ""),
Temporal("summaries.temporal", "extent.temporal", "summaries.temporal", List.of(TemporalStart, TemporalEnd)),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package au.org.aodn.ogcapi.server.core.parser;
package au.org.aodn.ogcapi.server.core.parser.elastic;

import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFields;
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFieldsInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package au.org.aodn.ogcapi.server.core.parser;
package au.org.aodn.ogcapi.server.core.parser.elastic;

import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package au.org.aodn.ogcapi.server.core.parser;
package au.org.aodn.ogcapi.server.core.parser.elastic;

import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFields;
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFieldsInterface;
Expand Down
Loading

0 comments on commit a267991

Please sign in to comment.