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
4 changes: 4 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions coverages/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<groupId>com.github.joschi.jackson</groupId>
<artifactId>jackson-datatype-threetenbp</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions features/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions maps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<groupId>com.github.joschi.jackson</groupId>
<artifactId>jackson-datatype-threetenbp</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.13</version>
<version>3.5.14</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>au.org.aodn.ogcapi</groupId>
Expand All @@ -21,8 +21,8 @@
<org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
<org.projectlombok.version>1.18.30</org.projectlombok.version>
<org.projectlombok.binding>0.2.0</org.projectlombok.binding>
<swagger.codegen.version>3.0.61</swagger.codegen.version>
<org.geotools.version>29.2</org.geotools.version>
<swagger.codegen.version>3.0.69</swagger.codegen.version>
<org.geotools.version>29.6</org.geotools.version>
<maven.deploy.skip>true</maven.deploy.skip>
<versioning.updatePom>true</versioning.updatePom>
<aws.sdk.version>2.29.52</aws.sdk.version>
Expand Down Expand Up @@ -56,7 +56,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.8</version>
<version>2.8.17</version>
</dependency>
<dependency>
<groupId>com.github.joschi.jackson</groupId>
Expand Down
4 changes: 4 additions & 0 deletions processes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<groupId>com.github.joschi.jackson</groupId>
<artifactId>jackson-datatype-threetenbp</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions records/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
<groupId>com.github.joschi.jackson</groupId>
<artifactId>jackson-datatype-threetenbp</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@
<groupId>au.org.aodn</groupId>
<artifactId>stacmodel</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Map;

@Configuration
@EnableCaching
Expand Down Expand Up @@ -100,13 +99,13 @@ public JCacheCacheManager cacheManager() throws IOException {
)
.withCache(STRING_TO_GEOMETRY,
CacheConfigurationBuilder.newCacheConfigurationBuilder(
Map.class, Geometry.class,
Object.class, Geometry.class,
ResourcePoolsBuilder.heap(20000)
).withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofMinutes(24)))
)
.withCache(STRING_TO_PREPARE_GEOMETRY,
CacheConfigurationBuilder.newCacheConfigurationBuilder(
Map.class, PreparedGeometry.class,
Object.class, PreparedGeometry.class,
ResourcePoolsBuilder.heap(20000)
).withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofMinutes(24)))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import au.org.aodn.ogcapi.server.core.model.StacItemModel;
import au.org.aodn.ogcapi.server.core.service.ElasticSearch;
import org.mapstruct.Mapper;
import org.openapitools.jackson.nullable.JsonNullable;
import org.opengis.filter.Filter;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -37,8 +38,7 @@ public FeatureCollectionGeoJSON convert(ElasticSearch.SearchResult<StacItemModel
feature.setGeometry(new PointGeoJSON().type(PointGeoJSON.TypeEnum.POINT).coordinates(c));
}
}
feature.setProperties(i.getProperties());

