Skip to content

Commit

Permalink
Refactor and fix to reduce IDE warning
Browse files Browse the repository at this point in the history
  • Loading branch information
utas-raymondng committed Jun 4, 2024
1 parent 8e3e345 commit dfd4a4f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class RestExtApi {
* @throws java.lang.Exception
*/
@GetMapping(path="/autocomplete")
public ResponseEntity<List<String>> getAutocompleteSuggestions(
public ResponseEntity<Map<String, ?>> 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <F extends StacCollectionModel> Collection getCollection(F m, String host) {
default <D extends StacCollectionModel> Collection getCollection(D m, String host) {

ExtendedCollection collection = new ExtendedCollection();
collection.setId(m.getUuid());
Expand All @@ -63,7 +63,9 @@ default <F extends StacCollectionModel> 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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;

import java.util.List;

Expand All @@ -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<LinkModel> links;

@Getter
protected String title;

@JsonProperty("id")
protected String uuid;

Expand All @@ -29,8 +32,4 @@ public class StacCollectionModel {
@JsonProperty("stac_extensions")
protected List<String> stacExtensions;

public String getTitle() {
return title;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CQLException> 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<CQLException> e) { this.errors.addAll(e); }
public List<CQLException> getErrors() { return this.errors; }

/**
* Convert the WKT format from the cql to GeoJson use by Elastic search
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -197,7 +188,7 @@ protected List<Hit<CategorySuggestDTO>> getCategorySuggestions(String input) thr
return response.hits().hits();
}

public ResponseEntity getAutocompleteSuggestions(String input, String cql, CQLCrsType coor) throws IOException, CQLException {
public ResponseEntity<Map<String, ?>> getAutocompleteSuggestions(String input, String cql, CQLCrsType coor) throws IOException, CQLException {
// extract category suggestions
Set<String> categorySuggestions = new HashSet<>();
for (Hit<CategorySuggestDTO> item : this.getCategorySuggestions(input)) {
Expand Down Expand Up @@ -236,8 +227,6 @@ protected List<StacCollectionModel> searchCollectionBy(List<Query> queries,

SearchRequest.Builder builder = new SearchRequest.Builder();

// List<String> categories = Arrays.asList(cql.split("=")[1].split(","));

builder.index(indexName)
.size(size) // Max hit to return
.from(from) // Skip how many record
Expand All @@ -255,6 +244,7 @@ protected List<StacCollectionModel> searchCollectionBy(List<Query> queries,
List<String> 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
Expand Down Expand Up @@ -323,7 +313,7 @@ protected List<StacCollectionModel> searchCollectionsByIds(List<String> ids, Boo
List<Query> filters = null;
if(ids != null && !ids.isEmpty()) {
List<FieldValue> values = ids.stream()
.map(id -> FieldValue.of(id))
.map(FieldValue::of)
.collect(Collectors.toList());

filters = List.of(
Expand Down Expand Up @@ -398,8 +388,8 @@ public BinaryResponse searchCollectionVectorTile(List<String> 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 <field> values that intersect the <zoom>/<x>/<y> tile with wrap_longitude
// set to false. The resulting bounding box may be larger than the vector tile.
Expand All @@ -408,7 +398,7 @@ public BinaryResponse searchCollectionVectorTile(List<String> ids, Integer tileM

if(ids != null && !ids.isEmpty()) {
List<FieldValue> values = ids.stream()
.map(id -> FieldValue.of(id))
.map(FieldValue::of)
.collect(Collectors.toList());

List<Query> filters = List.of(
Expand All @@ -419,10 +409,8 @@ public BinaryResponse searchCollectionVectorTile(List<String> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Map;

public interface Search {
List<StacCollectionModel> searchCollectionWithGeometry(List<String> ids) throws Exception;
Expand All @@ -19,5 +20,5 @@ public interface Search {

BinaryResponse searchCollectionVectorTile(List<String> ids, Integer tileMatrix, Integer tileRow, Integer tileCol) throws IOException;

ResponseEntity<List<String>> getAutocompleteSuggestions(String input, String cql, CQLCrsType coor) throws Exception;
ResponseEntity<Map<String, ?>> getAutocompleteSuggestions(String input, String cql, CQLCrsType coor) throws Exception;
}

0 comments on commit dfd4a4f

Please sign in to comment.