Skip to content

Commit 21bae10

Browse files
authored
Merge pull request #120 from davidblasby/_ogcapi_test_clean
ogcapi - clean up + test cases
2 parents 266cf36 + 9da5cf9 commit 21bae10

File tree

24 files changed

+757
-153
lines changed

24 files changed

+757
-153
lines changed

modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/gn/IndexRecord.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public IndexRecord() {
210210
*/
211211
public List<String> getGeometriesAsJsonString() {
212212
if (geometries == null || geometries.isEmpty()) {
213-
return null;
213+
return new ArrayList<>();
214214
}
215215
List<String> result = new ArrayList<>();
216216

modules/library/common-search/src/main/java/org/fao/geonet/common/search/ElasticSearchProxy.java

+12
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555
@Slf4j(topic = "org.fao.geonet.searching")
5656
public class ElasticSearchProxy {
5757

58+
/**
59+
* ACCEPT_OVERRIDE_ATTRIBUTE.
60+
*
61+
* <p>request.setVariable(ACCEPT_OVERRIDE_ATTRIBUTE, "gnindex");
62+
* This will force this to return the underlying gnindex json instead of the format in the
63+
* request.
64+
* This allows a GeoJSON to still get the underlying gnindex json.
65+
*/
66+
public static final String ACCEPT_OVERRIDE_ATTRIBUTE = "accepts-override";
5867
public static final String[] validContentTypes = {
5968
"application/json", "text/plain", "application/rss+xml"
6069
};
@@ -745,6 +754,9 @@ private void processResponse(
745754

746755
// TODO: Header can contain a list of ... So get the first which match a processor
747756
String acceptHeader = getAcceptValue(request);
757+
if (request.getAttribute(ACCEPT_OVERRIDE_ATTRIBUTE) != null) {
758+
acceptHeader = request.getAttribute(ACCEPT_OVERRIDE_ATTRIBUTE).toString();
759+
}
748760

749761
boolean isDcatOnItem =
750762
request.getRequestURI().matches(".*/collections/.*/items/.*")

modules/library/common-search/src/main/resources/application.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ gn:
111111
responseProcessor: RssResponseProcessorImpl
112112
operations:
113113
- items
114-
- name : gnindex-json
114+
- name : gnindex
115115
mimeType : application/gnindex+json
116116
responseProcessor : JsonUserAndSelectionAwareResponseProcessorImpl
117117
operations :

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/MvcConfigurer.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
3+
* GPL 2.0 license, available at the root application directory.
4+
*/
5+
16
package org.fao.geonet.ogcapi.records;
27

38
import static springfox.documentation.builders.PathSelectors.regex;

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/ApiDocController.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
3+
* GPL 2.0 license, available at the root application directory.
4+
*/
5+
16
package org.fao.geonet.ogcapi.records.controller;
27

38
import java.io.IOException;

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/CapabilitiesApiController.java

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Locale;
1313
import javax.servlet.http.HttpServletRequest;
1414
import javax.servlet.http.HttpServletResponse;
15+
import org.fao.geonet.common.search.GnMediaType;
1516
import org.fao.geonet.common.search.SearchConfiguration;
1617
import org.fao.geonet.common.search.SearchConfiguration.Operations;
1718
import org.fao.geonet.domain.Source;

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/ItemApiController.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,17 @@ public ResponseEntity<Void> collectionsCollectionIdItemsRecordIdGet(
162162
ListUtils.union(MediaTypeUtil.defaultSupportedMediaTypes,
163163
MediaTypeUtil.ldSupportedMediaTypes);
164164
allowedMediaTypes.add(GnMediaType.APPLICATION_GEOJSON);
165+
allowedMediaTypes.add(GnMediaType.APPLICATION_ELASTICJSON);
165166

166167
MediaType mediaType =
167168
mediaTypeUtil.calculatePriorityMediaTypeFromRequest(request, allowedMediaTypes);
168169

169170
if (mediaType.equals(MediaType.APPLICATION_JSON)
170-
|| mediaType.equals(GnMediaType.APPLICATION_GEOJSON)) {
171+
|| mediaType.equals(GnMediaType.APPLICATION_GEOJSON)
172+
|| mediaType.equals(GnMediaType.APPLICATION_ELASTICJSON)) {
171173
try {
172-
String type = mediaType.equals(MediaType.APPLICATION_JSON) ? "json" : "geojson";
174+
String type = getSimplifiedMediaType(mediaType);
175+
173176
JsonNode recordAsJson = recordService.getRecordAsJson(collectionId, recordId,
174177
request, source, type);
175178

@@ -198,6 +201,22 @@ public ResponseEntity<Void> collectionsCollectionIdItemsRecordIdGet(
198201
}
199202
}
200203

204+
private String getSimplifiedMediaType(MediaType mediaType) {
205+
String type = "gnindex";
206+
if (mediaType.equals(MediaType.APPLICATION_JSON)) {
207+
type = "json";
208+
} else {
209+
if (mediaType.equals(GnMediaType.APPLICATION_GEOJSON)) {
210+
type = "geojson";
211+
} else {
212+
if (mediaType.equals(GnMediaType.APPLICATION_ELASTICJSON)) {
213+
type = "gnindex";
214+
}
215+
}
216+
}
217+
return type;
218+
}
219+
201220

202221
/**
203222
* Describe the collection items.

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/model/Conformance.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
3+
* GPL 2.0 license, available at the root application directory.
4+
*/
5+
16
package org.fao.geonet.ogcapi.records.controller.model;
27

38
import com.fasterxml.jackson.annotation.JsonProperty;

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/model/Content.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
3+
* GPL 2.0 license, available at the root application directory.
4+
*/
5+
16
package org.fao.geonet.ogcapi.records.controller.model;
27

38
import com.fasterxml.jackson.annotation.JsonProperty;

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/model/Exception.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
3+
* GPL 2.0 license, available at the root application directory.
4+
*/
5+
16
package org.fao.geonet.ogcapi.records.controller.model;
27

38
import com.fasterxml.jackson.annotation.JsonProperty;

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/model/ReqClasses.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
3+
* GPL 2.0 license, available at the root application directory.
4+
*/
5+
16
package org.fao.geonet.ogcapi.records.controller.model;
27

38
import com.fasterxml.jackson.annotation.JsonProperty;

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/model/Root.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
3+
* GPL 2.0 license, available at the root application directory.
4+
*/
5+
16
package org.fao.geonet.ogcapi.records.controller.model;
27

38
import com.fasterxml.jackson.annotation.JsonInclude;

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/service/CollectionService.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
3+
* GPL 2.0 license, available at the root application directory.
4+
*/
5+
16
package org.fao.geonet.ogcapi.records.service;
27

38

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/service/QueryBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Query buildFromRequest(String collectionId,
9393
*/
9494
private void injectExtraFromRequest(String collectionId, Query result,
9595
Map<String, String[]> parameterMap) {
96-
var queryables = queryablesService.buildQueryables(collectionId)
96+
var queryables = queryablesService.getFullQueryables(collectionId)
9797
.getProperties();
9898

9999
result.setPropValues(new LinkedHashMap<>());

modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/service/QueryToElastic.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void augmentWithQueryables(SearchSourceBuilder sourceBuilder,
7070
}
7171
var boolQuery = (BoolQueryBuilder) mainQuery;
7272

73-
var jsonSchema = queryablesService.buildQueryables(query.getCollectionId());
73+
var jsonSchema = queryablesService.getFullQueryables(query.getCollectionId());
7474

7575
for (var prop : query.getPropValues().entrySet()) {
7676
var jsonProp = jsonSchema.getProperties().get(prop.getKey());
@@ -196,9 +196,9 @@ private QueryBuilder createGeo(GnElasticInfo gnElasticInfo, String userSearchTer
196196

197197
Rectangle rectangle = new Rectangle(
198198
Double.parseDouble(nums[0]),
199-
Double.parseDouble(nums[1]),
199+
Double.parseDouble(nums[2]),
200200
Double.parseDouble(nums[3]),
201-
Double.parseDouble(nums[2]));
201+
Double.parseDouble(nums[1]));
202202

203203
try {
204204
var geoQuery = QueryBuilders

0 commit comments

Comments
 (0)