Skip to content

Commit 91cb45c

Browse files
committed
[Fixes #286] Allow to add metadata when uploading a resource
1 parent 3231f58 commit 91cb45c

File tree

10 files changed

+25
-7
lines changed

10 files changed

+25
-7
lines changed

importer/api/serializer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Meta:
1616
"overwrite_existing_layer",
1717
"skip_existing_layers",
1818
"source",
19+
"custom",
1920
)
2021

2122
base_file = serializers.FileField()
@@ -25,3 +26,4 @@ class Meta:
2526
overwrite_existing_layer = serializers.BooleanField(required=False, default=False)
2627
skip_existing_layers = serializers.BooleanField(required=False, default=False)
2728
source = serializers.CharField(required=False, default="upload")
29+
custom = serializers.JSONField(required=False, default={})

importer/api/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def create(self, request, *args, **kwargs):
136136
try:
137137
# cloning data into a local folder
138138
extracted_params, _data = handler.extract_params_from_data(_data)
139+
extracted_params.update({"custom": _data.pop("custom", {})})
139140
if _file:
140141
storage_manager, asset, files = self._handle_asset(
141142
request, asset_dir, storage_manager, _data, handler

importer/celery_tasks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,20 +342,23 @@ def create_geonode_resource(
342342

343343
handler = import_string(handler_module_path)()
344344
_overwrite = _exec.input_params.get("overwrite_existing_layer")
345+
_custom = _exec.input_params.get("custom")
345346

346347
if _overwrite:
347348
resource = handler.overwrite_geonode_resource(
348349
layer_name=layer_name,
349350
alternate=alternate,
350351
execution_id=execution_id,
351352
asset=_asset,
353+
custom=_custom,
352354
)
353355
else:
354356
resource = handler.create_geonode_resource(
355357
layer_name=layer_name,
356358
alternate=alternate,
357359
execution_id=execution_id,
358360
asset=_asset,
361+
custom=_custom,
359362
)
360363

361364
if _overwrite:

importer/handlers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def publish_resources(resources: List[str], catalog, store, workspace):
236236
return NotImplementedError
237237

238238
def create_geonode_resource(
239-
self, layer_name, alternate, execution_id, resource_type: Dataset = Dataset
239+
self, layer_name, alternate, execution_id, resource_type: Dataset = Dataset, custom={}
240240
):
241241
"""
242242
Base function to create the resource into geonode. Each handler can specify

importer/handlers/common/raster.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ def create_geonode_resource(
312312
execution_id: str,
313313
resource_type: Dataset = Dataset,
314314
asset=None,
315+
custom={},
315316
):
316317
"""
317318
Base function to create the resource into geonode. Each handler can specify
@@ -348,6 +349,7 @@ def create_geonode_resource(
348349
owner=_exec.user,
349350
asset=asset,
350351
),
352+
custom=custom,
351353
)
352354

353355
saved_dataset.refresh_from_db()
@@ -369,6 +371,7 @@ def overwrite_geonode_resource(
369371
execution_id: str,
370372
resource_type: Dataset = Dataset,
371373
asset=None,
374+
custom={},
372375
):
373376

374377
_exec = self._get_execution_request_object(execution_id)
@@ -397,7 +400,7 @@ def overwrite_geonode_resource(
397400
f"The dataset required {alternate} does not exists, but an overwrite is required, the resource will be created"
398401
)
399402
return self.create_geonode_resource(
400-
layer_name, alternate, execution_id, resource_type, asset
403+
layer_name, alternate, execution_id, resource_type, asset, custom
401404
)
402405
elif not dataset.exists() and not _overwrite:
403406
logger.warning(

importer/handlers/common/remote.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def create_geonode_resource(
179179
execution_id: str,
180180
resource_type: ResourceBase = ResourceBase,
181181
asset=None,
182+
custom={},
182183
):
183184
"""
184185
Creating geonode base resource
@@ -195,6 +196,7 @@ def create_geonode_resource(
195196
defaults=self.generate_resource_payload(
196197
layer_name, alternate, asset, _exec, None, **params
197198
),
199+
custom=custom,
198200
)
199201
resource_manager.set_thumbnail(None, instance=resource)
200202

@@ -252,6 +254,7 @@ def overwrite_geonode_resource(
252254
execution_id: str,
253255
resource_type: Dataset = ResourceBase,
254256
asset=None,
257+
custom={},
255258
):
256259
_exec = self._get_execution_request_object(execution_id)
257260
resource = resource_type.objects.filter(alternate__icontains=alternate, owner=_exec.user)
@@ -275,7 +278,7 @@ def overwrite_geonode_resource(
275278
f"The dataset required {alternate} does not exists, but an overwrite is required, the resource will be created"
276279
)
277280
return self.create_geonode_resource(
278-
layer_name, alternate, execution_id, resource_type, asset
281+
layer_name, alternate, execution_id, resource_type, asset, custom=custom,
279282
)
280283
elif not resource.exists() and not _overwrite:
281284
logger.warning(

importer/handlers/common/vector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ def create_geonode_resource(
568568
execution_id: str,
569569
resource_type: Dataset = Dataset,
570570
asset=None,
571+
custom={},
571572
):
572573
"""
573574
Base function to create the resource into geonode. Each handler can specify
@@ -597,6 +598,7 @@ def create_geonode_resource(
597598
defaults=self.generate_resource_payload(
598599
layer_name, alternate, asset, _exec, workspace
599600
),
601+
custom=custom,
600602
)
601603

602604
saved_dataset.refresh_from_db()
@@ -631,6 +633,7 @@ def overwrite_geonode_resource(
631633
execution_id: str,
632634
resource_type: Dataset = Dataset,
633635
asset=None,
636+
custom={},
634637
):
635638
_exec = self._get_execution_request_object(execution_id)
636639

@@ -662,7 +665,7 @@ def overwrite_geonode_resource(
662665
f"The dataset required {alternate} does not exists, but an overwrite is required, the resource will be created"
663666
)
664667
return self.create_geonode_resource(
665-
layer_name, alternate, execution_id, resource_type, asset
668+
layer_name, alternate, execution_id, resource_type, asset, custom=custom,
666669
)
667670
elif not dataset.exists() and not _overwrite:
668671
logger.warning(

importer/handlers/remote/tiles3d.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ def create_geonode_resource(
6161
execution_id: str,
6262
resource_type: Dataset = ResourceBase,
6363
asset=None,
64+
custom={},
6465
):
6566
resource = super().create_geonode_resource(
66-
layer_name, alternate, execution_id, resource_type, asset
67+
layer_name, alternate, execution_id, resource_type, asset, custom=custom
6768
)
6869
_exec = orchestrator.get_execution_object(exec_id=execution_id)
6970
try:

importer/handlers/remote/wms.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ def create_geonode_resource(
115115
execution_id: str,
116116
resource_type: Dataset = ...,
117117
asset=None,
118+
custom={},
118119
):
119120
"""
120121
Use the default RemoteResourceHandler to create the geonode resource
121122
after that, we assign the bbox and re-generate the thumbnail
122123
"""
123124
resource = super().create_geonode_resource(
124-
layer_name, alternate, execution_id, Dataset, asset
125+
layer_name, alternate, execution_id, Dataset, asset, custom=custom,
125126
)
126127
_exec = orchestrator.get_execution_object(execution_id)
127128
remote_bbox = _exec.input_params.get("bbox")

importer/handlers/tiles3d/handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,14 @@ def create_geonode_resource(
216216
execution_id: str,
217217
resource_type: Dataset = ...,
218218
asset=None,
219+
custom={},
219220
):
220221
# we want just the tileset.json as location of the asset
221222
asset.location = [path for path in asset.location if path.endswith(".json")]
222223
asset.save()
223224

224225
resource = super().create_geonode_resource(
225-
layer_name, alternate, execution_id, ResourceBase, asset
226+
layer_name, alternate, execution_id, ResourceBase, asset, custom=custom,
226227
)
227228

228229
# fixing-up bbox for the 3dtile object

0 commit comments

Comments
 (0)