From e253dda6216810963d151fd18a0b5d0ccc50d8ef Mon Sep 17 00:00:00 2001 From: Mattia Date: Thu, 17 Oct 2024 17:45:15 +0200 Subject: [PATCH] [Fixes #12657] Refactor supported types --- geonode/resource/enumerator.py | 1 + geonode/settings.py | 50 -------------------- geonode/storage/tests.py | 17 ------- geonode/tests/test_utils.py | 37 +-------------- geonode/upload/api/views.py | 2 +- geonode/upload/celery_tasks.py | 6 +-- geonode/upload/handlers/apps.py | 18 ------- geonode/upload/handlers/base.py | 2 +- geonode/upload/handlers/common/metadata.py | 3 +- geonode/upload/handlers/common/raster.py | 2 +- geonode/upload/handlers/common/remote.py | 4 +- geonode/upload/handlers/common/vector.py | 6 +-- geonode/upload/handlers/csv/handler.py | 22 ++++++--- geonode/upload/handlers/geojson/handler.py | 26 ++++++++-- geonode/upload/handlers/geotiff/handler.py | 37 ++++++++++++--- geonode/upload/handlers/gpkg/handler.py | 13 +++-- geonode/upload/handlers/kml/handler.py | 20 ++++++-- geonode/upload/handlers/shapefile/handler.py | 16 ++++--- geonode/upload/handlers/sld/handler.py | 21 +++----- geonode/upload/handlers/tiles3d/handler.py | 16 ++++--- geonode/upload/handlers/xml/handler.py | 21 +++----- geonode/upload/orchestrator.py | 3 ++ geonode/upload/tests/unit/test_task.py | 10 ++-- geonode/upload/utils.py | 2 + geonode/utils.py | 26 ++++++++-- 25 files changed, 174 insertions(+), 207 deletions(-) diff --git a/geonode/resource/enumerator.py b/geonode/resource/enumerator.py index 8ace0c22100..4d96b0aa291 100644 --- a/geonode/resource/enumerator.py +++ b/geonode/resource/enumerator.py @@ -22,6 +22,7 @@ class ExecutionRequestAction(enum.Enum): IMPORT = _("import") + UPLOAD = _("upload") CREATE = _("create") COPY = _("copy") DELETE = _("delete") diff --git a/geonode/settings.py b/geonode/settings.py index 03807b16dbc..2be775af909 100644 --- a/geonode/settings.py +++ b/geonode/settings.py @@ -2240,56 +2240,6 @@ def get_geonode_catalogue_service(): "document_upload", ) -SUPPORTED_DATASET_FILE_TYPES = [ - { - "id": "shp", - "label": "ESRI Shapefile", - "format": "vector", - "ext": ["shp"], - "requires": ["shp", "prj", "dbf", "shx"], - "optional": ["xml", "sld"], - }, - { - "id": "tiff", - "label": "GeoTIFF", - "format": "raster", - "ext": ["tiff", "tif", "geotiff", "geotif"], - "mimeType": ["image/tiff"], - "optional": ["xml", "sld"], - }, - { - "id": "csv", - "label": "Comma Separated Value (CSV)", - "format": "vector", - "ext": ["csv"], - "mimeType": ["text/csv"], - "optional": ["xml", "sld"], - }, - { - "id": "zip", - "label": "Zip Archive", - "format": "archive", - "ext": ["zip"], - "mimeType": ["application/zip"], - "optional": ["xml", "sld"], - }, - { - "id": "xml", - "label": "XML Metadata File", - "format": "metadata", - "ext": ["xml"], - "mimeType": ["application/json"], - "needsFiles": ["shp", "prj", "dbf", "shx", "csv", "tiff", "zip", "sld"], - }, - { - "id": "sld", - "label": "Styled Layer Descriptor (SLD)", - "format": "metadata", - "ext": ["sld"], - "mimeType": ["application/json"], - "needsFiles": ["shp", "prj", "dbf", "shx", "csv", "tiff", "zip", "xml"], - }, -] INSTALLED_APPS += ( "dynamic_models", # "importer", diff --git a/geonode/storage/tests.py b/geonode/storage/tests.py index 43adc794ffa..9a4401c36d5 100644 --- a/geonode/storage/tests.py +++ b/geonode/storage/tests.py @@ -573,23 +573,6 @@ def test_zip_file_should_correctly_index_file_extensions(self): # extensions found more than once get indexed self.assertIsNotNone(_files.get("csv_file_1")) - @override_settings( - SUPPORTED_DATASET_FILE_TYPES=[ - {"id": "kmz", "label": "kmz", "format": "vector", "ext": ["kmz"]}, - {"id": "kml", "label": "kml", "format": "vector", "ext": ["kml"]}, - ] - ) - def test_zip_file_should_correctly_recognize_main_extension_with_kmz(self): - # reinitiate the storage manager with the zip file - storage_manager = self.sut( - remote_files={"base_file": os.path.join(f"{self.project_root}", "tests/data/Italy.kmz")} - ) - storage_manager.clone_remote_files() - - self.assertIsNotNone(storage_manager.data_retriever.temporary_folder) - _files = storage_manager.get_retrieved_paths() - self.assertTrue("doc.kml" in _files.get("base_file"), msg=f"files available: {_files}") - def test_zip_file_should_correctly_recognize_main_extension_with_shp(self): # zipping files storage_manager = self.sut(remote_files=self.local_files_paths) diff --git a/geonode/tests/test_utils.py b/geonode/tests/test_utils.py index e39600b60f2..20ff8b67f4c 100644 --- a/geonode/tests/test_utils.py +++ b/geonode/tests/test_utils.py @@ -18,7 +18,6 @@ ######################################################################### import copy from unittest import TestCase -from django.test import override_settings from unittest.mock import patch from datetime import datetime, timedelta @@ -32,8 +31,7 @@ from geonode.geoserver.helpers import set_attributes from geonode.tests.base import GeoNodeBaseTestSupport from geonode.br.management.commands.utils.utils import ignore_time -from geonode.utils import copy_tree, get_supported_datasets_file_types, bbox_to_wkt -from geonode import settings +from geonode.utils import copy_tree, bbox_to_wkt class TestCopyTree(GeoNodeBaseTestSupport): @@ -205,39 +203,6 @@ def setUp(self): }, ] - @override_settings( - ADDITIONAL_DATASET_FILE_TYPES=[ - {"id": "dummy_type", "label": "Dummy Type", "format": "dummy", "ext": ["dummy"]}, - ] - ) - def test_should_append_additional_type_if_config_is_provided(self): - prev_count = len(settings.SUPPORTED_DATASET_FILE_TYPES) - supported_types = get_supported_datasets_file_types() - supported_keys = [t.get("id") for t in supported_types] - self.assertIn("dummy_type", supported_keys) - self.assertEqual(len(supported_keys), prev_count + 1) - - @override_settings( - ADDITIONAL_DATASET_FILE_TYPES=[ - { - "id": "shp", - "label": "Replaced type", - "format": "vector", - "ext": ["shp"], - "requires": ["shp", "prj", "dbf", "shx"], - "optional": ["xml", "sld"], - }, - ] - ) - def test_should_replace_the_type_id_if_already_exists(self): - prev_count = len(settings.SUPPORTED_DATASET_FILE_TYPES) - supported_types = get_supported_datasets_file_types() - supported_keys = [t.get("id") for t in supported_types] - self.assertIn("shp", supported_keys) - self.assertEqual(len(supported_keys), prev_count) - shp_type = [t for t in supported_types if t["id"] == "shp"][0] - self.assertEqual(shp_type["label"], "Replaced type") - class TestRegionsCrossingDateLine(TestCase): def setUp(self): diff --git a/geonode/upload/api/views.py b/geonode/upload/api/views.py index 53f86bab425..8261668b08c 100644 --- a/geonode/upload/api/views.py +++ b/geonode/upload/api/views.py @@ -191,7 +191,7 @@ def create(self, request, *args, **kwargs): self.validate_upload(request, storage_manager) - action = ExecutionRequestAction.IMPORT.value + action = ExecutionRequestAction.UPLOAD.value input_params = { **{"files": files, "handler_module_path": str(handler)}, diff --git a/geonode/upload/celery_tasks.py b/geonode/upload/celery_tasks.py index 6a270d70133..2aeb9170cf2 100644 --- a/geonode/upload/celery_tasks.py +++ b/geonode/upload/celery_tasks.py @@ -90,7 +90,7 @@ def import_orchestrator( step="start_import", layer_name=None, alternate=None, - action=exa.IMPORT.value, + action=exa.UPLOAD.value, **kwargs, ): """ @@ -179,7 +179,7 @@ def import_resource(self, execution_id, /, handler_module_path, action, **kwargs call_rollback_function( execution_id, handlers_module_path=handler_module_path, - prev_action=exa.IMPORT.value, + prev_action=exa.UPLOAD.value, layer=None, alternate=None, error=e, @@ -309,7 +309,7 @@ def create_geonode_resource( layer_name: Optional[str] = None, alternate: Optional[str] = None, handler_module_path: str = None, - action: str = exa.IMPORT.value, + action: str = exa.UPLOAD.value, **kwargs, ): """ diff --git a/geonode/upload/handlers/apps.py b/geonode/upload/handlers/apps.py index 7e50e59aae5..72e26b7c585 100644 --- a/geonode/upload/handlers/apps.py +++ b/geonode/upload/handlers/apps.py @@ -41,21 +41,3 @@ def run_setup_hooks(*args, **kwargs): for item in _handlers: item.register() logger.info(f"The following handlers have been registered: {', '.join(available_handlers)}") - - _available_settings = [ - import_string(module_path)().supported_file_extension_config - for module_path in available_handlers - if import_string(module_path)().supported_file_extension_config - ] - # injecting the new config required for FE - supported_type = [] - supported_type.extend(_available_settings) - if not getattr(settings, "ADDITIONAL_DATASET_FILE_TYPES", None): - setattr(settings, "ADDITIONAL_DATASET_FILE_TYPES", supported_type) - elif "gpkg" not in [x.get("id") for x in settings.ADDITIONAL_DATASET_FILE_TYPES]: - settings.ADDITIONAL_DATASET_FILE_TYPES.extend(supported_type) - setattr( - settings, - "ADDITIONAL_DATASET_FILE_TYPES", - settings.ADDITIONAL_DATASET_FILE_TYPES, - ) diff --git a/geonode/upload/handlers/base.py b/geonode/upload/handlers/base.py index c0199b61f48..1c2407bf6c1 100644 --- a/geonode/upload/handlers/base.py +++ b/geonode/upload/handlers/base.py @@ -47,7 +47,7 @@ class BaseHandler(ABC): REGISTRY = [] TASKS = { - exa.IMPORT.value: (), + exa.UPLOAD.value: (), exa.COPY.value: (), exa.DELETE.value: (), exa.UPDATE.value: (), diff --git a/geonode/upload/handlers/common/metadata.py b/geonode/upload/handlers/common/metadata.py index 923183f07b9..9da9a13a08d 100644 --- a/geonode/upload/handlers/common/metadata.py +++ b/geonode/upload/handlers/common/metadata.py @@ -17,7 +17,6 @@ # ######################################################################### import logging -from geonode.resource.enumerator import ExecutionRequestAction as exa from geonode.upload.handlers.base import BaseHandler from geonode.upload.handlers.utils import UploadSourcesEnum from geonode.upload.models import ResourceHandlerInfo @@ -37,7 +36,7 @@ class MetadataFileHandler(BaseHandler): """ TASKS = { - exa.IMPORT.value: ("start_import", "geonode.upload.import_resource"), + ira.RESOURCE_METADATA_UPLOAD.value: ("start_import", "geonode.upload.import_resource"), ira.ROLLBACK.value: ( "start_rollback", "geonode.upload.rollback", diff --git a/geonode/upload/handlers/common/raster.py b/geonode/upload/handlers/common/raster.py index a4eac9c79e1..1c00e8fa067 100644 --- a/geonode/upload/handlers/common/raster.py +++ b/geonode/upload/handlers/common/raster.py @@ -310,7 +310,7 @@ def import_resource(self, files: dict, execution_id: str, **kwargs) -> str: "geonode.upload.import_resource", layer_name, alternate, - exa.IMPORT.value, + exa.UPLOAD.value, ) ) return layer_name, alternate, execution_id diff --git a/geonode/upload/handlers/common/remote.py b/geonode/upload/handlers/common/remote.py index 2185f653013..2366ec0f473 100755 --- a/geonode/upload/handlers/common/remote.py +++ b/geonode/upload/handlers/common/remote.py @@ -48,7 +48,7 @@ class BaseRemoteResourceHandler(BaseHandler): """ TASKS = { - exa.IMPORT.value: ( + exa.UPLOAD.value: ( "start_import", "geonode.upload.import_resource", "geonode.upload.create_geonode_resource", @@ -163,7 +163,7 @@ def import_resource(self, files: dict, execution_id: str, **kwargs) -> str: "geonode.upload.import_resource", layer_name, alternate, - exa.IMPORT.value, + exa.UPLOAD.value, ) ) return layer_name, alternate, execution_id diff --git a/geonode/upload/handlers/common/vector.py b/geonode/upload/handlers/common/vector.py index e1303d077b7..c38f871f1f2 100644 --- a/geonode/upload/handlers/common/vector.py +++ b/geonode/upload/handlers/common/vector.py @@ -851,7 +851,7 @@ def import_next_step( actual_step, layer_name, alternate, - exa.IMPORT.value, + exa.UPLOAD.value, ) import_orchestrator.apply_async(task_params, kwargs) @@ -859,7 +859,7 @@ def import_next_step( call_rollback_function( execution_id, handlers_module_path=handlers_module_path, - prev_action=exa.IMPORT.value, + prev_action=exa.UPLOAD.value, layer=layer_name, alternate=alternate, error=e, @@ -927,7 +927,7 @@ def import_with_ogr2ogr( call_rollback_function( execution_id, handlers_module_path=handler_module_path, - prev_action=exa.IMPORT.value, + prev_action=exa.UPLOAD.value, layer=original_name, alternate=alternate, error=e, diff --git a/geonode/upload/handlers/csv/handler.py b/geonode/upload/handlers/csv/handler.py index 2a1187795f8..7cea75d5e38 100644 --- a/geonode/upload/handlers/csv/handler.py +++ b/geonode/upload/handlers/csv/handler.py @@ -41,7 +41,7 @@ class CSVFileHandler(BaseVectorFileHandler): """ TASKS = { - exa.IMPORT.value: ( + exa.UPLOAD.value: ( "start_import", "geonode.upload.import_resource", "geonode.upload.publish_resource", @@ -58,6 +58,12 @@ class CSVFileHandler(BaseVectorFileHandler): "start_rollback", "geonode.upload.rollback", ), + ira.REPLACE.value: ( + "start_import", + "geonode.upload.import_resource", + "geonode.upload.publish_resource", + "geonode.upload.create_geonode_resource", + ), } possible_geometry_column_name = ["geom", "geometry", "wkt_geom", "the_geom"] @@ -69,11 +75,15 @@ class CSVFileHandler(BaseVectorFileHandler): def supported_file_extension_config(self): return { "id": "csv", - "label": "CSV", - "format": "vector", - "mimeType": ["text/csv"], - "ext": ["csv"], - "optional": ["sld", "xml"], + "formats": [ + { + "label": "CSV", + "required_ext": ["csv"], + "optional_ext": ["sld", "xml"], + } + ], + "actions": list(self.TASKS.keys()), + "type": "vector", } @staticmethod diff --git a/geonode/upload/handlers/geojson/handler.py b/geonode/upload/handlers/geojson/handler.py index 2a738eb37ab..c1e960de243 100644 --- a/geonode/upload/handlers/geojson/handler.py +++ b/geonode/upload/handlers/geojson/handler.py @@ -37,7 +37,7 @@ class GeoJsonFileHandler(BaseVectorFileHandler): """ TASKS = { - exa.IMPORT.value: ( + exa.UPLOAD.value: ( "start_import", "geonode.upload.import_resource", "geonode.upload.publish_resource", @@ -54,16 +54,32 @@ class GeoJsonFileHandler(BaseVectorFileHandler): "start_rollback", "geonode.upload.rollback", ), + ira.REPLACE.value: ( + "start_import", + "geonode.upload.import_resource", + "geonode.upload.publish_resource", + "geonode.upload.create_geonode_resource", + ), } @property def supported_file_extension_config(self): return { "id": "geojson", - "label": "GeoJSON", - "format": "vector", - "ext": ["json", "geojson"], - "optional": ["xml", "sld"], + "formats": [ + { + "label": "GeoJSON", + "required_ext": ["geojson"], + "optional_ext": ["sld", "xml"], + }, + { + "label": "GeoJSON", + "required_ext": ["json"], + "optional_ext": ["sld", "xml"], + }, + ], + "actions": list(self.TASKS.keys()), + "type": "vector", } @staticmethod diff --git a/geonode/upload/handlers/geotiff/handler.py b/geonode/upload/handlers/geotiff/handler.py index cd869273287..62da37bde1b 100644 --- a/geonode/upload/handlers/geotiff/handler.py +++ b/geonode/upload/handlers/geotiff/handler.py @@ -35,7 +35,7 @@ class GeoTiffFileHandler(BaseRasterFileHandler): """ TASKS = { - exa.IMPORT.value: ( + exa.UPLOAD.value: ( "start_import", "geonode.upload.import_resource", "geonode.upload.publish_resource", @@ -51,17 +51,42 @@ class GeoTiffFileHandler(BaseRasterFileHandler): "start_rollback", "geonode.upload.rollback", ), + ira.REPLACE.value: ( + "start_import", + "geonode.upload.import_resource", + "geonode.upload.publish_resource", + "geonode.upload.create_geonode_resource", + ), } @property def supported_file_extension_config(self): return { "id": "tiff", - "label": "GeoTIFF", - "format": "raster", - "ext": ["tiff", "tif", "geotiff", "geotif"], - "mimeType": ["image/tiff"], - "optional": ["xml", "sld"], + "formats": [ + { + "label": "TIFF", + "required_ext": ["tiff"], + "optional_ext": ["xml", "sld"], + }, + { + "label": "TIF", + "required_ext": ["tif"], + "optional_ext": ["xml", "sld"], + }, + { + "label": "GeoTIFF", + "required_ext": ["geotiff"], + "optional_ext": ["xml", "sld"], + }, + { + "label": "GeoTIF", + "required_ext": ["geotif"], + "optional_ext": ["xml", "sld"], + }, + ], + "actions": list(self.TASKS.keys()), + "type": "raster", } @staticmethod diff --git a/geonode/upload/handlers/gpkg/handler.py b/geonode/upload/handlers/gpkg/handler.py index 2ba6f74655f..860d0ef8212 100644 --- a/geonode/upload/handlers/gpkg/handler.py +++ b/geonode/upload/handlers/gpkg/handler.py @@ -38,7 +38,7 @@ class GPKGFileHandler(BaseVectorFileHandler): """ TASKS = { - exa.IMPORT.value: ( + exa.UPLOAD.value: ( "start_import", "geonode.upload.import_resource", "geonode.upload.publish_resource", @@ -61,9 +61,14 @@ class GPKGFileHandler(BaseVectorFileHandler): def supported_file_extension_config(self): return { "id": "gpkg", - "label": "GeoPackage", - "format": "vector", - "ext": ["gpkg"], + "formats": [ + { + "label": "GeoPackage", + "required_ext": ["gpkg"], + } + ], + "actions": list(self.TASKS.keys()), + "type": "vector", } @property diff --git a/geonode/upload/handlers/kml/handler.py b/geonode/upload/handlers/kml/handler.py index 7361b232727..34079fb517a 100644 --- a/geonode/upload/handlers/kml/handler.py +++ b/geonode/upload/handlers/kml/handler.py @@ -38,7 +38,7 @@ class KMLFileHandler(BaseVectorFileHandler): """ TASKS = { - exa.IMPORT.value: ( + exa.UPLOAD.value: ( "start_import", "geonode.upload.import_resource", "geonode.upload.publish_resource", @@ -55,15 +55,27 @@ class KMLFileHandler(BaseVectorFileHandler): "start_rollback", "geonode.upload.rollback", ), + ira.REPLACE.value: ( + "start_import", + "geonode.upload.import_resource", + "geonode.upload.publish_resource", + "geonode.upload.create_geonode_resource", + ), } @property def supported_file_extension_config(self): return { "id": "kml", - "label": "KML/KMZ", - "format": "vector", - "ext": ["kml", "kmz"], + "formats": [ + {"label": "KML", "required_ext": ["kml"]}, + { + "label": "KMZ", + "required_ext": ["kmz"], + }, + ], + "actions": list(self.TASKS.keys()), + "type": "vector", } @property diff --git a/geonode/upload/handlers/shapefile/handler.py b/geonode/upload/handlers/shapefile/handler.py index c5109ef227b..7b64bc3623b 100644 --- a/geonode/upload/handlers/shapefile/handler.py +++ b/geonode/upload/handlers/shapefile/handler.py @@ -41,7 +41,7 @@ class ShapeFileHandler(BaseVectorFileHandler): """ TASKS = { - exa.IMPORT.value: ( + exa.UPLOAD.value: ( "start_import", "geonode.upload.import_resource", "geonode.upload.publish_resource", @@ -64,11 +64,15 @@ class ShapeFileHandler(BaseVectorFileHandler): def supported_file_extension_config(self): return { "id": "shp", - "label": "ESRI Shapefile", - "format": "vector", - "ext": ["shp"], - "requires": ["shp", "prj", "dbf", "shx"], - "optional": ["xml", "sld", "cpg", "cst"], + "formats": [ + { + "label": "ESRI Shapefile", + "required_ext": ["shp", "prj", "dbf", "shx"], + "optional_ext": ["xml", "sld", "cpg", "cst"], + } + ], + "actions": list(self.TASKS.keys()), + "type": "vector", } @staticmethod diff --git a/geonode/upload/handlers/sld/handler.py b/geonode/upload/handlers/sld/handler.py index c6cd25863a4..4a50a17c449 100644 --- a/geonode/upload/handlers/sld/handler.py +++ b/geonode/upload/handlers/sld/handler.py @@ -36,21 +36,14 @@ class SLDFileHandler(MetadataFileHandler): def supported_file_extension_config(self): return { "id": "sld", - "label": "Styled Layer Descriptor (SLD)", - "format": "metadata", - "ext": ["sld"], - "mimeType": ["application/json"], - "needsFiles": [ - "shp", - "prj", - "dbf", - "shx", - "csv", - "tiff", - "zip", - "xml", - "geojson", + "formats": [ + { + "label": "Styled Layer Descriptor 1.0, 1.1 (SLD)", + "required_ext": ["sld"], + } ], + "actions": list(self.TASKS.keys()), + "type": "metadata", } @staticmethod diff --git a/geonode/upload/handlers/tiles3d/handler.py b/geonode/upload/handlers/tiles3d/handler.py index 0222a63fdd7..378f57580ca 100755 --- a/geonode/upload/handlers/tiles3d/handler.py +++ b/geonode/upload/handlers/tiles3d/handler.py @@ -43,7 +43,7 @@ class Tiles3DFileHandler(BaseVectorFileHandler): """ TASKS = { - exa.IMPORT.value: ( + exa.UPLOAD.value: ( "start_import", "geonode.upload.import_resource", "geonode.upload.create_geonode_resource", @@ -62,10 +62,14 @@ class Tiles3DFileHandler(BaseVectorFileHandler): def supported_file_extension_config(self): return { "id": "3dtiles", - "label": "3D Tiles", - "format": "vector", - "ext": ["json"], - "optional": ["xml", "sld"], + "formats": [ + { + "label": "3D Tiles", + "required_ext": ["zip"], + } + ], + "actions": list(self.TASKS.keys()), + "type": "vector", } @staticmethod @@ -198,7 +202,7 @@ def import_resource(self, files: dict, execution_id: str, **kwargs) -> str: "geonode.upload.import_resource", layer_name, alternate, - exa.IMPORT.value, + exa.UPLOAD.value, ) ) return layer_name, alternate, execution_id diff --git a/geonode/upload/handlers/xml/handler.py b/geonode/upload/handlers/xml/handler.py index a6f6340689f..9a383362542 100644 --- a/geonode/upload/handlers/xml/handler.py +++ b/geonode/upload/handlers/xml/handler.py @@ -36,21 +36,14 @@ class XMLFileHandler(MetadataFileHandler): def supported_file_extension_config(self): return { "id": "xml", - "label": "XML Metadata File", - "format": "metadata", - "ext": ["xml"], - "mimeType": ["application/json"], - "needsFiles": [ - "shp", - "prj", - "dbf", - "shx", - "csv", - "tiff", - "zip", - "sld", - "geojson", + "formats": [ + { + "label": "XML Metadata File (XML - ISO, FGDC, ebRIM, Dublin Core)", + "required_ext": ["xml"], + } ], + "actions": list(self.TASKS.keys()), + "type": "metadata", } @staticmethod diff --git a/geonode/upload/orchestrator.py b/geonode/upload/orchestrator.py index 1611e4f6d91..3a40549ac20 100644 --- a/geonode/upload/orchestrator.py +++ b/geonode/upload/orchestrator.py @@ -48,6 +48,9 @@ class ImportOrchestrator: """ + def get_handler_registry(self): + return BaseHandler.get_registry() + def get_handler(self, _data) -> Optional[BaseHandler]: """ If is part of the supported format, return the handler which can handle the import diff --git a/geonode/upload/tests/unit/test_task.py b/geonode/upload/tests/unit/test_task.py index 1f374da4112..09a90881620 100644 --- a/geonode/upload/tests/unit/test_task.py +++ b/geonode/upload/tests/unit/test_task.py @@ -120,7 +120,7 @@ def test_import_resource_should_rase_exp_if_is_invalid( with self.assertRaises(InvalidInputFileException) as _exc: import_resource( str(exec_id), - action=ExecutionRequestAction.IMPORT.value, + action=ExecutionRequestAction.UPLOAD.value, handler_module_path="geonode.upload.handlers.gpkg.handler.GPKGFileHandler", ) expected_msg = f"Invalid format type. Request: {str(exec_id)}" @@ -151,7 +151,7 @@ def test_import_resource_should_work( import_resource( str(exec_id), resource_type="gpkg", - action=ExecutionRequestAction.IMPORT.value, + action=ExecutionRequestAction.UPLOAD.value, handler_module_path="geonode.upload.handlers.gpkg.handler.GPKGFileHandler", ) @@ -178,7 +178,7 @@ def test_publish_resource_should_work( step_name="publish_resource", layer_name="dataset3", alternate="alternate_dataset3", - action=ExecutionRequestAction.IMPORT.value, + action=ExecutionRequestAction.UPLOAD.value, handler_module_path="geonode.upload.handlers.gpkg.handler.GPKGFileHandler", ) @@ -224,7 +224,7 @@ def test_publish_resource_if_overwrite_should_call_the_publishing( step_name="publish_resource", layer_name="dataset3", alternate="alternate_dataset3", - action=ExecutionRequestAction.IMPORT.value, + action=ExecutionRequestAction.UPLOAD.value, handler_module_path="geonode.upload.handlers.gpkg.handler.GPKGFileHandler", ) @@ -276,7 +276,7 @@ def test_publish_resource_if_overwrite_should_not_call_the_publishing( step_name="publish_resource", layer_name="dataset3", alternate="alternate_dataset3", - action=ExecutionRequestAction.IMPORT.value, + action=ExecutionRequestAction.UPLOAD.value, handler_module_path="geonode.upload.handlers.gpkg.handler.GPKGFileHandler", ) diff --git a/geonode/upload/utils.py b/geonode/upload/utils.py index a82147b6253..911526fd8ab 100644 --- a/geonode/upload/utils.py +++ b/geonode/upload/utils.py @@ -50,6 +50,8 @@ def get_max_upload_parallelism_limit(slug): class ImporterRequestAction(enum.Enum): ROLLBACK = _("rollback") + RESOURCE_METADATA_UPLOAD = _("resource_metadata_upload") + REPLACE = _("replace") def error_handler(exc, exec_id=None): diff --git a/geonode/utils.py b/geonode/utils.py index 514061ca7f0..a400fc7c787 100755 --- a/geonode/utils.py +++ b/geonode/utils.py @@ -1706,13 +1706,33 @@ def get_geonode_app_types(): def get_supported_datasets_file_types(): from django.conf import settings as gn_settings + from geonode.upload.orchestrator import orchestrator """ Return a list of all supported file type in geonode If one of the type provided in the custom type exists in the default is going to override it """ - default_types = settings.SUPPORTED_DATASET_FILE_TYPES + _available_settings = [ + module().supported_file_extension_config + for module in orchestrator.get_handler_registry() + if module().supported_file_extension_config + ] + # injecting the new config required for FE + default_types = [ + { + "id": "zip", + "formats": { + "label": "Zip Archive", + "required_ext": ["zip"], + "optional_ext": ["xml", "sld"], + }, + "action": ["upload"], + "type": "archive", + } + ] + default_types.extend(_available_settings) + types_module = ( gn_settings.ADDITIONAL_DATASET_FILE_TYPES if hasattr(gn_settings, "ADDITIONAL_DATASET_FILE_TYPES") else [] ) @@ -1730,7 +1750,7 @@ def get_supported_datasets_file_types(): (weight[1], resource_type) for resource_type in supported_types for weight in formats_order - if resource_type.get("format") in weight[0] + if resource_type.get("type") in weight[0] ) # Flatten the list @@ -1738,7 +1758,7 @@ def get_supported_datasets_file_types(): other_resource_types = [ resource_type for resource_type in supported_types - if resource_type.get("format") is None or resource_type.get("format") not in [f[0] for f in formats_order] + if resource_type.get("type") is None or resource_type.get("type") not in [f[0] for f in formats_order] ] return ordered_resource_types + other_resource_types