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
@@ -1,9 +1,11 @@
package au.org.aodn.ogcapi.server.core.configuration;

import au.org.aodn.ogcapi.server.core.service.CacheNoLandGeometry;
import au.org.aodn.ogcapi.server.core.util.GeometryUtils;
import org.ehcache.config.builders.*;
import org.ehcache.config.units.MemoryUnit;
import org.ehcache.jsr107.EhcacheCachingProvider;
import org.locationtech.jts.geom.Geometry;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.jcache.JCacheCacheManager;
import org.springframework.context.annotation.Bean;
Expand All @@ -27,6 +29,7 @@ public class CacheConfig {
public static final String ALL_NO_LAND_GEOMETRY = "all-noland-geometry";
public static final String ALL_PARAM_VOCABS = "parameter-vocabs";
public static final String ELASTIC_SEARCH_UUID_ONLY = "elastic-search-uuid-only";
public static final String STRING_TO_GEOMETRY = "string-to-geometry";

@Bean
public CacheNoLandGeometry createCacheNoLandGeometry() {
Expand Down Expand Up @@ -74,9 +77,15 @@ public JCacheCacheManager cacheManager() throws IOException {
.withCache(ELASTIC_SEARCH_UUID_ONLY,
CacheConfigurationBuilder.newCacheConfigurationBuilder(
Object.class, Object.class,
ResourcePoolsBuilder.heap(200)
ResourcePoolsBuilder.heap(50)
).withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofMinutes(5)))
)
.withCache(STRING_TO_GEOMETRY,
CacheConfigurationBuilder.newCacheConfigurationBuilder(
String.class, Geometry.class,
ResourcePoolsBuilder.heap(20000)
).withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofMinutes(24)))
)
.withCache(GET_CAPABILITIES_WMS_LAYERS,
CacheConfigurationBuilder.newCacheConfigurationBuilder(
Object.class, Object.class,
Expand All @@ -95,6 +104,8 @@ public JCacheCacheManager cacheManager() throws IOException {
config
);

GeometryUtils.setCacheManager(jCacheManager);

return new JCacheCacheManager(jCacheManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Mapper(componentModel = "spring")
Expand All @@ -23,7 +22,7 @@ public abstract class StacToCollections implements Converter<ElasticSearch.Searc
@Override
public Collections convert(ElasticSearch.SearchResult<StacCollectionModel> model, Filter filter) {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public FeatureCollectionGeoJSON convert(ElasticSearch.SearchResult<StacItemModel
FeatureCollectionGeoJSON f = new FeatureCollectionGeoJSON();
f.setType(FeatureCollectionGeoJSON.TypeEnum.FEATURECOLLECTION);

List<FeatureGeoJSON> features = model.getCollections().parallelStream()
List<FeatureGeoJSON> features = model.getCollections().stream()
.map(i -> {
FeatureGeoJSON feature = new FeatureGeoJSON();
feature.setType(FeatureGeoJSON.TypeEnum.FEATURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.cache.Cache;
import javax.cache.CacheManager;
import java.io.IOException;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.*;

import static au.org.aodn.ogcapi.server.core.configuration.CacheConfig.STRING_TO_GEOMETRY;

public class GeometryUtils {

protected static final int PRECISION = 15;

@Setter
protected static volatile CacheManager cacheManager;

@Getter
protected static GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);

Expand Down Expand Up @@ -212,13 +219,34 @@ public static String convertToGeoJson(LiteralExpressionImpl literalExpression, C
*/
public static Optional<Geometry> readGeometry(Object input) {
try {
String j;
if (!(input instanceof String)) {
input = mapper.writeValueAsString(input);
j = mapper.writeValueAsString(input);
} else {
j = (String) input;
}

if (cacheManager != null) {
Cache<String, Geometry> cache = cacheManager.getCache(STRING_TO_GEOMETRY);

if (cache != null) {
Geometry geometry = cache.get(j);
if (geometry == null) {
geometry = json.read(j);
cache.put(j, geometry);
}
return Optional.of(geometry);
}
}
return Optional.of(json.read(input));
} catch (IOException e) {
return Optional.empty();
else {
// We have not setup cache manager in test
return Optional.of(json.read(j));
}
}
catch (IOException e) {
// Do nothing
}
return Optional.empty();
}

/**
Expand Down