feature.setProperties(JsonNullable.of(i.getProperties()));
return feature;
})
.filter(i -> i.getGeometry() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import au.org.aodn.ogcapi.features.model.PointGeoJSON;
import au.org.aodn.ogcapi.server.core.model.enumeration.FeatureProperty;
import au.org.aodn.ogcapi.server.core.util.DatasetSummarizer;
import org.openapitools.jackson.nullable.JsonNullable;

import java.math.BigDecimal;
import java.util.ArrayList;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void addDatum(StacItemModel datum) {
.ifPresent(val -> properties.put(FeatureProperty.COUNT.getValue(), val));


feature.setProperties(properties);
feature.setProperties(JsonNullable.of(properties));
dataset.getFeatures().add(feature);
}

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.FeatureGeoJSON;
import lombok.Getter;
import lombok.Setter;
import org.openapitools.jackson.nullable.JsonNullable;

import java.util.Map;
@Getter
Expand All @@ -19,7 +20,7 @@ public FeatureGeoJSON toFeatureGeoJSON() {
//TODO: when more geometry types are supported, functions should be
// updated then.
f.setGeometry(geometry.toGeoJson());
f.setProperties(properties);
f.setProperties(JsonNullable.of(properties));
return f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLElasticSetting;
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFieldsInterface;
import lombok.Getter;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.NameImpl;
import org.geotools.filter.AttributeExpressionImpl;
import org.geotools.filter.IllegalFilterException;
import org.geotools.filter.LiteralExpressionImpl;
Expand Down Expand Up @@ -92,7 +94,7 @@ public static Map<CQLElasticSetting, String> getDefaultSetting() {
*
* @param geometry1 - The attribute value, it will be mapped by the type T enum to the real field name in Elastic
* @param geometry2 - The Polygon and will convert to GeoJson
* @return
* @return IntersectsImpl - The intersects filter, internally it constructed the query chain
*/
@Override
public Intersects intersects(Expression geometry1, Expression geometry2) {
Expand Down Expand Up @@ -709,12 +711,16 @@ public Subtract subtract(Expression expression, Expression expression1) {

@Override
public Function function(String s, Expression... expressions) {
return null;
return function(new NameImpl(s), expressions);
}

@Override
public Function function(Name name, Expression... expressions) {
return null;
logger.debug("Function {} {}", name, expressions);
if(name.getLocalPart().equals(IBoundaryFunction.NAME.getFunctionName().getLocalPart())) {
return new IBoundaryFunction(List.of(expressions), null);
}
return CommonFactoryFinder.getFilterFactory2().function(name, expressions);
}

@Override
Expand Down Expand Up @@ -768,9 +774,9 @@ public Literal literal(boolean b) {
}
/**
* The jj parse have not setup anything related to sort, so this is not use, manual parse needed.
* @param s
* @param sortOrder
* @return
* @param s - Field name
* @param sortOrder - Order of sort
* @return - SortBy
*/
@Override
public SortBy sort(String s, SortOrder sortOrder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package au.org.aodn.ogcapi.server.core.parser.elastic;


import au.org.aodn.ogcapi.server.core.util.GeometryUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.geotools.filter.FunctionImpl;
import org.geotools.filter.capability.FunctionNameImpl;
import org.locationtech.jts.geom.Geometry;
import org.opengis.filter.capability.FunctionName;
import org.opengis.filter.expression.Expression;
import org.opengis.filter.expression.Literal;
import org.springframework.core.io.ClassPathResource;

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

@Slf4j
public class IBoundaryFunction extends FunctionImpl {

private static Map<String, Geometry> loadStaticMap(String path, String keyField) {
final Map<String, Geometry> map = new HashMap<>();
try (InputStream is = new ClassPathResource(path).getInputStream()) {
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(is);
JsonNode features = root.get("features");
if (features != null && features.isArray()) {
for (JsonNode feature : features) {
JsonNode properties = feature.get("properties");
if (properties != null) {
JsonNode objectId = properties.get(keyField);
if (objectId != null) {
String key = objectId.asText();
JsonNode geometry = feature.get("geometry");
if (geometry != null) {
String geoJson = mapper.writeValueAsString(geometry);
GeometryUtils.readGeometry(geoJson).ifPresent(geo -> map.put(key, geo));
}
}
}
}
}
} catch (IOException e) {
log.error("Failed to load {}", path, e);
}
return map;
}

static final Map<String, Geometry> CORAL_ATLAS = loadStaticMap("static/api/v1/ogc/ext/static/Allen_Coral_Atlas.json", "OBJECTID");

static final Map<String, Geometry> AUZ_MARINE_PARK = loadStaticMap("static/api/v1/ogc/ext/static/Australian_Marine_Parks_boundaries.json", "OBJECTID");

static final Map<String, Geometry> MEOW = loadStaticMap("static/api/v1/ogc/ext/static/Meow.json", "ECO_CODE");

static Geometry getGeoJsonFromMap(String mapName, String key) {
return switch (mapName) {
case "CORAL_ATLAS" -> CORAL_ATLAS.get(key);
case "AUSTRALIAN_MARINE_PARKS" -> AUZ_MARINE_PARK.get(key);
case "MEOW" -> MEOW.get(key);
default -> null;
};
}

public static final FunctionName NAME = new FunctionNameImpl(
"IBOUNDARY",
Geometry.class,
FunctionNameImpl.parameter("name", String.class),
FunctionNameImpl.parameter("id", String.class) // optional
);

public IBoundaryFunction(List<Expression> parameters, Literal fallback) {
this.setName("IBOUNDARY");
this.setParameters(parameters);
this.setFallbackValue(fallback);
}

@Override
public Object evaluate(Object feature) {
String name = getParameters().get(0).evaluate(feature, String.class);
String id = getParameters().get(1).evaluate(feature, String.class);

return getGeoJsonFromMap(name, id);
}

@Override
public FunctionName getFunctionName() {
return NAME;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package au.org.aodn.ogcapi.server.core.parser.elastic;

import org.geotools.feature.NameImpl;
import org.geotools.filter.FunctionFactory;
import org.opengis.feature.type.Name;
import org.opengis.filter.capability.FunctionName;
import org.opengis.filter.expression.Expression;
import org.opengis.filter.expression.Function;
import org.opengis.filter.expression.Literal;

import java.util.List;

public class IBoundaryFunctionFactory implements FunctionFactory {

@Override
public List<FunctionName> getFunctionNames() {
return List.of(IBoundaryFunction.NAME);
}

@Override
public Function function(String name, List<Expression> args, Literal fallback) {
return function(new NameImpl(name), args, fallback);
}

@Override
public Function function(Name name, List<Expression> args, Literal fallback) {
if (IBoundaryFunction.NAME.getFunctionName().equals(name)) {
return new IBoundaryFunction(args, fallback);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import au.org.aodn.ogcapi.server.core.util.GeometryUtils;
import org.geotools.filter.AttributeExpressionImpl;
import org.geotools.filter.LiteralExpressionImpl;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.opengis.filter.FilterVisitor;
import org.opengis.filter.expression.Expression;
import org.opengis.filter.expression.Function;
import org.opengis.filter.spatial.Intersects;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.operation.TransformException;
Expand All @@ -27,7 +29,21 @@ public IntersectsImpl(Expression expression1, Expression expression2, Class<T> e
this.expression1 = expression1;
this.expression2 = expression2;

if(expression1 instanceof AttributeExpressionImpl attribute && expression2 instanceof LiteralExpressionImpl literal) {
if(expression1 instanceof AttributeExpressionImpl attribute && expression2 instanceof Function func) {
Object val = func.evaluate(null);
if(val instanceof Geometry geometry) {
try {
String geojson = GeometryUtils.convertToGeoJson(geometry, cqlCrsType);
T v = Enum.valueOf(enumType, attribute.toString());
this.query = v.getIntersectsQuery(geojson);
}
catch (Exception e) {
logger.warn("Exception in geometry transform, query result will be wrong", e);
this.query = null;
}
}
}
else if(expression1 instanceof AttributeExpressionImpl attribute && expression2 instanceof LiteralExpressionImpl literal) {
try {
String geojson = GeometryUtils.convertToGeoJson(literal, cqlCrsType);
// Create elastic query here
Expand Down
Loading
Loading