@@ -216,7 +216,7 @@ def _order(
216
216
product .properties ["storageStatus" ] = STAGING_STATUS
217
217
except RequestException as e :
218
218
self ._check_auth_exception (e )
219
- msg = f' { product .properties [" title" ]} could not be ordered'
219
+ msg = f" { product .properties [' title' ]} could not be ordered"
220
220
if e .response is not None and e .response .status_code == 400 :
221
221
raise ValidationError .from_error (e , msg ) from e
222
222
else :
@@ -255,6 +255,16 @@ def order_response_process(
255
255
product .properties .update (
256
256
{k : v for k , v in properties_update .items () if v != NOT_AVAILABLE }
257
257
)
258
+ # the job id becomes the product id for EcmwfSearch products
259
+ if "ORDERABLE" in product .properties .get ("id" , "" ):
260
+ product .properties ["id" ] = product .properties .get (
261
+ "orderId" , product .properties ["id" ]
262
+ )
263
+ product .properties ["title" ] = (
264
+ (product .product_type or product .provider ).upper ()
265
+ + "_"
266
+ + product .properties ["id" ]
267
+ )
258
268
if "downloadLink" in product .properties :
259
269
product .remote_location = product .location = product .properties [
260
270
"downloadLink"
@@ -390,7 +400,10 @@ def _request(
390
400
# success and no need to get status response content
391
401
skip_parsing_status_response = True
392
402
except RequestException as e :
393
- msg = f'{ product .properties ["title" ]} order status could not be checked'
403
+ msg = (
404
+ f"{ product .properties .get ('title' ) or product .properties .get ('id' ) or product } "
405
+ "order status could not be checked"
406
+ )
394
407
if e .response is not None and e .response .status_code == 400 :
395
408
raise ValidationError .from_error (e , msg ) from e
396
409
else :
@@ -426,23 +439,29 @@ def _request(
426
439
f"{ product .properties ['title' ]} order status: { status_percent } "
427
440
)
428
441
429
- status_message = status_dict .get ("message" )
442
+ product .properties .update (
443
+ {k : v for k , v in status_dict .items () if v != NOT_AVAILABLE }
444
+ )
445
+
430
446
product .properties ["orderStatus" ] = status_dict .get ("status" )
431
447
448
+ status_message = status_dict .get ("message" )
449
+
432
450
# handle status error
433
451
errors : dict [str , Any ] = status_config .get ("error" , {})
434
452
if errors and errors .items () <= status_dict .items ():
435
453
raise DownloadError (
436
454
f"Provider { product .provider } returned: { status_dict .get ('error_message' , status_message )} "
437
455
)
438
456
457
+ product .properties ["storageStatus" ] = STAGING_STATUS
458
+
439
459
success_status : dict [str , Any ] = status_config .get ("success" , {}).get ("status" )
440
460
# if not success
441
461
if (success_status and success_status != status_dict .get ("status" )) or (
442
462
success_code and success_code != response .status_code
443
463
):
444
- error = NotAvailableError (status_message )
445
- raise error
464
+ return None
446
465
447
466
product .properties ["storageStatus" ] = ONLINE_STATUS
448
467
@@ -461,7 +480,11 @@ def _request(
461
480
product .properties ["title" ],
462
481
e ,
463
482
)
464
- return None
483
+ msg = f"{ product .properties ['title' ]} order status could not be checked"
484
+ if e .response is not None and e .response .status_code == 400 :
485
+ raise ValidationError .from_error (e , msg ) from e
486
+ else :
487
+ raise DownloadError .from_error (e , msg ) from e
465
488
466
489
result_type = config_on_success .get ("result_type" , "json" )
467
490
result_entry = config_on_success .get ("results_entry" )
@@ -626,6 +649,8 @@ def download_request(
626
649
if fs_path is not None :
627
650
ext = Path (product .filename ).suffix
628
651
path = Path (fs_path ).with_suffix (ext )
652
+ if "ORDERABLE" in path .stem and product .properties .get ("title" ):
653
+ path = path .with_stem (sanitize (product .properties ["title" ]))
629
654
630
655
with open (path , "wb" ) as fhandle :
631
656
for chunk in chunk_iterator :
@@ -961,17 +986,21 @@ def _stream_download(
961
986
auth = None
962
987
963
988
s = requests .Session ()
964
- self .stream = s .request (
965
- req_method ,
966
- req_url ,
967
- stream = True ,
968
- auth = auth ,
969
- params = params ,
970
- headers = USER_AGENT ,
971
- timeout = DEFAULT_STREAM_REQUESTS_TIMEOUT ,
972
- verify = ssl_verify ,
973
- ** req_kwargs ,
974
- )
989
+ try :
990
+ self .stream = s .request (
991
+ req_method ,
992
+ req_url ,
993
+ stream = True ,
994
+ auth = auth ,
995
+ params = params ,
996
+ headers = USER_AGENT ,
997
+ timeout = DEFAULT_STREAM_REQUESTS_TIMEOUT ,
998
+ verify = ssl_verify ,
999
+ ** req_kwargs ,
1000
+ )
1001
+ except requests .exceptions .MissingSchema :
1002
+ # location is not a valid url -> product is not available yet
1003
+ raise NotAvailableError ("Product is not available yet" )
975
1004
try :
976
1005
self .stream .raise_for_status ()
977
1006
except requests .exceptions .Timeout as exc :
0 commit comments