Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions importer/api/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Meta:
"overwrite_existing_layer",
"skip_existing_layers",
"source",
"custom",
)

base_file = serializers.FileField()
Expand All @@ -25,3 +26,4 @@ class Meta:
overwrite_existing_layer = serializers.BooleanField(required=False, default=False)
skip_existing_layers = serializers.BooleanField(required=False, default=False)
source = serializers.CharField(required=False, default="upload")
custom = serializers.JSONField(required=False, default={})
1 change: 1 addition & 0 deletions importer/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def create(self, request, *args, **kwargs):
try:
# cloning data into a local folder
extracted_params, _data = handler.extract_params_from_data(_data)
extracted_params.update({"custom": _data.pop("custom", {})})
if _file:
storage_manager, asset, files = self._handle_asset(
request, asset_dir, storage_manager, _data, handler
Expand Down
3 changes: 3 additions & 0 deletions importer/celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,20 +342,23 @@ def create_geonode_resource(

handler = import_string(handler_module_path)()
_overwrite = _exec.input_params.get("overwrite_existing_layer")
_custom = _exec.input_params.get("custom")

if _overwrite:
resource = handler.overwrite_geonode_resource(
layer_name=layer_name,
alternate=alternate,
execution_id=execution_id,
asset=_asset,
custom=_custom,
)
else:
resource = handler.create_geonode_resource(
layer_name=layer_name,
alternate=alternate,
execution_id=execution_id,
asset=_asset,
custom=_custom,
)

if _overwrite:
Expand Down
2 changes: 1 addition & 1 deletion importer/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def publish_resources(resources: List[str], catalog, store, workspace):
return NotImplementedError

def create_geonode_resource(
self, layer_name, alternate, execution_id, resource_type: Dataset = Dataset
self, layer_name, alternate, execution_id, resource_type: Dataset = Dataset, custom={}
):
"""
Base function to create the resource into geonode. Each handler can specify
Expand Down
5 changes: 4 additions & 1 deletion importer/handlers/common/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def create_geonode_resource(
execution_id: str,
resource_type: Dataset = Dataset,
asset=None,
custom={},
):
"""
Base function to create the resource into geonode. Each handler can specify
Expand Down Expand Up @@ -348,6 +349,7 @@ def create_geonode_resource(
owner=_exec.user,
asset=asset,
),
custom=custom,
)

saved_dataset.refresh_from_db()
Expand All @@ -369,6 +371,7 @@ def overwrite_geonode_resource(
execution_id: str,
resource_type: Dataset = Dataset,
asset=None,
custom={},
):

_exec = self._get_execution_request_object(execution_id)
Expand Down Expand Up @@ -397,7 +400,7 @@ def overwrite_geonode_resource(
f"The dataset required {alternate} does not exists, but an overwrite is required, the resource will be created"
)
return self.create_geonode_resource(
layer_name, alternate, execution_id, resource_type, asset
layer_name, alternate, execution_id, resource_type, asset, custom
)
elif not dataset.exists() and not _overwrite:
logger.warning(
Expand Down
5 changes: 4 additions & 1 deletion importer/handlers/common/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def create_geonode_resource(
execution_id: str,
resource_type: ResourceBase = ResourceBase,
asset=None,
custom={},
):
"""
Creating geonode base resource
Expand All @@ -195,6 +196,7 @@ def create_geonode_resource(
defaults=self.generate_resource_payload(
layer_name, alternate, asset, _exec, None, **params
),
custom=custom,
)
resource_manager.set_thumbnail(None, instance=resource)

Expand Down Expand Up @@ -252,6 +254,7 @@ def overwrite_geonode_resource(
execution_id: str,
resource_type: Dataset = ResourceBase,
asset=None,
custom={},
):
_exec = self._get_execution_request_object(execution_id)
resource = resource_type.objects.filter(alternate__icontains=alternate, owner=_exec.user)
Expand All @@ -275,7 +278,7 @@ def overwrite_geonode_resource(
f"The dataset required {alternate} does not exists, but an overwrite is required, the resource will be created"
)
return self.create_geonode_resource(
layer_name, alternate, execution_id, resource_type, asset
layer_name, alternate, execution_id, resource_type, asset, custom=custom,
)
elif not resource.exists() and not _overwrite:
logger.warning(
Expand Down
5 changes: 4 additions & 1 deletion importer/handlers/common/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ def create_geonode_resource(
execution_id: str,
resource_type: Dataset = Dataset,
asset=None,
custom={},
):
"""
Base function to create the resource into geonode. Each handler can specify
Expand Down Expand Up @@ -597,6 +598,7 @@ def create_geonode_resource(
defaults=self.generate_resource_payload(
layer_name, alternate, asset, _exec, workspace
),
custom=custom,
)

saved_dataset.refresh_from_db()
Expand Down Expand Up @@ -631,6 +633,7 @@ def overwrite_geonode_resource(
execution_id: str,
resource_type: Dataset = Dataset,
asset=None,
custom={},
):
_exec = self._get_execution_request_object(execution_id)

Expand Down Expand Up @@ -662,7 +665,7 @@ def overwrite_geonode_resource(
f"The dataset required {alternate} does not exists, but an overwrite is required, the resource will be created"
)
return self.create_geonode_resource(
layer_name, alternate, execution_id, resource_type, asset
layer_name, alternate, execution_id, resource_type, asset, custom=custom,
)
elif not dataset.exists() and not _overwrite:
logger.warning(
Expand Down
3 changes: 2 additions & 1 deletion importer/handlers/remote/tiles3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ def create_geonode_resource(
execution_id: str,
resource_type: Dataset = ResourceBase,
asset=None,
custom={},
):
resource = super().create_geonode_resource(
layer_name, alternate, execution_id, resource_type, asset
layer_name, alternate, execution_id, resource_type, asset, custom=custom
)
_exec = orchestrator.get_execution_object(exec_id=execution_id)
try:
Expand Down
3 changes: 2 additions & 1 deletion importer/handlers/remote/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ def create_geonode_resource(
execution_id: str,
resource_type: Dataset = ...,
asset=None,
custom={},
):
"""
Use the default RemoteResourceHandler to create the geonode resource
after that, we assign the bbox and re-generate the thumbnail
"""
resource = super().create_geonode_resource(
layer_name, alternate, execution_id, Dataset, asset
layer_name, alternate, execution_id, Dataset, asset, custom=custom,
)
_exec = orchestrator.get_execution_object(execution_id)
remote_bbox = _exec.input_params.get("bbox")
Expand Down
3 changes: 2 additions & 1 deletion importer/handlers/tiles3d/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,14 @@ def create_geonode_resource(
execution_id: str,
resource_type: Dataset = ...,
asset=None,
custom={},
):
# we want just the tileset.json as location of the asset
asset.location = [path for path in asset.location if path.endswith(".json")]
asset.save()

resource = super().create_geonode_resource(
layer_name, alternate, execution_id, ResourceBase, asset
layer_name, alternate, execution_id, ResourceBase, asset, custom=custom,
)

# fixing-up bbox for the 3dtile object
Expand Down
Loading