@@ -419,6 +419,8 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
419419 :returns: tuple of headers, status code, content
420420 """
421421
422+ cql_ops = []
423+
422424 if collection not in self .get_all_collections ():
423425 msg = 'Invalid collection'
424426 LOGGER .exception (msg )
@@ -430,32 +432,93 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
430432 LOGGER .debug ('Empty JSON payload' )
431433 json_post_data = {}
432434
433- if 'filter' in json_post_data :
434- LOGGER .debug ('Detected filter query parameter' )
435- json_post_data = json_post_data .pop ('filter' )
436-
437435 if 'bbox' in json_post_data :
438436 LOGGER .debug ('Detected bbox query parameter' )
439- bbox_ = json_post_data .pop ('bbox' )
440- bbox_ = ',' .join ([str (b ) for b in bbox_ ])
441- args ['bbox' ] = bbox_
437+
438+ cql_ops .append ({
439+ 'op' : 's_intersects' , 'args' : [{
440+ 'property' : 'geometry'
441+ },
442+ {'bbox' : json_post_data .pop ('bbox' )}]
443+ })
442444
443445 if 'limit' in json_post_data :
444446 LOGGER .debug ('Detected limit query parameter' )
445447 args ['limit' ] = json_post_data .pop ('limit' )
446448
447449 if 'collections' in json_post_data :
448- LOGGER .debug ('Detected limit query parameter' )
449- args ['collections' ] = ',' .join (json_post_data .pop ('collections' ))
450+ LOGGER .debug ('Detected collections query parameter' )
451+ cql_ops .append ({
452+ 'op' : 'in' ,
453+ 'args' : [{
454+ 'property' : 'collections' ,
455+ },
456+ json_post_data .pop ('collections' )
457+ ]
458+ })
450459
451460 if 'ids' in json_post_data :
452461 LOGGER .debug ('Detected ids query parameter' )
453- args ['ids' ] = ',' .join (json_post_data .pop ('ids' ))
462+ cql_ops .append ({
463+ 'op' : 'in' ,
464+ 'args' : [{
465+ 'property' : 'identifier' ,
466+ },
467+ json_post_data .pop ('ids' )
468+ ]
469+ })
454470
455471 if 'intersects' in json_post_data :
456472 LOGGER .debug ('Detected intersects query parameter' )
457473 # TODO
458474
475+ if 'datetime' in json_post_data :
476+ if '/' not in json_post_data ['datetime' ]:
477+ cql_ops .append ({
478+ 'op' : '=' ,
479+ 'args' : [
480+ {'property' : 'date' },
481+ json_post_data .pop ('datetime' )
482+ ]
483+ })
484+ else :
485+ begin , end = json_post_data .pop ('datetime' ).split ('/' )
486+ if begin != '..' :
487+ cql_ops .append ({
488+ 'op' : '>=' ,
489+ 'args' : [
490+ {'property' : 'time_begin' },
491+ begin
492+ ]
493+ })
494+ if end != '..' :
495+ cql_ops .append ({
496+ 'op' : '<=' ,
497+ 'args' : [
498+ {'property' : 'time_end' },
499+ end
500+ ]
501+ })
502+
503+ if 'filter' in json_post_data :
504+ LOGGER .debug ('Detected filter query parameter' )
505+ json_post_data = json_post_data .pop ('filter' )
506+
507+ if not json_post_data and not cql_ops :
508+ LOGGER .debug ('No JSON POST data or CQL ops' )
509+ elif not json_post_data and cql_ops :
510+ LOGGER .debug ('No JSON POST data left' )
511+ json_post_data = {
512+ 'op' : 'and' ,
513+ 'args' : cql_ops
514+ }
515+ else :
516+ LOGGER .debug ('JSON POST data is CQL2 JSON' )
517+ if cql_ops :
518+ print ("JJ2" , json_post_data )
519+ LOGGER .debug ('Adding STAC API query parameters to CQL2 JSON' )
520+ json_post_data ['args' ].extend (cql_ops )
521+
459522 headers , status , response = super ().items (headers_ , json_post_data , args , collection )
460523
461524 response = json .loads (response )
0 commit comments