diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/common/RestExtApi.java b/server/src/main/java/au/org/aodn/ogcapi/server/common/RestExtApi.java index 99f352c6..80028df6 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/common/RestExtApi.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/common/RestExtApi.java @@ -40,7 +40,7 @@ public class RestExtApi { * @throws java.lang.Exception */ @GetMapping(path="/autocomplete") - public ResponseEntity> getAutocompleteSuggestions( + public ResponseEntity> getAutocompleteSuggestions( @RequestParam String input, //categories is an optional parameter, if not provided, the method will return suggestions from all categories @Parameter(in = ParameterIn.QUERY, description = "Filter expression") 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 df5a3f71..0f596560 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 @@ -47,10 +47,10 @@ default au.org.aodn.ogcapi.tile.model.Link getTileSchema(String hostname) { } /** * Create a collection given stac model - * @param m - * @return + * @param m - Income object to be transformed + * @return A mapped JSON which match the St */ - default Collection getCollection(F m, String host) { + default Collection getCollection(D m, String host) { ExtendedCollection collection = new ExtendedCollection(); collection.setId(m.getUuid()); @@ -63,7 +63,9 @@ default Collection getCollection(F m, String hos if(m.getExtent() != null) { extent.setSpatial(new ExtentSpatial()); - if(m.getExtent().getBbox() != null && !m.getExtent().getBbox().isEmpty()) { + if(m.getExtent().getBbox() != null + && !m.getExtent().getBbox().isEmpty() + && m.getExtent().getBbox().size() > 1) { // The first item is the overall bbox, this is STAC spec requirement but not for // OGC collection, hence we remove the first item. extent.getSpatial().bbox(m.getExtent().getBbox().subList(1, m.getExtent().getBbox().size())); diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/service/CategorySuggestDTO.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/CategorySuggestDTO.java similarity index 87% rename from server/src/main/java/au/org/aodn/ogcapi/server/core/service/CategorySuggestDTO.java rename to server/src/main/java/au/org/aodn/ogcapi/server/core/model/CategorySuggestDTO.java index 0d5c0b4f..48a1a4cc 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/service/CategorySuggestDTO.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/CategorySuggestDTO.java @@ -1,4 +1,4 @@ -package au.org.aodn.ogcapi.server.core.service; +package au.org.aodn.ogcapi.server.core.model; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.AllArgsConstructor; diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/service/RecordSuggestDTO.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/RecordSuggestDTO.java similarity index 87% rename from server/src/main/java/au/org/aodn/ogcapi/server/core/service/RecordSuggestDTO.java rename to server/src/main/java/au/org/aodn/ogcapi/server/core/model/RecordSuggestDTO.java index 15c7ac49..e8fb7bc7 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/service/RecordSuggestDTO.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/model/RecordSuggestDTO.java @@ -1,4 +1,4 @@ -package au.org.aodn.ogcapi.server.core.service; +package au.org.aodn.ogcapi.server.core.model; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.AllArgsConstructor; 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 4e84fed1..ce138142 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 @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; import lombok.Data; +import lombok.Getter; import java.util.List; @@ -13,13 +14,15 @@ @Builder public class StacCollectionModel { - protected String title; protected String description; protected String type; protected ExtentModel extent; protected SummariesModel summaries; protected List links; + @Getter + protected String title; + @JsonProperty("id") protected String uuid; @@ -29,8 +32,4 @@ public class StacCollectionModel { @JsonProperty("stac_extensions") protected List stacExtensions; - public String getTitle() { - return title; - } - } diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/parser/ElasticFilter.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/parser/ElasticFilter.java index a1908091..b6168943 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/parser/ElasticFilter.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/parser/ElasticFilter.java @@ -2,6 +2,7 @@ import au.org.aodn.ogcapi.server.core.model.enumeration.CQLCrsType; import co.elastic.clients.elasticsearch._types.query_dsl.Query; +import lombok.Getter; import org.geotools.filter.LiteralExpressionImpl; import org.geotools.filter.text.cql2.CQLException; import org.geotools.geojson.geom.GeometryJSON; @@ -23,18 +24,18 @@ public abstract class ElasticFilter { - protected final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - protected Logger logger = LoggerFactory.getLogger(ElasticFilter.class); + @Getter + protected Query query; + @Getter protected List errors = new ArrayList<>(); - protected Query query; - public Query getQuery() { return query;} + protected final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + protected Logger logger = LoggerFactory.getLogger(ElasticFilter.class); public void addErrors(CQLException... e) { this.errors.addAll(List.of(e)); } public void addErrors(List e) { this.errors.addAll(e); } - public List getErrors() { return this.errors; } /** * Convert the WKT format from the cql to GeoJson use by Elastic search diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/service/ElasticSearch.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/service/ElasticSearch.java index d37e2a65..5f00b4c5 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/service/ElasticSearch.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/service/ElasticSearch.java @@ -1,5 +1,7 @@ package au.org.aodn.ogcapi.server.core.service; +import au.org.aodn.ogcapi.server.core.model.CategorySuggestDTO; +import au.org.aodn.ogcapi.server.core.model.RecordSuggestDTO; import au.org.aodn.ogcapi.server.core.model.StacCollectionModel; import au.org.aodn.ogcapi.server.core.model.enumeration.*; import au.org.aodn.ogcapi.server.core.parser.CQLToElasticFilterFactory; @@ -158,17 +160,6 @@ this query uses AND operator for the categories (e.g "wave" AND "temperature") filters = List.of(MatchAllQuery.of(q -> q)._toQuery()); } - /* - if want to use OR operator for the categories (e.g "wave" OR "temperature", use the following code - if (categories != null && !categories.isEmpty()) { - filters = List.of(TermsQuery.of(q -> q - .field(StacBasicField.DiscoveryCategories.searchField) - .terms(t -> t.value(categories.stream().map(category -> FieldValue.of(category.toLowerCase())).collect(Collectors.toList()))))._toQuery()); - } else { - filters = List.of(MatchAllQuery.of(q -> q)._toQuery()); - } - */; - // create request SearchRequest searchRequest = this.buildSearchAsYouTypeRequest(List.of("title"), indexName, List.of(searchAsYouTypeQuery), filters); @@ -197,7 +188,7 @@ protected List> getCategorySuggestions(String input) thr return response.hits().hits(); } - public ResponseEntity getAutocompleteSuggestions(String input, String cql, CQLCrsType coor) throws IOException, CQLException { + public ResponseEntity> getAutocompleteSuggestions(String input, String cql, CQLCrsType coor) throws IOException, CQLException { // extract category suggestions Set categorySuggestions = new HashSet<>(); for (Hit item : this.getCategorySuggestions(input)) { @@ -236,8 +227,6 @@ protected List searchCollectionBy(List queries, SearchRequest.Builder builder = new SearchRequest.Builder(); -// List categories = Arrays.asList(cql.split("=")[1].split(",")); - builder.index(indexName) .size(size) // Max hit to return .from(from) // Skip how many record @@ -255,6 +244,7 @@ protected List searchCollectionBy(List queries, List fs = properties .stream() .map(v -> CQLCollectionsField.valueOf(v).getDisplayField()) + .filter(Objects::nonNull) .collect(Collectors.toList()); // Set fetch to false so that it do not return the original document but just the field @@ -323,7 +313,7 @@ protected List searchCollectionsByIds(List ids, Boo List filters = null; if(ids != null && !ids.isEmpty()) { List values = ids.stream() - .map(id -> FieldValue.of(id)) + .map(FieldValue::of) .collect(Collectors.toList()); filters = List.of( @@ -398,8 +388,8 @@ public BinaryResponse searchCollectionVectorTile(List ids, Integer tileM builder.index(indexName) .field(StacSummeries.Geometry.searchField) .zoom(tileMatrix) - .x(tileRow.intValue()) - .y(tileCol.intValue()) + .x(tileRow) + .y(tileCol) // If true, the meta layer’s feature is a bounding box resulting from a geo_bounds aggregation. // The aggregation runs on values that intersect the // tile with wrap_longitude // set to false. The resulting bounding box may be larger than the vector tile. @@ -408,7 +398,7 @@ public BinaryResponse searchCollectionVectorTile(List ids, Integer tileM if(ids != null && !ids.isEmpty()) { List values = ids.stream() - .map(id -> FieldValue.of(id)) + .map(FieldValue::of) .collect(Collectors.toList()); List filters = List.of( @@ -419,10 +409,8 @@ public BinaryResponse searchCollectionVectorTile(List ids, Integer tileM builder.query(q -> q.bool(b -> b.filter(filters))); } - logger.debug("Final elastic search mvt payload {}", builder.toString()); - - BinaryResponse er = esClient.searchMvt(builder.build()); + logger.debug("Final elastic search mvt payload {}", builder); - return er; + return esClient.searchMvt(builder.build()); } } diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/service/Search.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/service/Search.java index 0efa6162..d2f188d5 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/service/Search.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/service/Search.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.util.List; +import java.util.Map; public interface Search { List searchCollectionWithGeometry(List ids) throws Exception; @@ -19,5 +20,5 @@ public interface Search { BinaryResponse searchCollectionVectorTile(List ids, Integer tileMatrix, Integer tileRow, Integer tileCol) throws IOException; - ResponseEntity> getAutocompleteSuggestions(String input, String cql, CQLCrsType coor) throws Exception; + ResponseEntity> getAutocompleteSuggestions(String input, String cql, CQLCrsType coor) throws Exception; }