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 @@ -146,7 +146,12 @@ public FunctionName functionName(Name name, List<Parameter<?>> list, Parameter<?

@Override
public Id id(FeatureId... featureIds) {
return null;
return id(new HashSet<>(Arrays.asList(featureIds)));
}

@Override
public Id id(Set<? extends Identifier> set) {
return new IdImpl<>(set, collectionFieldType);
}

@Override
Expand Down Expand Up @@ -227,12 +232,6 @@ public Not not(Filter filter) {
}
}

@Override
public Id id(Set<? extends Identifier> set) {
logger.debug("id {}", set);
return null;
}

@Override
public PropertyIsBetween between(Expression expression, Expression expression1, Expression expression2) {
logger.debug("BETWEEN {} {}, {}", expression, expression1, expression2);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package au.org.aodn.ogcapi.server.core.parser.elastic;

import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFieldsInterface;
import au.org.aodn.ogcapi.server.core.model.enumeration.StacBasicField;
import co.elastic.clients.elasticsearch._types.FieldValue;
import co.elastic.clients.elasticsearch._types.query_dsl.TermsQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.TermsQueryField;
import org.opengis.filter.FilterVisitor;
import org.opengis.filter.Id;
import org.opengis.filter.identity.Identifier;

import java.util.HashSet;
import java.util.Set;

/**
* ECQL parser id different, you need to pass in ID IN (id1, id2, id3), then this class will trigger to create a
* TermsQuery for id. Other fields are fine with k=v
* @param <T>
*/
public class IdImpl<T extends Enum<T> & CQLFieldsInterface> extends QueryHandler implements Id {

protected Set<Identifier> identifiers = new HashSet<>();

public IdImpl(Set<? extends Identifier> identifiers, Class<T> enumType) {
this.identifiers.addAll(identifiers);
this.query = TermsQuery.of(t -> t
.field(StacBasicField.UUID.searchField)
.terms(TermsQueryField.of(f -> f.value(identifiers.stream().map(i -> FieldValue.of(i.toString())).toList())))
)._toQuery();
}

@Override
public Set<Object> getIDs() {
return Set.of();
}

@Override
public Set<Identifier> getIdentifiers() {
return identifiers;
}

@Override
public boolean evaluate(Object o) {
return false;
}

@Override
public Object accept(FilterVisitor filterVisitor, Object o) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,26 +308,31 @@ public ElasticSearchBase.SearchResult<StacCollectionModel> searchByParameters(Li

CQLToElasticFilterFactory<CQLFields> factory = new CQLToElasticFilterFactory<>(coor, CQLFields.class);
if(cql != null) {
Filter filter = CompilerUtil.parseFilter(Language.ECQL, cql, factory);

if(filter instanceof QueryHandler handler) {
if(handler.getErrors() == null || handler.getErrors().isEmpty()) {
if(handler.getQuery() != null) {
// There is no error during parsing
filters = List.of(handler.getQuery());
try {
Filter filter = CompilerUtil.parseFilter(Language.ECQL, cql, factory);
if(filter instanceof QueryHandler handler) {
if(handler.getErrors() == null || handler.getErrors().isEmpty()) {
if(handler.getQuery() != null) {
// There is no error during parsing
filters = List.of(handler.getQuery());
}
}
else {
throw new IllegalArgumentException(
"ECQL Parse Error",
handler.getErrors()
.stream()
.reduce(null, (e1, e2) -> {
if (e1 == null) return e2;
e1.addSuppressed(e2);
return e1;
}));
}
}
else {
throw new IllegalArgumentException(
"CQL Parse Error",
handler.getErrors()
.stream()
.reduce(null, (e1, e2) -> {
if (e1 == null) return e2;
e1.addSuppressed(e2);
return e1;
}));
}
}
catch(CQLException ce) {
log.error("Error parsing ECQL", ce);
throw ce;
}
}
// Get the page size after parsing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,4 +804,25 @@ public void verifyIBoundaryFunctionWorks() throws IOException {
assertEquals(1, Objects.requireNonNull(collections.getBody()).getCollections().size(), "hit 1");
assertEquals("516811d7-cd1e-207a-e0440003ba8c79dd", Objects.requireNonNull(collections.getBody()).getCollections().get(0).getId(), "id correct");
}
/**
* The correct syntax for an id query is id IN (xxxxx), use id=xxxx will fail parsing
* @throws IOException - Not expected
*/
@Test
public void verifyQueryByIdWorks() throws IOException {
super.insertJsonToElasticRecordIndex(
// Will hit Shark Bay
"516811d7-cd1e-207a-e0440003ba8c79dd.json",
// Will hit Central Eastern of Auz marine park, but not Shark Bay
"ae86e2f5-eaaf-459e-a405-e654d85adb9c.json"
);
ResponseEntity<Collections> collections = testRestTemplate.exchange(
getBasePath() + "/collections?properties=id,geometry&filter=id IN('516811d7-cd1e-207a-e0440003ba8c79dd')",
HttpMethod.GET,
null,
new ParameterizedTypeReference<>() {});

assertEquals(1, Objects.requireNonNull(collections.getBody()).getCollections().size(), "hit 1");
assertEquals("516811d7-cd1e-207a-e0440003ba8c79dd", Objects.requireNonNull(collections.getBody()).getCollections().get(0).getId(), "id correct");
}
}
Loading