Skip to content

Commit

Permalink
add support for copying files after download
Browse files Browse the repository at this point in the history
  • Loading branch information
aperrin66 committed Feb 6, 2025
1 parent fc1b706 commit 9de7575
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions geospaas_rest_api/processing_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ class Meta:

@classmethod
def get_signature(cls, parameters):
tasks = [tasks_core.download.signature()]
tasks = [
tasks_core.download.signature(),
tasks_core.copy.signature(kwargs={'copy_to': parameters.get('copy_to', None)}),
]

# only unarchive if cropping is needed
bounding_box = parameters.get('bounding_box', None)
Expand All @@ -104,8 +107,10 @@ def check_parameters(parameters):
- dataset_id: integer
- bounding_box: 4-elements list
"""
if not set(parameters).issubset(set(('dataset_id', 'bounding_box', 'publish'))):
raise ValidationError("The download action accepts only one parameter: 'dataset_id'")
allowed_parameters = ('dataset_id', 'bounding_box', 'publish', 'copy_to')
if not set(parameters).issubset(set(allowed_parameters)):
raise ValidationError(
f"The download action accepts only the following parameters: {allowed_parameters}")
if not isinstance(parameters['dataset_id'], int):
raise ValidationError("'dataset_id' must be an integer")
if ('bounding_box' in parameters and
Expand All @@ -115,6 +120,8 @@ def check_parameters(parameters):
"west, north, east, south")
if ('publish' in parameters and not isinstance(parameters['publish'], bool)):
raise ValidationError("'publish' must be a boolean")
if 'copy_to' in parameters and not isinstance(parameters['copy_to'], str):
raise ValidationError("'copy_to' must be a string")
return parameters

@staticmethod
Expand All @@ -136,6 +143,7 @@ def get_signature(cls, parameters):
if conversion_format == 'idf':
return celery.chain(
tasks_core.download.signature(),
tasks_core.copy.signature(copy_to=parameters.get('copy_to', None)),
tasks_core.unarchive.signature(),
tasks_core.crop.signature(
kwargs={'bounding_box': parameters.get('bounding_box', None)}),
Expand All @@ -145,6 +153,7 @@ def get_signature(cls, parameters):
elif conversion_format == 'syntool':
syntool_tasks = [
tasks_core.download.signature(),
tasks_core.copy.signature(kwargs={'copy_to': parameters.get('copy_to', None)}),
tasks_core.unarchive.signature(),
tasks_core.crop.signature(
kwargs={'bounding_box': parameters.get('bounding_box', None)}),
Expand Down Expand Up @@ -181,7 +190,8 @@ def check_parameters(parameters):
'skip_check',
'converter_options',
'remove_downloaded',
'ttl')
'ttl',
'copy_to')
if not set(parameters).issubset(set(accepted_keys)):
raise ValidationError(
f"The convert action accepts only these parameters: {', '.join(accepted_keys)}")
Expand All @@ -208,6 +218,9 @@ def check_parameters(parameters):
parameters['ttl'] is None or isinstance(parameters['ttl'], dict))):
raise ValidationError("'ttl' should be a dictionary or None")

if 'copy_to' in parameters and not isinstance(parameters['copy_to'], str):
raise ValidationError("'copy_to' must be a string")

return parameters

@staticmethod
Expand Down

0 comments on commit 9de7575

Please sign in to comment.