5
5
6
6
package org .fao .geonet .ogcapi .records .controller ;
7
7
8
- import com .fasterxml .jackson .core .JsonFactory ;
9
- import com .fasterxml .jackson .core .JsonParser ;
10
8
import com .fasterxml .jackson .databind .JsonNode ;
11
- import com .fasterxml .jackson .databind .ObjectMapper ;
12
9
import io .swagger .annotations .Api ;
13
10
import io .swagger .annotations .ApiParam ;
14
11
import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
54
51
import org .fao .geonet .ogcapi .records .model .Item ;
55
52
import org .fao .geonet .ogcapi .records .model .XsltModel ;
56
53
import org .fao .geonet .ogcapi .records .service .CollectionService ;
54
+ import org .fao .geonet .ogcapi .records .service .QueryBuilder ;
57
55
import org .fao .geonet .ogcapi .records .service .RecordService ;
58
56
import org .fao .geonet .ogcapi .records .util .MediaTypeUtil ;
59
57
import org .fao .geonet .ogcapi .records .util .RecordsEsQueryBuilder ;
87
85
@ Slf4j (topic = "org.fao.geonet.ogcapi.records" )
88
86
public class ItemApiController {
89
87
88
+
90
89
public static final String EXCEPTION_COLLECTION_NOT_FOUND =
91
90
"ogcapir.exception.collection.notFound" ;
92
91
public static final String EXCEPTION_COLLECTION_ITEM_NOT_FOUND =
@@ -114,10 +113,11 @@ public class ItemApiController {
114
113
DcatConverter dcatConverter ;
115
114
@ Autowired
116
115
RecordService recordService ;
116
+ @ Autowired
117
+ QueryBuilder queryBuilder ;
117
118
118
119
/**
119
120
* Describe a collection item.
120
- *
121
121
*/
122
122
@ io .swagger .v3 .oas .annotations .Operation (
123
123
summary = "Describe a collection item." ,
@@ -143,7 +143,7 @@ public ResponseEntity<Void> collectionsCollectionIdItemsRecordIdGet(
143
143
@ ApiParam (value = "Identifier (name) of a specific collection" , required = true )
144
144
@ PathVariable ("collectionId" ) String collectionId ,
145
145
@ ApiParam (value = "Identifier (name) of a specific record" , required = true )
146
- @ PathVariable ("recordId" )String recordId ,
146
+ @ PathVariable ("recordId" ) String recordId ,
147
147
@ ApiIgnore HttpServletRequest request ,
148
148
@ ApiIgnore HttpServletResponse response ,
149
149
@ ApiIgnore Model model ) {
@@ -165,7 +165,6 @@ public ResponseEntity<Void> collectionsCollectionIdItemsRecordIdGet(
165
165
MediaType mediaType =
166
166
mediaTypeUtil .calculatePriorityMediaTypeFromRequest (request , allowedMediaTypes );
167
167
168
-
169
168
if (mediaType .equals (MediaType .APPLICATION_JSON )
170
169
|| mediaType .equals (GnMediaType .APPLICATION_GEOJSON )) {
171
170
try {
@@ -201,7 +200,6 @@ public ResponseEntity<Void> collectionsCollectionIdItemsRecordIdGet(
201
200
202
201
/**
203
202
* Describe the collection items.
204
- *
205
203
*/
206
204
@ io .swagger .v3 .oas .annotations .Operation (
207
205
summary = "Describe the collection items." ,
@@ -248,13 +246,27 @@ public ResponseEntity<Void> collectionsCollectionIdItemsGet(
248
246
@ ApiParam (value = "" )
249
247
@ RequestParam (value = "externalids" , required = false )
250
248
List <String > externalids ,
249
+ @ RequestParam (value = "ids" , required = false )
250
+ List <String > ids ,
251
251
@ ApiParam (value = "" )
252
252
@ RequestParam (value = "sortby" , required = false )
253
253
List <String > sortby ,
254
254
@ ApiIgnore HttpServletRequest request ,
255
255
@ ApiIgnore HttpServletResponse response ,
256
256
@ ApiIgnore Model model ) throws Exception {
257
257
258
+ var query = queryBuilder .buildFromRequest (collectionId ,
259
+ bbox ,
260
+ datetime ,
261
+ limit ,
262
+ startindex ,
263
+ type ,
264
+ q ,
265
+ ids ,
266
+ externalids ,
267
+ sortby ,
268
+ request .getParameterMap ()
269
+ );
258
270
List <MediaType > allowedMediaTypes =
259
271
ListUtils .union (MediaTypeUtil .defaultSupportedMediaTypes ,
260
272
Arrays .asList (
@@ -276,15 +288,14 @@ public ResponseEntity<Void> collectionsCollectionIdItemsGet(
276
288
277
289
boolean allSourceFields =
278
290
mediaType .equals (GnMediaType .APPLICATION_DCAT2_XML )
279
- || mediaType .equals (GnMediaType .APPLICATION_RDF_XML );
291
+ || mediaType .equals (GnMediaType .APPLICATION_RDF_XML );
280
292
281
293
return collectionsCollectionIdItemsGetInternal (
282
- collectionId , bbox , datetime , limit , startindex , type , q , externalids , sortby ,
294
+ query ,
283
295
request , response , allSourceFields );
284
296
285
297
} else {
286
- return collectionsCollectionIdItemsGetAsHtml (collectionId , bbox , datetime , limit ,
287
- startindex , type , q , externalids , sortby , request , response , model );
298
+ return collectionsCollectionIdItemsGetAsHtml (query , request , response , model );
288
299
}
289
300
}
290
301
@@ -473,7 +484,7 @@ private ResponseEntity<Void> collectionsCollectionIdItemsRecordIdGetAsHtml(
473
484
private List <String > setDefaultRssSortBy (List <String > sortby , HttpServletRequest request ) {
474
485
boolean isRss = "rss" .equals (request .getParameter ("f" ))
475
486
|| (request .getHeader (HttpHeaders .ACCEPT ) != null
476
- && request .getHeader (HttpHeaders .ACCEPT ).contains (MediaType .APPLICATION_RSS_XML_VALUE ));
487
+ && request .getHeader (HttpHeaders .ACCEPT ).contains (MediaType .APPLICATION_RSS_XML_VALUE ));
477
488
if (isRss
478
489
&& (sortby == null || sortby .isEmpty ())) {
479
490
sortby = new ArrayList <>();
@@ -484,27 +495,18 @@ private List<String> setDefaultRssSortBy(List<String> sortby, HttpServletRequest
484
495
485
496
486
497
private String search (
487
- String collectionId ,
488
- List <BigDecimal > bbox ,
489
- String datetime ,
490
- Integer limit ,
491
- Integer startindex ,
492
- String type ,
493
- List <String > q ,
494
- List <String > externalids ,
495
- List <String > sortby ,
498
+ Query requestQuery ,
496
499
HttpServletRequest request , boolean allSourceFields ) {
497
500
498
- Source source = collectionService .retrieveSourceForCollection (collectionId );
501
+ Source source = collectionService .retrieveSourceForCollection (requestQuery . getCollectionId () );
499
502
500
503
if (source == null ) {
501
504
throw new ResponseStatusException (HttpStatus .NOT_FOUND , "Unable to find collection" );
502
505
}
503
506
504
507
String collectionFilter = collectionService .retrieveCollectionFilter (source , false );
505
508
String query = recordsEsQueryBuilder
506
- .buildQuery (q , externalids , bbox ,
507
- startindex , limit , collectionFilter , sortby ,
509
+ .buildQuery (requestQuery , collectionFilter ,
508
510
allSourceFields ? Set .of ("*" ) : null );
509
511
try {
510
512
return proxy .searchAndGetResult (request .getSession (), request , query , null );
@@ -519,23 +521,14 @@ private String search(
519
521
520
522
521
523
private ResponseEntity <Void > collectionsCollectionIdItemsGetInternal (
522
- String collectionId ,
523
- List <BigDecimal > bbox ,
524
- String datetime ,
525
- Integer limit ,
526
- Integer startindex ,
527
- String type ,
528
- List <String > q ,
529
- List <String > externalids ,
530
- List <String > sortby ,
524
+ Query query ,
531
525
HttpServletRequest request ,
532
526
HttpServletResponse response ,
533
527
boolean allSourceFields ) {
534
528
535
- sortby = setDefaultRssSortBy (sortby , request );
529
+ query . setSortBy ( setDefaultRssSortBy (query . getSortBy () , request ) );
536
530
537
- String queryResponse = search (collectionId , bbox , datetime , limit , startindex , type , q ,
538
- externalids , sortby , request , allSourceFields );
531
+ String queryResponse = search (query , request , allSourceFields );
539
532
540
533
try {
541
534
streamResult (response , queryResponse , getResponseContentType (request ));
@@ -551,30 +544,22 @@ private ResponseEntity<Void> collectionsCollectionIdItemsGetInternal(
551
544
* Collection items as HTML.
552
545
*/
553
546
private ResponseEntity <Void > collectionsCollectionIdItemsGetAsHtml (
554
- String collectionId ,
555
- List <BigDecimal > bbox ,
556
- String datetime ,
557
- Integer limit ,
558
- Integer startindex ,
559
- String type ,
560
- List <String > q ,
561
- List <String > externalids ,
562
- List <String > sortby ,
547
+ Query requestQuery ,
563
548
HttpServletRequest request ,
564
549
HttpServletResponse response ,
565
550
Model model ) throws Exception {
566
551
567
552
Locale locale = LocaleContextHolder .getLocale ();
568
553
String language = locale .getISO3Language ();
569
- Source source = collectionService .retrieveSourceForCollection (collectionId );
554
+ Source source = collectionService .retrieveSourceForCollection (requestQuery . getCollectionId () );
570
555
571
556
if (source == null ) {
572
557
throw new ResponseStatusException (HttpStatus .NOT_FOUND , "Unable to find collection" );
573
558
}
574
559
575
560
String collectionFilter = collectionService .retrieveCollectionFilter (source , false );
576
561
String query = recordsEsQueryBuilder
577
- .buildQuery (q , externalids , bbox , startindex , limit , collectionFilter , sortby , null );
562
+ .buildQuery (requestQuery , collectionFilter , null );
578
563
579
564
EsSearchResults results = new EsSearchResults ();
580
565
try {
@@ -588,10 +573,10 @@ private ResponseEntity<Void> collectionsCollectionIdItemsGetAsHtml(
588
573
XsltModel modelSource = new XsltModel ();
589
574
Map <String , String []> parameterMap = new HashMap <>(request .getParameterMap ());
590
575
if (request .getParameter ("limit" ) == null ) {
591
- parameterMap .put ("limit" , new String []{limit + "" });
576
+ parameterMap .put ("limit" , new String []{requestQuery . getLimit () + "" });
592
577
}
593
578
if (request .getParameter ("startindex" ) == null ) {
594
- parameterMap .put ("startindex" , new String []{startindex + "" });
579
+ parameterMap .put ("startindex" , new String []{requestQuery . getStartIndex () + "" });
595
580
}
596
581
modelSource .setRequestParameters (parameterMap );
597
582
modelSource .setCollection (source );
0 commit comments