From 4faae746673c6c0877d20abbd01b198ad2977519 Mon Sep 17 00:00:00 2001 From: Mattia Date: Wed, 16 Oct 2024 18:05:56 +0200 Subject: [PATCH 1/9] [Fixes #12657] Rename ACTIONS into TASKS --- geonode/upload/handlers/README.md | 4 ++-- geonode/upload/handlers/base.py | 10 +++++----- geonode/upload/handlers/common/metadata.py | 2 +- geonode/upload/handlers/common/raster.py | 2 +- geonode/upload/handlers/common/remote.py | 2 +- geonode/upload/handlers/common/test_remote.py | 8 ++++---- geonode/upload/handlers/common/vector.py | 2 +- geonode/upload/handlers/csv/handler.py | 2 +- geonode/upload/handlers/csv/tests.py | 8 ++++---- geonode/upload/handlers/geojson/handler.py | 2 +- geonode/upload/handlers/geojson/tests.py | 8 ++++---- geonode/upload/handlers/geotiff/handler.py | 2 +- geonode/upload/handlers/geotiff/tests.py | 8 ++++---- geonode/upload/handlers/gpkg/handler.py | 2 +- geonode/upload/handlers/gpkg/tests.py | 8 ++++---- geonode/upload/handlers/kml/handler.py | 2 +- geonode/upload/handlers/kml/tests.py | 8 ++++---- geonode/upload/handlers/remote/tests/test_3dtiles.py | 8 ++++---- geonode/upload/handlers/remote/tests/test_wms.py | 8 ++++---- geonode/upload/handlers/shapefile/handler.py | 2 +- geonode/upload/handlers/shapefile/tests.py | 8 ++++---- geonode/upload/handlers/sld/tests.py | 4 ++-- geonode/upload/handlers/tiles3d/handler.py | 2 +- geonode/upload/handlers/tiles3d/tests.py | 8 ++++---- geonode/upload/handlers/xml/tests.py | 4 ++-- 25 files changed, 62 insertions(+), 62 deletions(-) diff --git a/geonode/upload/handlers/README.md b/geonode/upload/handlers/README.md index 255c2b08331..1c85117d55e 100644 --- a/geonode/upload/handlers/README.md +++ b/geonode/upload/handlers/README.md @@ -32,7 +32,7 @@ class BaseVectorFileHandler(BaseHandler): It must provide the task_lists required to comple the upload """ - ACTIONS = { + TASKS = { exa.IMPORT.value: (), # define the list of the step (celery task) needed to execute the action for the resource exa.COPY.value: (), exa.DELETE.value: (), @@ -242,7 +242,7 @@ class NewVectorFileHandler(BaseVectorFileHandler): It must provide the task_lists required to comple the upload """ - ACTIONS = { + TASKS = { exa.IMPORT.value: ( "start_import", "geonode.upload.import_resource", diff --git a/geonode/upload/handlers/base.py b/geonode/upload/handlers/base.py index 5afb57bbe76..c0199b61f48 100644 --- a/geonode/upload/handlers/base.py +++ b/geonode/upload/handlers/base.py @@ -46,7 +46,7 @@ class BaseHandler(ABC): REGISTRY = [] - ACTIONS = { + TASKS = { exa.IMPORT.value: (), exa.COPY.value: (), exa.DELETE.value: (), @@ -70,9 +70,9 @@ def get_registry(cls): @classmethod def get_task_list(cls, action) -> tuple: - if action not in cls.ACTIONS: + if action not in cls.TASKS: raise Exception("The requested action is not implemented yet") - return cls.ACTIONS.get(action) + return cls.TASKS.get(action) @property def default_geometry_column_name(self): @@ -140,7 +140,7 @@ def can_do(action) -> bool: the Handler must be ready to handle them. If is not in the actual flow the already in place flow is followd """ - return action in BaseHandler.ACTIONS + return action in BaseHandler.TASKS @staticmethod def extract_params_from_data(_data): @@ -300,7 +300,7 @@ def overwrite_resourcehandlerinfo( return self.create_resourcehandlerinfo(handler_module_path, resource, execution_id, **kwargs) def rollback(self, exec_id, rollback_from_step, action_to_rollback, *args, **kwargs): - steps = self.ACTIONS.get(action_to_rollback) + steps = self.TASKS.get(action_to_rollback) if rollback_from_step not in steps: logger.info(f"Step not found {rollback_from_step}, skipping") diff --git a/geonode/upload/handlers/common/metadata.py b/geonode/upload/handlers/common/metadata.py index 35374a42a59..923183f07b9 100644 --- a/geonode/upload/handlers/common/metadata.py +++ b/geonode/upload/handlers/common/metadata.py @@ -36,7 +36,7 @@ class MetadataFileHandler(BaseHandler): It must provide the task_lists required to comple the upload """ - ACTIONS = { + TASKS = { exa.IMPORT.value: ("start_import", "geonode.upload.import_resource"), ira.ROLLBACK.value: ( "start_rollback", diff --git a/geonode/upload/handlers/common/raster.py b/geonode/upload/handlers/common/raster.py index 14dd5d40971..a4eac9c79e1 100644 --- a/geonode/upload/handlers/common/raster.py +++ b/geonode/upload/handlers/common/raster.py @@ -107,7 +107,7 @@ def can_do(action) -> bool: This endpoint will return True or False if with the info provided the handler is able to handle the file or not """ - return action in BaseHandler.ACTIONS + return action in BaseHandler.TASKS @staticmethod def create_error_log(exc, task_name, *args): diff --git a/geonode/upload/handlers/common/remote.py b/geonode/upload/handlers/common/remote.py index 6cc827f0e15..2185f653013 100755 --- a/geonode/upload/handlers/common/remote.py +++ b/geonode/upload/handlers/common/remote.py @@ -47,7 +47,7 @@ class BaseRemoteResourceHandler(BaseHandler): As first implementation only remote 3dtiles are supported """ - ACTIONS = { + TASKS = { exa.IMPORT.value: ( "start_import", "geonode.upload.import_resource", diff --git a/geonode/upload/handlers/common/test_remote.py b/geonode/upload/handlers/common/test_remote.py index 89430d618b9..157bccb9c54 100644 --- a/geonode/upload/handlers/common/test_remote.py +++ b/geonode/upload/handlers/common/test_remote.py @@ -82,16 +82,16 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.import_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 3) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 3) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( "start_copy", "geonode.upload.copy_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["copy"]), 2) - self.assertTupleEqual(expected, self.handler.ACTIONS["copy"]) + self.assertEqual(len(self.handler.TASKS["copy"]), 2) + self.assertTupleEqual(expected, self.handler.TASKS["copy"]) def test_is_valid_should_raise_exception_if_the_url_is_invalid(self): with self.assertRaises(ImportException) as _exc: diff --git a/geonode/upload/handlers/common/vector.py b/geonode/upload/handlers/common/vector.py index ddf755d55a1..e1303d077b7 100644 --- a/geonode/upload/handlers/common/vector.py +++ b/geonode/upload/handlers/common/vector.py @@ -117,7 +117,7 @@ def can_do(action) -> bool: This endpoint will return True or False if with the info provided the handler is able to handle the file or not """ - return action in BaseHandler.ACTIONS + return action in BaseHandler.TASKS @staticmethod def create_error_log(exc, task_name, *args): diff --git a/geonode/upload/handlers/csv/handler.py b/geonode/upload/handlers/csv/handler.py index 1e3483a25a8..2a1187795f8 100644 --- a/geonode/upload/handlers/csv/handler.py +++ b/geonode/upload/handlers/csv/handler.py @@ -40,7 +40,7 @@ class CSVFileHandler(BaseVectorFileHandler): It must provide the task_lists required to comple the upload """ - ACTIONS = { + TASKS = { exa.IMPORT.value: ( "start_import", "geonode.upload.import_resource", diff --git a/geonode/upload/handlers/csv/tests.py b/geonode/upload/handlers/csv/tests.py index dc75996bef4..b23c7dec6b2 100644 --- a/geonode/upload/handlers/csv/tests.py +++ b/geonode/upload/handlers/csv/tests.py @@ -57,8 +57,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 4) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( @@ -68,8 +68,8 @@ def test_task_list_is_the_expected_one_geojson(self): "geonode.upload.publish_resource", "geonode.upload.copy_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["copy"]), 5) - self.assertTupleEqual(expected, self.handler.ACTIONS["copy"]) + self.assertEqual(len(self.handler.TASKS["copy"]), 5) + self.assertTupleEqual(expected, self.handler.TASKS["copy"]) def test_is_valid_should_raise_exception_if_the_csv_is_invalid(self): with self.assertRaises(InvalidCSVException) as _exc: diff --git a/geonode/upload/handlers/geojson/handler.py b/geonode/upload/handlers/geojson/handler.py index 6060be709bf..2a738eb37ab 100644 --- a/geonode/upload/handlers/geojson/handler.py +++ b/geonode/upload/handlers/geojson/handler.py @@ -36,7 +36,7 @@ class GeoJsonFileHandler(BaseVectorFileHandler): It must provide the task_lists required to comple the upload """ - ACTIONS = { + TASKS = { exa.IMPORT.value: ( "start_import", "geonode.upload.import_resource", diff --git a/geonode/upload/handlers/geojson/tests.py b/geonode/upload/handlers/geojson/tests.py index acf5913e74e..105c91608a3 100644 --- a/geonode/upload/handlers/geojson/tests.py +++ b/geonode/upload/handlers/geojson/tests.py @@ -54,8 +54,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 4) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_task_list_is_the_expected_one_copy(self): expected = ( @@ -65,8 +65,8 @@ def test_task_list_is_the_expected_one_copy(self): "geonode.upload.publish_resource", "geonode.upload.copy_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["copy"]), 5) - self.assertTupleEqual(expected, self.handler.ACTIONS["copy"]) + self.assertEqual(len(self.handler.TASKS["copy"]), 5) + self.assertTupleEqual(expected, self.handler.TASKS["copy"]) def test_is_valid_should_raise_exception_if_the_parallelism_is_met(self): parallelism, created = UploadParallelismLimit.objects.get_or_create(slug="default_max_parallel_uploads") diff --git a/geonode/upload/handlers/geotiff/handler.py b/geonode/upload/handlers/geotiff/handler.py index e49584a9639..cd869273287 100644 --- a/geonode/upload/handlers/geotiff/handler.py +++ b/geonode/upload/handlers/geotiff/handler.py @@ -34,7 +34,7 @@ class GeoTiffFileHandler(BaseRasterFileHandler): It must provide the task_lists required to comple the upload """ - ACTIONS = { + TASKS = { exa.IMPORT.value: ( "start_import", "geonode.upload.import_resource", diff --git a/geonode/upload/handlers/geotiff/tests.py b/geonode/upload/handlers/geotiff/tests.py index 882236409a9..6e0c769c346 100644 --- a/geonode/upload/handlers/geotiff/tests.py +++ b/geonode/upload/handlers/geotiff/tests.py @@ -48,8 +48,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 4) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_task_list_is_the_expected_one_copy(self): expected = ( @@ -58,8 +58,8 @@ def test_task_list_is_the_expected_one_copy(self): "geonode.upload.publish_resource", "geonode.upload.copy_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["copy"]), 4) - self.assertTupleEqual(expected, self.handler.ACTIONS["copy"]) + self.assertEqual(len(self.handler.TASKS["copy"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["copy"]) def test_is_valid_should_raise_exception_if_the_parallelism_is_met(self): parallelism, created = UploadParallelismLimit.objects.get_or_create(slug="default_max_parallel_uploads") diff --git a/geonode/upload/handlers/gpkg/handler.py b/geonode/upload/handlers/gpkg/handler.py index 1742d12c9e1..2ba6f74655f 100644 --- a/geonode/upload/handlers/gpkg/handler.py +++ b/geonode/upload/handlers/gpkg/handler.py @@ -37,7 +37,7 @@ class GPKGFileHandler(BaseVectorFileHandler): It must provide the task_lists required to comple the upload """ - ACTIONS = { + TASKS = { exa.IMPORT.value: ( "start_import", "geonode.upload.import_resource", diff --git a/geonode/upload/handlers/gpkg/tests.py b/geonode/upload/handlers/gpkg/tests.py index 32770d5c393..0bae64fe295 100644 --- a/geonode/upload/handlers/gpkg/tests.py +++ b/geonode/upload/handlers/gpkg/tests.py @@ -55,8 +55,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 4) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( @@ -66,8 +66,8 @@ def test_task_list_is_the_expected_one_geojson(self): "geonode.upload.publish_resource", "geonode.upload.copy_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["copy"]), 5) - self.assertTupleEqual(expected, self.handler.ACTIONS["copy"]) + self.assertEqual(len(self.handler.TASKS["copy"]), 5) + self.assertTupleEqual(expected, self.handler.TASKS["copy"]) def test_is_valid_should_raise_exception_if_the_gpkg_is_invalid(self): with self.assertRaises(InvalidGeopackageException) as _exc: diff --git a/geonode/upload/handlers/kml/handler.py b/geonode/upload/handlers/kml/handler.py index 8ab7f9d00a4..7361b232727 100644 --- a/geonode/upload/handlers/kml/handler.py +++ b/geonode/upload/handlers/kml/handler.py @@ -37,7 +37,7 @@ class KMLFileHandler(BaseVectorFileHandler): It must provide the task_lists required to comple the upload """ - ACTIONS = { + TASKS = { exa.IMPORT.value: ( "start_import", "geonode.upload.import_resource", diff --git a/geonode/upload/handlers/kml/tests.py b/geonode/upload/handlers/kml/tests.py index 9fe0a873c47..28eb25be8f1 100644 --- a/geonode/upload/handlers/kml/tests.py +++ b/geonode/upload/handlers/kml/tests.py @@ -49,8 +49,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 4) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( @@ -60,8 +60,8 @@ def test_task_list_is_the_expected_one_geojson(self): "geonode.upload.publish_resource", "geonode.upload.copy_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["copy"]), 5) - self.assertTupleEqual(expected, self.handler.ACTIONS["copy"]) + self.assertEqual(len(self.handler.TASKS["copy"]), 5) + self.assertTupleEqual(expected, self.handler.TASKS["copy"]) def test_is_valid_should_raise_exception_if_the_kml_is_invalid(self): with self.assertRaises(InvalidKmlException) as _exc: diff --git a/geonode/upload/handlers/remote/tests/test_3dtiles.py b/geonode/upload/handlers/remote/tests/test_3dtiles.py index 675b65e92f4..0ad54a9a989 100644 --- a/geonode/upload/handlers/remote/tests/test_3dtiles.py +++ b/geonode/upload/handlers/remote/tests/test_3dtiles.py @@ -83,16 +83,16 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.import_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 3) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 3) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( "start_copy", "geonode.upload.copy_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["copy"]), 2) - self.assertTupleEqual(expected, self.handler.ACTIONS["copy"]) + self.assertEqual(len(self.handler.TASKS["copy"]), 2) + self.assertTupleEqual(expected, self.handler.TASKS["copy"]) def test_is_valid_should_raise_exception_if_the_url_is_invalid(self): with self.assertRaises(ImportException) as _exc: diff --git a/geonode/upload/handlers/remote/tests/test_wms.py b/geonode/upload/handlers/remote/tests/test_wms.py index 5330343b405..60ed0130125 100644 --- a/geonode/upload/handlers/remote/tests/test_wms.py +++ b/geonode/upload/handlers/remote/tests/test_wms.py @@ -96,16 +96,16 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.import_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 3) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 3) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( "start_copy", "geonode.upload.copy_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["copy"]), 2) - self.assertTupleEqual(expected, self.handler.ACTIONS["copy"]) + self.assertEqual(len(self.handler.TASKS["copy"]), 2) + self.assertTupleEqual(expected, self.handler.TASKS["copy"]) def test_is_valid_should_raise_exception_if_the_url_is_invalid(self): with self.assertRaises(ImportException) as _exc: diff --git a/geonode/upload/handlers/shapefile/handler.py b/geonode/upload/handlers/shapefile/handler.py index d93214a03bc..c5109ef227b 100644 --- a/geonode/upload/handlers/shapefile/handler.py +++ b/geonode/upload/handlers/shapefile/handler.py @@ -40,7 +40,7 @@ class ShapeFileHandler(BaseVectorFileHandler): It must provide the task_lists required to comple the upload """ - ACTIONS = { + TASKS = { exa.IMPORT.value: ( "start_import", "geonode.upload.import_resource", diff --git a/geonode/upload/handlers/shapefile/tests.py b/geonode/upload/handlers/shapefile/tests.py index f643306bf7e..3462face165 100644 --- a/geonode/upload/handlers/shapefile/tests.py +++ b/geonode/upload/handlers/shapefile/tests.py @@ -62,8 +62,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 4) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_copy_task_list_is_the_expected_one(self): expected = ( @@ -73,8 +73,8 @@ def test_copy_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.copy_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["copy"]), 5) - self.assertTupleEqual(expected, self.handler.ACTIONS["copy"]) + self.assertEqual(len(self.handler.TASKS["copy"]), 5) + self.assertTupleEqual(expected, self.handler.TASKS["copy"]) def test_is_valid_should_raise_exception_if_the_parallelism_is_met(self): parallelism, created = UploadParallelismLimit.objects.get_or_create(slug="default_max_parallel_uploads") diff --git a/geonode/upload/handlers/sld/tests.py b/geonode/upload/handlers/sld/tests.py index 1864ba2dee1..b88026636ec 100644 --- a/geonode/upload/handlers/sld/tests.py +++ b/geonode/upload/handlers/sld/tests.py @@ -59,8 +59,8 @@ def test_task_list_is_the_expected_one(self): "start_import", "geonode.upload.import_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 2) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 2) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_is_valid_should_raise_exception_if_the_sld_is_invalid(self): with self.assertRaises(InvalidSldException) as _exc: diff --git a/geonode/upload/handlers/tiles3d/handler.py b/geonode/upload/handlers/tiles3d/handler.py index 9cb2db7e426..0222a63fdd7 100755 --- a/geonode/upload/handlers/tiles3d/handler.py +++ b/geonode/upload/handlers/tiles3d/handler.py @@ -42,7 +42,7 @@ class Tiles3DFileHandler(BaseVectorFileHandler): It must provide the task_lists required to comple the upload """ - ACTIONS = { + TASKS = { exa.IMPORT.value: ( "start_import", "geonode.upload.import_resource", diff --git a/geonode/upload/handlers/tiles3d/tests.py b/geonode/upload/handlers/tiles3d/tests.py index 4db2b54d6b0..7951be07065 100755 --- a/geonode/upload/handlers/tiles3d/tests.py +++ b/geonode/upload/handlers/tiles3d/tests.py @@ -58,16 +58,16 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.import_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 3) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 3) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_task_list_is_the_expected_one_copy(self): expected = ( "start_copy", "geonode.upload.copy_geonode_resource", ) - self.assertEqual(len(self.handler.ACTIONS["copy"]), 2) - self.assertTupleEqual(expected, self.handler.ACTIONS["copy"]) + self.assertEqual(len(self.handler.TASKS["copy"]), 2) + self.assertTupleEqual(expected, self.handler.TASKS["copy"]) def test_is_valid_should_raise_exception_if_the_parallelism_is_met(self): parallelism, created = UploadParallelismLimit.objects.get_or_create(slug="default_max_parallel_uploads") diff --git a/geonode/upload/handlers/xml/tests.py b/geonode/upload/handlers/xml/tests.py index af9916a1fc8..716b8db65e9 100644 --- a/geonode/upload/handlers/xml/tests.py +++ b/geonode/upload/handlers/xml/tests.py @@ -58,8 +58,8 @@ def test_task_list_is_the_expected_one(self): "start_import", "geonode.upload.import_resource", ) - self.assertEqual(len(self.handler.ACTIONS["import"]), 2) - self.assertTupleEqual(expected, self.handler.ACTIONS["import"]) + self.assertEqual(len(self.handler.TASKS["import"]), 2) + self.assertTupleEqual(expected, self.handler.TASKS["import"]) def test_is_valid_should_raise_exception_if_the_xml_is_invalid(self): with self.assertRaises(InvalidXmlException) as _exc: From e253dda6216810963d151fd18a0b5d0ccc50d8ef Mon Sep 17 00:00:00 2001 From: Mattia Date: Thu, 17 Oct 2024 17:45:15 +0200 Subject: [PATCH 2/9] [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 From 9a46a38dd27e2ef698aee43fcd3c4dd13deeae67 Mon Sep 17 00:00:00 2001 From: Mattia Date: Thu, 17 Oct 2024 18:08:17 +0200 Subject: [PATCH 3/9] [Fixes #12657] Refactor supported types --- geonode/upload/handlers/common/metadata.py | 9 --------- geonode/upload/handlers/remote/tiles3d.py | 4 ++++ geonode/upload/handlers/shapefile/handler.py | 6 ++++++ geonode/upload/handlers/sld/handler.py | 9 +++++++++ geonode/upload/handlers/xml/handler.py | 8 ++++++++ geonode/upload/utils.py | 1 + geonode/utils.py | 2 +- 7 files changed, 29 insertions(+), 10 deletions(-) diff --git a/geonode/upload/handlers/common/metadata.py b/geonode/upload/handlers/common/metadata.py index 9da9a13a08d..3138be1e9dc 100644 --- a/geonode/upload/handlers/common/metadata.py +++ b/geonode/upload/handlers/common/metadata.py @@ -21,7 +21,6 @@ from geonode.upload.handlers.utils import UploadSourcesEnum from geonode.upload.models import ResourceHandlerInfo from geonode.upload.handlers.xml.serializer import MetadataFileSerializer -from geonode.upload.utils import ImporterRequestAction as ira from geonode.upload.orchestrator import orchestrator from django.shortcuts import get_object_or_404 from geonode.layers.models import Dataset @@ -35,14 +34,6 @@ class MetadataFileHandler(BaseHandler): It must provide the task_lists required to comple the upload """ - TASKS = { - ira.RESOURCE_METADATA_UPLOAD.value: ("start_import", "geonode.upload.import_resource"), - ira.ROLLBACK.value: ( - "start_rollback", - "geonode.upload.rollback", - ), - } - @staticmethod def can_handle(_data) -> bool: """ diff --git a/geonode/upload/handlers/remote/tiles3d.py b/geonode/upload/handlers/remote/tiles3d.py index 94f04199abc..c47df255e2a 100644 --- a/geonode/upload/handlers/remote/tiles3d.py +++ b/geonode/upload/handlers/remote/tiles3d.py @@ -33,6 +33,10 @@ class RemoteTiles3DResourceHandler(BaseRemoteResourceHandler, Tiles3DFileHandler): + @property + def supported_file_extension_config(self): + return {} + @staticmethod def has_serializer(data) -> bool: if "url" in data and "3dtiles" in data.get("type", "").lower(): diff --git a/geonode/upload/handlers/shapefile/handler.py b/geonode/upload/handlers/shapefile/handler.py index 7b64bc3623b..000ca9e156f 100644 --- a/geonode/upload/handlers/shapefile/handler.py +++ b/geonode/upload/handlers/shapefile/handler.py @@ -58,6 +58,12 @@ class ShapeFileHandler(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 diff --git a/geonode/upload/handlers/sld/handler.py b/geonode/upload/handlers/sld/handler.py index 4a50a17c449..3efb55e3516 100644 --- a/geonode/upload/handlers/sld/handler.py +++ b/geonode/upload/handlers/sld/handler.py @@ -22,6 +22,7 @@ from geonode.upload.handlers.common.metadata import MetadataFileHandler from geonode.upload.handlers.sld.exceptions import InvalidSldException from owslib.etree import etree as dlxml +from geonode.upload.utils import ImporterRequestAction as ira logger = logging.getLogger("importer") @@ -32,6 +33,14 @@ class SLDFileHandler(MetadataFileHandler): It must provide the task_lists required to comple the upload """ + TASKS = { + ira.RESOURCE_SLD_UPLOAD.value: ("start_import", "geonode.upload.import_resource"), + ira.ROLLBACK.value: ( + "start_rollback", + "geonode.upload.rollback", + ), + } + @property def supported_file_extension_config(self): return { diff --git a/geonode/upload/handlers/xml/handler.py b/geonode/upload/handlers/xml/handler.py index 9a383362542..1e000b0081c 100644 --- a/geonode/upload/handlers/xml/handler.py +++ b/geonode/upload/handlers/xml/handler.py @@ -22,6 +22,7 @@ from geonode.upload.handlers.common.metadata import MetadataFileHandler from geonode.upload.handlers.xml.exceptions import InvalidXmlException from owslib.etree import etree as dlxml +from geonode.upload.utils import ImporterRequestAction as ira logger = logging.getLogger("importer") @@ -32,6 +33,13 @@ class XMLFileHandler(MetadataFileHandler): It must provide the task_lists required to comple the upload """ + TASKS = { + ira.RESOURCE_METADATA_UPLOAD.value: ("start_import", "geonode.upload.import_resource"), + ira.ROLLBACK.value: ( + "start_rollback", + "geonode.upload.rollback", + ), + } @property def supported_file_extension_config(self): return { diff --git a/geonode/upload/utils.py b/geonode/upload/utils.py index 911526fd8ab..0dbcb246864 100644 --- a/geonode/upload/utils.py +++ b/geonode/upload/utils.py @@ -51,6 +51,7 @@ def get_max_upload_parallelism_limit(slug): class ImporterRequestAction(enum.Enum): ROLLBACK = _("rollback") RESOURCE_METADATA_UPLOAD = _("resource_metadata_upload") + RESOURCE_SLD_UPLOAD = _("resource_sld_upload") REPLACE = _("replace") diff --git a/geonode/utils.py b/geonode/utils.py index a400fc7c787..3cf9a71fb99 100755 --- a/geonode/utils.py +++ b/geonode/utils.py @@ -1727,7 +1727,7 @@ def get_supported_datasets_file_types(): "required_ext": ["zip"], "optional_ext": ["xml", "sld"], }, - "action": ["upload"], + "action": ["upload", "replace"], "type": "archive", } ] From ec76dff1690070d716150bf43d298c50fb582915 Mon Sep 17 00:00:00 2001 From: Mattia Date: Fri, 18 Oct 2024 10:47:31 +0200 Subject: [PATCH 4/9] [Fixes #12657] Refactor supported type, fix data retriever and refactor handlers configuration --- geonode/upload/api/serializer.py | 4 +- geonode/upload/api/views.py | 8 +--- geonode/upload/handlers/common/metadata.py | 13 +------ geonode/upload/handlers/common/raster.py | 18 +++------ geonode/upload/handlers/common/remote.py | 2 +- geonode/upload/handlers/common/serializer.py | 4 +- geonode/upload/handlers/common/vector.py | 38 +++++++++++++++++-- geonode/upload/handlers/csv/handler.py | 27 ------------- geonode/upload/handlers/csv/tests.py | 2 +- geonode/upload/handlers/geojson/handler.py | 28 -------------- geonode/upload/handlers/geojson/tests.py | 2 +- geonode/upload/handlers/geotiff/handler.py | 2 +- geonode/upload/handlers/geotiff/tests.py | 2 +- geonode/upload/handlers/gpkg/handler.py | 6 +-- geonode/upload/handlers/gpkg/tests.py | 2 +- geonode/upload/handlers/kml/handler.py | 6 --- geonode/upload/handlers/kml/tests.py | 2 +- geonode/upload/handlers/shapefile/handler.py | 38 +++++-------------- .../upload/handlers/shapefile/serializer.py | 4 +- geonode/upload/handlers/shapefile/tests.py | 2 +- geonode/upload/handlers/sld/handler.py | 6 +-- geonode/upload/handlers/sld/tests.py | 2 +- geonode/upload/handlers/tiles3d/handler.py | 2 +- geonode/upload/handlers/utils.py | 7 ---- geonode/upload/handlers/xml/handler.py | 7 ++-- geonode/upload/handlers/xml/serializer.py | 4 +- geonode/upload/handlers/xml/tests.py | 2 +- geonode/upload/orchestrator.py | 19 +++++++--- .../upload/tests/unit/test_orchestrator.py | 2 +- geonode/utils.py | 23 +++++++---- 30 files changed, 112 insertions(+), 172 deletions(-) diff --git a/geonode/upload/api/serializer.py b/geonode/upload/api/serializer.py index 4657ddb9f3d..9d807c44bb1 100644 --- a/geonode/upload/api/serializer.py +++ b/geonode/upload/api/serializer.py @@ -34,7 +34,7 @@ class Meta: "sld_file", "store_spatial_files", "skip_existing_layers", - "source", + "action", ) base_file = serializers.FileField() @@ -42,7 +42,7 @@ class Meta: sld_file = serializers.FileField(required=False) store_spatial_files = serializers.BooleanField(required=False, default=True) skip_existing_layers = serializers.BooleanField(required=False, default=False) - source = serializers.CharField(required=False, default="upload") + action = serializers.CharField(required=True) class OverwriteImporterSerializer(ImporterSerializer): diff --git a/geonode/upload/api/views.py b/geonode/upload/api/views.py index 8261668b08c..d3122d0d99b 100644 --- a/geonode/upload/api/views.py +++ b/geonode/upload/api/views.py @@ -176,7 +176,6 @@ def create(self, request, *args, **kwargs): ) handler = orchestrator.get_handler(_data) - # not file but handler means that is a remote resource if handler: asset = None @@ -191,8 +190,6 @@ def create(self, request, *args, **kwargs): self.validate_upload(request, storage_manager) - action = ExecutionRequestAction.UPLOAD.value - input_params = { **{"files": files, "handler_module_path": str(handler)}, **extracted_params, @@ -205,7 +202,7 @@ def create(self, request, *args, **kwargs): "asset_module_path": f"{asset.__module__}.{asset.__class__.__name__}", } ) - + action = input_params.get("action") execution_id = orchestrator.create_execution_request( user=request.user, func_name=next(iter(handler.get_task_list(action=action))), @@ -213,7 +210,6 @@ def create(self, request, *args, **kwargs): input_params=input_params, action=action, name=_file.name if _file else extracted_params.get("title", None), - source=extracted_params.get("source"), ) sig = import_orchestrator.s(files, str(execution_id), handler=str(handler), action=action) @@ -234,7 +230,7 @@ def create(self, request, *args, **kwargs): logger.exception(e) raise ImportException(detail=e.args[0] if len(e.args) > 0 else e) - raise ImportException(detail="No handlers found for this dataset type") + raise ImportException(detail="No handlers found for this dataset type/action") def _handle_asset(self, request, asset_dir, storage_manager, _data, handler): if storage_manager is None: diff --git a/geonode/upload/handlers/common/metadata.py b/geonode/upload/handlers/common/metadata.py index 3138be1e9dc..06ab95acc1c 100644 --- a/geonode/upload/handlers/common/metadata.py +++ b/geonode/upload/handlers/common/metadata.py @@ -18,7 +18,6 @@ ######################################################################### import logging from geonode.upload.handlers.base import BaseHandler -from geonode.upload.handlers.utils import UploadSourcesEnum from geonode.upload.models import ResourceHandlerInfo from geonode.upload.handlers.xml.serializer import MetadataFileSerializer from geonode.upload.orchestrator import orchestrator @@ -34,16 +33,6 @@ class MetadataFileHandler(BaseHandler): It must provide the task_lists required to comple the upload """ - @staticmethod - def can_handle(_data) -> bool: - """ - This endpoint will return True or False if with the info provided - the handler is able to handle the file or not - """ - if _data.get("source", None) == UploadSourcesEnum.resource_file_upload.value: - return True - return False - @staticmethod def has_serializer(data) -> bool: _base = data.get("base_file") @@ -69,7 +58,7 @@ def extract_params_from_data(_data, action=None): "overwrite_existing_layer": _data.pop("overwrite_existing_layer", False), "resource_pk": _data.pop("resource_pk", None), "store_spatial_file": _data.pop("store_spatial_files", "True"), - "source": _data.pop("source", "resource_file_upload"), + "action": _data.pop("action"), }, _data @staticmethod diff --git a/geonode/upload/handlers/common/raster.py b/geonode/upload/handlers/common/raster.py index 1c00e8fa067..22c273b40c4 100644 --- a/geonode/upload/handlers/common/raster.py +++ b/geonode/upload/handlers/common/raster.py @@ -35,7 +35,7 @@ from geonode.upload.celery_tasks import ErrorBaseTaskClass, import_orchestrator from geonode.upload.handlers.base import BaseHandler from geonode.upload.handlers.geotiff.exceptions import InvalidGeoTiffException -from geonode.upload.handlers.utils import UploadSourcesEnum, create_alternate, should_be_imported +from geonode.upload.handlers.utils import create_alternate, should_be_imported from geonode.upload.models import ResourceHandlerInfo from geonode.upload.orchestrator import orchestrator from osgeo import gdal @@ -83,16 +83,6 @@ def is_valid(files, user, **kwargs): raise ImportException(stderr) return True - @staticmethod - def can_handle(_data) -> bool: - """ - This endpoint will return True or False if with the info provided - the handler is able to handle the file or not - """ - if _data.get("source", None) != UploadSourcesEnum.upload.value: - return False - return True - @staticmethod def has_serializer(_data) -> bool: """ @@ -132,7 +122,7 @@ def extract_params_from_data(_data, action=None): "overwrite_existing_layer": _data.pop("overwrite_existing_layer", False), "resource_pk": _data.pop("resource_pk", None), "store_spatial_file": _data.pop("store_spatial_files", "True"), - "source": _data.pop("source", "upload"), + "action": _data.pop("action", "upload"), }, _data @staticmethod @@ -285,6 +275,8 @@ def import_resource(self, files: dict, execution_id: str, **kwargs) -> str: dataset = Dataset.objects.filter(pk=_exec.input_params.get("resource_pk")).first() if not dataset: raise ImportException("The dataset selected for the ovewrite does not exists") + if dataset.is_vector(): + raise Exception("cannot override a vector dataset with a raster one") alternate = dataset.alternate.split(":")[-1] orchestrator.update_execution_request_obj(_exec, {"geonode_resource": dataset}) else: @@ -293,6 +285,8 @@ def import_resource(self, files: dict, execution_id: str, **kwargs) -> str: dataset_exists = user_datasets.exists() if dataset_exists and should_be_overwritten: + if user_datasets.is_vector(): + raise Exception("cannot override a vector dataset with a raster one") layer_name, alternate = ( layer_name, user_datasets.first().alternate.split(":")[-1], diff --git a/geonode/upload/handlers/common/remote.py b/geonode/upload/handlers/common/remote.py index 2366ec0f473..ac7e2ec2718 100755 --- a/geonode/upload/handlers/common/remote.py +++ b/geonode/upload/handlers/common/remote.py @@ -105,7 +105,7 @@ def extract_params_from_data(_data, action=None): return {"title": title.pop("title")}, _data return { - "source": _data.pop("source", "upload"), + "action": _data.pop("action", "upload"), "title": _data.pop("title", None), "url": _data.pop("url", None), "type": _data.pop("type", None), diff --git a/geonode/upload/handlers/common/serializer.py b/geonode/upload/handlers/common/serializer.py index f1b12b7d8db..c1eab398781 100644 --- a/geonode/upload/handlers/common/serializer.py +++ b/geonode/upload/handlers/common/serializer.py @@ -26,7 +26,7 @@ class Meta: ref_name = "RemoteResourceSerializer" model = ResourceBase view_name = "importer_upload" - fields = ("url", "title", "type", "source", "overwrite_existing_layer") + fields = ("url", "title", "type", "action", "overwrite_existing_layer") url = serializers.URLField(required=True, help_text="URL of the remote service / resource") title = serializers.CharField(required=True, help_text="Title of the resource. Can be None or Empty") @@ -34,6 +34,6 @@ class Meta: required=True, help_text="Remote resource type, for example wms or 3dtiles. Is used by the handler to understand if can handle the resource", ) - source = serializers.CharField(required=False, default="upload") + action = serializers.CharField(required=True) overwrite_existing_layer = serializers.BooleanField(required=False, default=False) diff --git a/geonode/upload/handlers/common/vector.py b/geonode/upload/handlers/common/vector.py index c38f871f1f2..10b10d6cebd 100644 --- a/geonode/upload/handlers/common/vector.py +++ b/geonode/upload/handlers/common/vector.py @@ -39,7 +39,6 @@ from geonode.upload.handlers.utils import ( GEOM_TYPE_MAPPING, STANDARD_TYPE_MAPPING, - UploadSourcesEnum, drop_dynamic_model_schema, ) from geonode.resource.manager import resource_manager @@ -55,6 +54,7 @@ from django.db.models import Q import pyproj from geonode.geoserver.security import delete_dataset_cache, set_geowebcache_invalidate_cache +from geonode.upload.utils import ImporterRequestAction as ira logger = logging.getLogger("importer") @@ -65,6 +65,32 @@ class BaseVectorFileHandler(BaseHandler): It must provide the task_lists required to comple the upload """ + TASKS = { + exa.UPLOAD.value: ( + "start_import", + "geonode.upload.import_resource", + "geonode.upload.publish_resource", + "geonode.upload.create_geonode_resource", + ), + exa.COPY.value: ( + "start_copy", + "geonode.upload.copy_dynamic_model", + "geonode.upload.copy_geonode_data_table", + "geonode.upload.publish_resource", + "geonode.upload.copy_geonode_resource", + ), + ira.ROLLBACK.value: ( + "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 default_geometry_column_name(self): return "geometry" @@ -99,7 +125,7 @@ def can_handle(_data) -> bool: This endpoint will return True or False if with the info provided the handler is able to handle the file or not """ - if _data.get("source", None) != UploadSourcesEnum.upload.value: + if _data.get("action", None) not in BaseVectorFileHandler.TASKS: return False return True @@ -142,7 +168,7 @@ def extract_params_from_data(_data, action=None): "overwrite_existing_layer": _data.pop("overwrite_existing_layer", False), "resource_pk": _data.pop("resource_pk", None), "store_spatial_file": _data.pop("store_spatial_files", "True"), - "source": _data.pop("source", "upload"), + "action": _data.pop("action", "upload"), }, _data @staticmethod @@ -431,6 +457,9 @@ def find_alternate_by_dataset(self, _exec_obj, layer_name, should_be_overwritten dataset = Dataset.objects.filter(pk=_exec_obj.input_params.get("resource_pk")).first() if not dataset: raise ImportException("The dataset selected for the ovewrite does not exists") + if should_be_overwritten: + if not dataset.is_vector(): + raise Exception("Cannot override a raster dataset with a vector one") alternate = dataset.alternate.split(":") return alternate[-1] @@ -438,6 +467,9 @@ def find_alternate_by_dataset(self, _exec_obj, layer_name, should_be_overwritten dataset_available = Dataset.objects.filter(alternate__iexact=f"{workspace.name}:{layer_name}") dataset_exists = dataset_available.exists() + if should_be_overwritten: + if not dataset_available.is_vector(): + raise Exception("Cannot override a raster dataset with a vector one") if dataset_exists and should_be_overwritten: alternate = dataset_available.first().alternate.split(":")[-1] diff --git a/geonode/upload/handlers/csv/handler.py b/geonode/upload/handlers/csv/handler.py index 7cea75d5e38..3d26a4d6e66 100644 --- a/geonode/upload/handlers/csv/handler.py +++ b/geonode/upload/handlers/csv/handler.py @@ -29,7 +29,6 @@ from dynamic_models.models import ModelSchema from geonode.upload.handlers.common.vector import BaseVectorFileHandler from geonode.upload.handlers.utils import GEOM_TYPE_MAPPING -from geonode.upload.utils import ImporterRequestAction as ira logger = logging.getLogger("importer") @@ -40,32 +39,6 @@ class CSVFileHandler(BaseVectorFileHandler): It must provide the task_lists required to comple the upload """ - TASKS = { - exa.UPLOAD.value: ( - "start_import", - "geonode.upload.import_resource", - "geonode.upload.publish_resource", - "geonode.upload.create_geonode_resource", - ), - exa.COPY.value: ( - "start_copy", - "geonode.upload.copy_dynamic_model", - "geonode.upload.copy_geonode_data_table", - "geonode.upload.publish_resource", - "geonode.upload.copy_geonode_resource", - ), - ira.ROLLBACK.value: ( - "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"] possible_lat_column = ["latitude", "lat", "y"] possible_long_column = ["longitude", "long", "x"] diff --git a/geonode/upload/handlers/csv/tests.py b/geonode/upload/handlers/csv/tests.py index b23c7dec6b2..a32d69cc82d 100644 --- a/geonode/upload/handlers/csv/tests.py +++ b/geonode/upload/handlers/csv/tests.py @@ -46,7 +46,7 @@ def setUpClass(cls): cls.missing_geom = f"{project_dir}/tests/fixture/missing_geom.csv" cls.user, _ = get_user_model().objects.get_or_create(username="admin") cls.invalid_files = {"base_file": cls.invalid_csv} - cls.valid_files = {"base_file": cls.valid_csv, "source": "upload"} + cls.valid_files = {"base_file": cls.valid_csv, "action": "upload"} cls.owner = get_user_model().objects.first() cls.layer = create_single_dataset(name="test", owner=cls.owner) diff --git a/geonode/upload/handlers/geojson/handler.py b/geonode/upload/handlers/geojson/handler.py index c1e960de243..eb4c740463d 100644 --- a/geonode/upload/handlers/geojson/handler.py +++ b/geonode/upload/handlers/geojson/handler.py @@ -19,11 +19,9 @@ import json import logging import os -from geonode.resource.enumerator import ExecutionRequestAction as exa from geonode.upload.utils import UploadLimitValidator from geonode.upload.handlers.common.vector import BaseVectorFileHandler from osgeo import ogr -from geonode.upload.utils import ImporterRequestAction as ira from geonode.upload.handlers.geojson.exceptions import InvalidGeoJsonException @@ -36,32 +34,6 @@ class GeoJsonFileHandler(BaseVectorFileHandler): It must provide the task_lists required to comple the upload """ - TASKS = { - exa.UPLOAD.value: ( - "start_import", - "geonode.upload.import_resource", - "geonode.upload.publish_resource", - "geonode.upload.create_geonode_resource", - ), - exa.COPY.value: ( - "start_copy", - "geonode.upload.copy_dynamic_model", - "geonode.upload.copy_geonode_data_table", - "geonode.upload.publish_resource", - "geonode.upload.copy_geonode_resource", - ), - ira.ROLLBACK.value: ( - "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 { diff --git a/geonode/upload/handlers/geojson/tests.py b/geonode/upload/handlers/geojson/tests.py index 105c91608a3..d18f563a80a 100644 --- a/geonode/upload/handlers/geojson/tests.py +++ b/geonode/upload/handlers/geojson/tests.py @@ -43,7 +43,7 @@ def setUpClass(cls): cls.invalid_geojson = f"{project_dir}/tests/fixture/invalid.geojson" cls.user, _ = get_user_model().objects.get_or_create(username="admin") cls.invalid_files = {"base_file": cls.invalid_geojson} - cls.valid_files = {"base_file": cls.valid_geojson, "source": "upload"} + cls.valid_files = {"base_file": cls.valid_geojson, "action": "upload"} cls.owner = get_user_model().objects.first() cls.layer = create_single_dataset(name="stazioni_metropolitana", owner=cls.owner) diff --git a/geonode/upload/handlers/geotiff/handler.py b/geonode/upload/handlers/geotiff/handler.py index 62da37bde1b..232440360df 100644 --- a/geonode/upload/handlers/geotiff/handler.py +++ b/geonode/upload/handlers/geotiff/handler.py @@ -99,7 +99,7 @@ def can_handle(_data) -> bool: if not base: return False ext = base.split(".")[-1] if isinstance(base, str) else base.name.split(".")[-1] - return ext in ["tiff", "geotiff", "tif", "geotif"] and BaseRasterFileHandler.can_handle(_data) + return ext in ["tiff", "geotiff", "tif", "geotif"] and _data.get("action", None) in GeoTiffFileHandler.TASKS @staticmethod def is_valid(files, user, **kwargs): diff --git a/geonode/upload/handlers/geotiff/tests.py b/geonode/upload/handlers/geotiff/tests.py index 6e0c769c346..edd26d0d50e 100644 --- a/geonode/upload/handlers/geotiff/tests.py +++ b/geonode/upload/handlers/geotiff/tests.py @@ -35,7 +35,7 @@ def setUpClass(cls): super().setUpClass() cls.handler = GeoTiffFileHandler() cls.valid_tiff = f"{project_dir}/tests/fixture/test_raster.tif" - cls.valid_files = {"base_file": cls.valid_tiff, "source": "upload"} + cls.valid_files = {"base_file": cls.valid_tiff, "action": "upload"} cls.user, _ = get_user_model().objects.get_or_create(username="admin") cls.invalid_tiff = {"base_file": "invalid.file.foo"} cls.owner = get_user_model().objects.first() diff --git a/geonode/upload/handlers/gpkg/handler.py b/geonode/upload/handlers/gpkg/handler.py index 860d0ef8212..59553de453a 100644 --- a/geonode/upload/handlers/gpkg/handler.py +++ b/geonode/upload/handlers/gpkg/handler.py @@ -89,9 +89,9 @@ def can_handle(_data) -> bool: base = _data.get("base_file") if not base: return False - return ( - base.endswith(".gpkg") if isinstance(base, str) else base.name.endswith(".gpkg") - ) and BaseVectorFileHandler.can_handle(_data) + return (base.endswith(".gpkg") if isinstance(base, str) else base.name.endswith(".gpkg")) and _data.get( + "action", None + ) in GPKGFileHandler.TASKS @staticmethod def is_valid(files, user, **kwargs): diff --git a/geonode/upload/handlers/gpkg/tests.py b/geonode/upload/handlers/gpkg/tests.py index 0bae64fe295..a89b344e09b 100644 --- a/geonode/upload/handlers/gpkg/tests.py +++ b/geonode/upload/handlers/gpkg/tests.py @@ -44,7 +44,7 @@ def setUpClass(cls): cls.invalid_gpkg = f"{project_dir}/tests/fixture/invalid.gpkg" cls.user, _ = get_user_model().objects.get_or_create(username="admin") cls.invalid_files = {"base_file": cls.invalid_gpkg} - cls.valid_files = {"base_file": cls.valid_gpkg, "source": "upload"} + cls.valid_files = {"base_file": cls.valid_gpkg, "action": "upload"} cls.owner = get_user_model().objects.first() cls.layer = create_single_dataset(name="stazioni_metropolitana", owner=cls.owner) diff --git a/geonode/upload/handlers/kml/handler.py b/geonode/upload/handlers/kml/handler.py index 34079fb517a..aaaa07cb4c5 100644 --- a/geonode/upload/handlers/kml/handler.py +++ b/geonode/upload/handlers/kml/handler.py @@ -55,12 +55,6 @@ 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 diff --git a/geonode/upload/handlers/kml/tests.py b/geonode/upload/handlers/kml/tests.py index 28eb25be8f1..d14f53e3bf3 100644 --- a/geonode/upload/handlers/kml/tests.py +++ b/geonode/upload/handlers/kml/tests.py @@ -38,7 +38,7 @@ def setUpClass(cls): cls.invalid_kml = f"{project_dir}/tests/fixture/inva.lid.kml" cls.user, _ = get_user_model().objects.get_or_create(username="admin") cls.invalid_files = {"base_file": cls.invalid_kml} - cls.valid_files = {"base_file": cls.valid_kml, "source": "upload"} + cls.valid_files = {"base_file": cls.valid_kml, "action": "upload"} cls.owner = get_user_model().objects.first() cls.layer = create_single_dataset(name="extruded_polygon", owner=cls.owner) diff --git a/geonode/upload/handlers/shapefile/handler.py b/geonode/upload/handlers/shapefile/handler.py index 000ca9e156f..d02f509a6da 100644 --- a/geonode/upload/handlers/shapefile/handler.py +++ b/geonode/upload/handlers/shapefile/handler.py @@ -29,7 +29,6 @@ from geonode.upload.handlers.shapefile.exceptions import InvalidShapeFileException from geonode.upload.handlers.shapefile.serializer import OverwriteShapeFileSerializer, ShapeFileSerializer -from geonode.upload.utils import ImporterRequestAction as ira logger = logging.getLogger("importer") @@ -40,32 +39,6 @@ class ShapeFileHandler(BaseVectorFileHandler): It must provide the task_lists required to comple the upload """ - TASKS = { - exa.UPLOAD.value: ( - "start_import", - "geonode.upload.import_resource", - "geonode.upload.publish_resource", - "geonode.upload.create_geonode_resource", - ), - exa.COPY.value: ( - "start_copy", - "geonode.upload.copy_dynamic_model", - "geonode.upload.copy_geonode_data_table", - "geonode.upload.publish_resource", - "geonode.upload.copy_geonode_resource", - ), - ira.ROLLBACK.value: ( - "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 { @@ -120,7 +93,7 @@ def extract_params_from_data(_data, action=None): "overwrite_existing_layer": _data.pop("overwrite_existing_layer", False), "resource_pk": _data.pop("resource_pk", None), "store_spatial_file": _data.pop("store_spatial_files", "True"), - "source": _data.pop("source", "upload"), + "action": _data.pop("action", "upload"), } return additional_params, _data @@ -140,7 +113,7 @@ def is_valid(files, user, **kwargs): _filename = Path(_file).stem - _shp_ext_needed = [x["requires"] for x in get_supported_datasets_file_types() if x["id"] == "shp"][0] + _shp_ext_needed = ShapeFileHandler._get_ext_needed() """ Check if the ext required for the shape file are available in the files uploaded @@ -166,6 +139,13 @@ def is_valid(files, user, **kwargs): return True + @staticmethod + def _get_ext_needed(): + for x in get_supported_datasets_file_types(): + if x["id"] == "shp": + for item in x["formats"][0]["required_ext"]: + yield item + def get_ogr2ogr_driver(self): return ogr.GetDriverByName("ESRI Shapefile") diff --git a/geonode/upload/handlers/shapefile/serializer.py b/geonode/upload/handlers/shapefile/serializer.py index cf7aa407436..4091cddb5ac 100644 --- a/geonode/upload/handlers/shapefile/serializer.py +++ b/geonode/upload/handlers/shapefile/serializer.py @@ -36,7 +36,7 @@ class Meta: "store_spatial_files", "overwrite_existing_layer", "skip_existing_layers", - "source", + "action", ) base_file = serializers.FileField() @@ -48,7 +48,7 @@ class Meta: store_spatial_files = serializers.BooleanField(required=False, default=True) 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") + action = serializers.CharField(required=True) class OverwriteShapeFileSerializer(ShapeFileSerializer): diff --git a/geonode/upload/handlers/shapefile/tests.py b/geonode/upload/handlers/shapefile/tests.py index 3462face165..af266bc1a29 100644 --- a/geonode/upload/handlers/shapefile/tests.py +++ b/geonode/upload/handlers/shapefile/tests.py @@ -48,7 +48,7 @@ def setUpClass(cls): "dbf_file": f"{file_path}/san_andres_y_providencia_highway.dbf", "prj_file": f"{file_path}/san_andres_y_providencia_highway.prj", "shx_file": f"{file_path}/san_andres_y_providencia_highway.shx", - "source": "upload", + "action": "upload", } cls.invalid_shp = f"{project_dir}/tests/fixture/invalid.geojson" cls.user, _ = get_user_model().objects.get_or_create(username="admin") diff --git a/geonode/upload/handlers/sld/handler.py b/geonode/upload/handlers/sld/handler.py index 3efb55e3516..9dc62364c78 100644 --- a/geonode/upload/handlers/sld/handler.py +++ b/geonode/upload/handlers/sld/handler.py @@ -64,9 +64,9 @@ def can_handle(_data) -> bool: base = _data.get("base_file") if not base: return False - return ( - base.endswith(".sld") if isinstance(base, str) else base.name.endswith(".sld") - ) and MetadataFileHandler.can_handle(_data) + return (base.endswith(".sld") if isinstance(base, str) else base.name.endswith(".sld")) and _data.get( + "action", None + ) == ira.RESOURCE_SLD_UPLOAD.value @staticmethod def is_valid(files, user, **kwargs): diff --git a/geonode/upload/handlers/sld/tests.py b/geonode/upload/handlers/sld/tests.py index b88026636ec..1ef0e421cd8 100644 --- a/geonode/upload/handlers/sld/tests.py +++ b/geonode/upload/handlers/sld/tests.py @@ -45,7 +45,7 @@ def setUpClass(cls): cls.valid_files = { "base_file": "/tmp/test_sld.sld", "sld_file": "/tmp/test_sld.sld", - "source": "resource_file_upload", + "action": "resource_file_upload", } cls.owner = get_user_model().objects.first() cls.layer = create_single_dataset(name="sld_dataset", owner=cls.owner) diff --git a/geonode/upload/handlers/tiles3d/handler.py b/geonode/upload/handlers/tiles3d/handler.py index 378f57580ca..189291a3b35 100755 --- a/geonode/upload/handlers/tiles3d/handler.py +++ b/geonode/upload/handlers/tiles3d/handler.py @@ -155,7 +155,7 @@ def extract_params_from_data(_data, action=None): return { "skip_existing_layers": _data.pop("skip_existing_layers", "False"), "store_spatial_file": _data.pop("store_spatial_files", "True"), - "source": _data.pop("source", "upload"), + "action": _data.pop("action", "upload"), "original_zip_name": _data.pop("original_zip_name", None), "overwrite_existing_layer": _data.pop("overwrite_existing_layer", False), }, _data diff --git a/geonode/upload/handlers/utils.py b/geonode/upload/handlers/utils.py index e6ea039d3f2..f4908d43b5a 100644 --- a/geonode/upload/handlers/utils.py +++ b/geonode/upload/handlers/utils.py @@ -16,7 +16,6 @@ # along with this program. If not, see . # ######################################################################### -import enum import hashlib from django.contrib.auth import get_user_model @@ -32,12 +31,6 @@ logger = logging.getLogger("importer") -# TODO this part should be improved when we will drop the legacy upload templates -class UploadSourcesEnum(enum.Enum): - upload = "upload" # used in the default upload flow - resource_file_upload = "resource_file_upload" # source used for the single resource metadata upload - - STANDARD_TYPE_MAPPING = { "Integer64": "django.db.models.IntegerField", "Integer": "django.db.models.IntegerField", diff --git a/geonode/upload/handlers/xml/handler.py b/geonode/upload/handlers/xml/handler.py index 1e000b0081c..58c64ac3a8a 100644 --- a/geonode/upload/handlers/xml/handler.py +++ b/geonode/upload/handlers/xml/handler.py @@ -40,6 +40,7 @@ class XMLFileHandler(MetadataFileHandler): "geonode.upload.rollback", ), } + @property def supported_file_extension_config(self): return { @@ -63,9 +64,9 @@ def can_handle(_data) -> bool: base = _data.get("base_file") if not base: return False - return ( - base.endswith(".xml") if isinstance(base, str) else base.name.endswith(".xml") - ) and MetadataFileHandler.can_handle(_data) + return (base.endswith(".xml") if isinstance(base, str) else base.name.endswith(".xml")) and _data.get( + "action", None + ) == ira.RESOURCE_METADATA_UPLOAD.value @staticmethod def is_valid(files, user=None, **kwargs): diff --git a/geonode/upload/handlers/xml/serializer.py b/geonode/upload/handlers/xml/serializer.py index a28ddd2118a..19bb53fb61c 100644 --- a/geonode/upload/handlers/xml/serializer.py +++ b/geonode/upload/handlers/xml/serializer.py @@ -27,9 +27,9 @@ class Meta: ref_name = "MetadataFileSerializer" model = ResourceBase view_name = "importer_upload" - fields = ("overwrite_existing_layer", "resource_pk", "base_file", "source") + fields = ("overwrite_existing_layer", "resource_pk", "base_file", "action") base_file = serializers.FileField() overwrite_existing_layer = serializers.BooleanField(required=False, default=True) resource_pk = serializers.CharField(required=True) - source = serializers.CharField(required=False, default="resource_file_upload") + action = serializers.CharField(required=True) diff --git a/geonode/upload/handlers/xml/tests.py b/geonode/upload/handlers/xml/tests.py index 716b8db65e9..909778fc050 100644 --- a/geonode/upload/handlers/xml/tests.py +++ b/geonode/upload/handlers/xml/tests.py @@ -44,7 +44,7 @@ def setUpClass(cls): cls.valid_files = { "base_file": "/tmp/test_xml.xml", "xml_file": "/tmp/test_xml.xml", - "source": "resource_file_upload", + "action": "resource_file_upload", } cls.owner = get_user_model().objects.first() cls.layer = create_single_dataset(name="extruded_polygon", owner=cls.owner) diff --git a/geonode/upload/orchestrator.py b/geonode/upload/orchestrator.py index 3a40549ac20..fdb146b44bc 100644 --- a/geonode/upload/orchestrator.py +++ b/geonode/upload/orchestrator.py @@ -56,14 +56,21 @@ def get_handler(self, _data) -> Optional[BaseHandler]: If is part of the supported format, return the handler which can handle the import otherwise return None """ - for handler in BaseHandler.get_registry(): - if handler.can_handle(_data): - return handler() - logger.error("Handler not found") + for handler in self.get_handler_registry(): + can_handle = handler.can_handle(_data) + match can_handle: + case True: + return handler() + case False: + logger.info( + f"The handler {str(handler)} cannot manage the requested action: {_data.get('action', None)}" + ) + + logger.error("No handlers found for this dataset type/action") return None def get_serializer(self, _data) -> serializers.Serializer: - for handler in BaseHandler.get_registry(): + for handler in self.get_handler_registry(): _serializer = handler.has_serializer(_data) if _serializer: return _serializer @@ -80,7 +87,7 @@ def load_handler(self, module_path): raise ImportException(detail=f"The handler is not available: {module_path}") def load_handler_by_id(self, handler_id): - for handler in BaseHandler.get_registry(): + for handler in self.get_handler_registry(): if handler().id == handler_id: return handler logger.error("Handler not found") diff --git a/geonode/upload/tests/unit/test_orchestrator.py b/geonode/upload/tests/unit/test_orchestrator.py index b4d3871c042..a8ddf8efd5b 100644 --- a/geonode/upload/tests/unit/test_orchestrator.py +++ b/geonode/upload/tests/unit/test_orchestrator.py @@ -44,7 +44,7 @@ def setUpClass(cls): cls.orchestrator = ImportOrchestrator() def test_get_handler(self): - _data = {"base_file": "file.gpkg", "source": "upload"} + _data = {"base_file": "file.gpkg", "action": "upload"} actual = self.orchestrator.get_handler(_data) self.assertIsNotNone(actual) self.assertEqual("geonode.upload.handlers.gpkg.handler.GPKGFileHandler", str(actual)) diff --git a/geonode/utils.py b/geonode/utils.py index 3cf9a71fb99..bb63c8ece31 100755 --- a/geonode/utils.py +++ b/geonode/utils.py @@ -29,7 +29,6 @@ import requests import tempfile import ipaddress -import itertools import traceback from lxml import etree @@ -1722,11 +1721,13 @@ def get_supported_datasets_file_types(): default_types = [ { "id": "zip", - "formats": { - "label": "Zip Archive", - "required_ext": ["zip"], - "optional_ext": ["xml", "sld"], - }, + "formats": [ + { + "label": "Zip Archive", + "required_ext": ["zip"], + "optional_ext": ["xml", "sld"], + } + ], "action": ["upload", "replace"], "type": "archive", } @@ -1764,4 +1765,12 @@ def get_supported_datasets_file_types(): def get_allowed_extensions(): - return list(itertools.chain.from_iterable([_type["ext"] for _type in get_supported_datasets_file_types()])) + """ + The main extension is rappresented by the position 0 of the configuration + that the handlers returns + """ + allowed_extention = [] + for _type in get_supported_datasets_file_types(): + for val in _type["formats"]: + allowed_extention.append(val["required_ext"][0]) + return list(set(allowed_extention)) From 49edf7676a9802fb9a0d9c05e93d48c984dbe1ea Mon Sep 17 00:00:00 2001 From: Mattia Date: Fri, 18 Oct 2024 12:20:44 +0200 Subject: [PATCH 5/9] [Fixes #12657] Refactor supported type, fix data retriever and refactor handlers configuration --- .../management/commands/importlayers.py | 1 + geonode/resource/api/tests.py | 2 +- geonode/upload/api/tests.py | 7 ++++++ geonode/upload/handlers/common/test_remote.py | 6 ++--- geonode/upload/handlers/csv/tests.py | 4 ++-- geonode/upload/handlers/geojson/tests.py | 4 ++-- geonode/upload/handlers/geotiff/tests.py | 4 ++-- geonode/upload/handlers/gpkg/tests.py | 4 ++-- geonode/upload/handlers/kml/tests.py | 4 ++-- .../handlers/remote/tests/test_3dtiles.py | 6 ++--- .../upload/handlers/remote/tests/test_wms.py | 6 ++--- geonode/upload/handlers/shapefile/tests.py | 4 ++-- geonode/upload/handlers/sld/tests.py | 6 ++--- geonode/upload/handlers/tiles3d/tests.py | 16 ++++++++----- geonode/upload/handlers/xml/tests.py | 6 ++--- geonode/upload/tests/end2end/test_end2end.py | 23 +++++++++++++++++++ .../upload/tests/end2end/test_end2end_copy.py | 6 +++++ geonode/upload/tests/unit/test_dastore.py | 4 ++-- .../upload/tests/unit/test_orchestrator.py | 18 ++++++++------- geonode/upload/tests/unit/test_publisher.py | 4 ++-- geonode/upload/tests/unit/test_task.py | 6 ++--- 21 files changed, 92 insertions(+), 49 deletions(-) diff --git a/geonode/geoserver/management/commands/importlayers.py b/geonode/geoserver/management/commands/importlayers.py index b92ac407396..c6eb9e233b3 100644 --- a/geonode/geoserver/management/commands/importlayers.py +++ b/geonode/geoserver/management/commands/importlayers.py @@ -149,6 +149,7 @@ def execute(self): params[name] = os.path.basename(value.name) params["non_interactive"] = 'true' + params["action"] = 'upload' response = client.post( urljoin(self.host, "/api/v2/uploads/upload/"), auth=HTTPBasicAuth(self.username, self.password), diff --git a/geonode/resource/api/tests.py b/geonode/resource/api/tests.py index 1deaa3f9a47..a93af1ffe0e 100644 --- a/geonode/resource/api/tests.py +++ b/geonode/resource/api/tests.py @@ -158,7 +158,7 @@ def test_endpoint_should_raise_error_if_pk_is_not_passed(self): def test_endpoint_should_return_the_source(self): # creating dummy execution request obj = ExecutionRequest.objects.create( - user=self.superuser, func_name="import_new_resource", action="import", source="upload_workflow" + user=self.superuser, func_name="import_new_resource", action="upload", source="upload_workflow" ) self.client.force_login(self.superuser) diff --git a/geonode/upload/api/tests.py b/geonode/upload/api/tests.py index 5d6aa237c6f..a6a2897058e 100644 --- a/geonode/upload/api/tests.py +++ b/geonode/upload/api/tests.py @@ -64,6 +64,7 @@ def test_raise_exception_if_file_is_not_a_handled(self): self.client.force_login(get_user_model().objects.get(username="admin")) payload = { "base_file": SimpleUploadedFile(name="file.invalid", content=b"abc"), + "action": "upload" } response = self.client.post(self.url, data=payload) self.assertEqual(500, response.status_code) @@ -76,6 +77,7 @@ def test_gpkg_raise_error_with_invalid_payload(self): content=b'{"type": "FeatureCollection", "content": "some-content"}', ), "store_spatial_files": "invalid", + "action": "upload" } expected = { "success": False, @@ -99,6 +101,7 @@ def test_gpkg_task_is_called(self, patch_upload): content=b'{"type": "FeatureCollection", "content": "some-content"}', ), "store_spatial_files": True, + "action": "upload" } response = self.client.post(self.url, data=payload) @@ -116,6 +119,7 @@ def test_geojson_task_is_called(self, patch_upload): content=b'{"type": "FeatureCollection", "content": "some-content"}', ), "store_spatial_files": True, + "action": "upload" } response = self.client.post(self.url, data=payload) @@ -133,6 +137,7 @@ def test_zip_file_is_unzip_and_the_handler_is_found(self, patch_upload): "base_file": open(f"{project_dir}/tests/fixture/valid.zip", "rb"), "zip_file": open(f"{project_dir}/tests/fixture/valid.zip", "rb"), "store_spatial_files": True, + "action": "upload" } response = self.client.post(self.url, data=payload) @@ -191,6 +196,7 @@ def test_asset_is_created_before_the_import_start(self, patch_upload): content=b'{"type": "FeatureCollection", "content": "some-content"}', ), "store_spatial_files": True, + "action": "upload" } response = self.client.post(self.url, data=payload) @@ -221,6 +227,7 @@ def test_asset_should_be_deleted_if_created_during_with_exception( content=b'{"type": "FeatureCollection", "content": "some-content"}', ), "store_spatial_files": True, + "action": "upload" } response = self.client.post(self.url, data=payload) diff --git a/geonode/upload/handlers/common/test_remote.py b/geonode/upload/handlers/common/test_remote.py index 157bccb9c54..c61b02981f1 100644 --- a/geonode/upload/handlers/common/test_remote.py +++ b/geonode/upload/handlers/common/test_remote.py @@ -82,8 +82,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.import_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 3) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["upload"]), 3) + self.assertTupleEqual(expected, self.handler.TASKS["upload"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( @@ -106,7 +106,7 @@ def test_is_valid_should_pass_with_valid_url(self): def test_extract_params_from_data(self): actual, _data = self.handler.extract_params_from_data( _data={"defaults": '{"url": "http://abc123defsadsa.org", "title": "Remote Title", "type": "3dtiles"}'}, - action="import", + action="upload", ) self.assertTrue("title" in actual) self.assertTrue("url" in actual) diff --git a/geonode/upload/handlers/csv/tests.py b/geonode/upload/handlers/csv/tests.py index a32d69cc82d..6321b880a88 100644 --- a/geonode/upload/handlers/csv/tests.py +++ b/geonode/upload/handlers/csv/tests.py @@ -57,8 +57,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 4) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["upload"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["upload"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( diff --git a/geonode/upload/handlers/geojson/tests.py b/geonode/upload/handlers/geojson/tests.py index d18f563a80a..ba222c2dec3 100644 --- a/geonode/upload/handlers/geojson/tests.py +++ b/geonode/upload/handlers/geojson/tests.py @@ -54,8 +54,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 4) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["upload"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["upload"]) def test_task_list_is_the_expected_one_copy(self): expected = ( diff --git a/geonode/upload/handlers/geotiff/tests.py b/geonode/upload/handlers/geotiff/tests.py index edd26d0d50e..be18b958896 100644 --- a/geonode/upload/handlers/geotiff/tests.py +++ b/geonode/upload/handlers/geotiff/tests.py @@ -48,8 +48,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 4) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["upload"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["upload"]) def test_task_list_is_the_expected_one_copy(self): expected = ( diff --git a/geonode/upload/handlers/gpkg/tests.py b/geonode/upload/handlers/gpkg/tests.py index a89b344e09b..8ea31059548 100644 --- a/geonode/upload/handlers/gpkg/tests.py +++ b/geonode/upload/handlers/gpkg/tests.py @@ -55,8 +55,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 4) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["upload"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["upload"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( diff --git a/geonode/upload/handlers/kml/tests.py b/geonode/upload/handlers/kml/tests.py index d14f53e3bf3..2b03a0a0a06 100644 --- a/geonode/upload/handlers/kml/tests.py +++ b/geonode/upload/handlers/kml/tests.py @@ -49,8 +49,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 4) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["upload"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["upload"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( diff --git a/geonode/upload/handlers/remote/tests/test_3dtiles.py b/geonode/upload/handlers/remote/tests/test_3dtiles.py index 0ad54a9a989..f5216ec9414 100644 --- a/geonode/upload/handlers/remote/tests/test_3dtiles.py +++ b/geonode/upload/handlers/remote/tests/test_3dtiles.py @@ -83,8 +83,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.import_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 3) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["upload"]), 3) + self.assertTupleEqual(expected, self.handler.TASKS["upload"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( @@ -107,7 +107,7 @@ def test_is_valid_should_pass_with_valid_url(self): def test_extract_params_from_data(self): actual, _data = self.handler.extract_params_from_data( _data={"defaults": '{"url": "http://abc123defsadsa.org", "title": "Remote Title", "type": "3dtiles"}'}, - action="import", + action="upload", ) self.assertTrue("title" in actual) self.assertTrue("url" in actual) diff --git a/geonode/upload/handlers/remote/tests/test_wms.py b/geonode/upload/handlers/remote/tests/test_wms.py index 60ed0130125..7099f72264f 100644 --- a/geonode/upload/handlers/remote/tests/test_wms.py +++ b/geonode/upload/handlers/remote/tests/test_wms.py @@ -96,8 +96,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.import_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 3) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["upload"]), 3) + self.assertTupleEqual(expected, self.handler.TASKS["upload"]) def test_task_list_is_the_expected_one_geojson(self): expected = ( @@ -120,7 +120,7 @@ def test_is_valid_should_pass_with_valid_url(self): def test_extract_params_from_data(self): actual, _data = self.handler.extract_params_from_data( _data={"defaults": f"{self.valid_payload_with_parse_true}"}, - action="import", + action="upload", ) self.assertTrue("title" in actual) self.assertTrue("url" in actual) diff --git a/geonode/upload/handlers/shapefile/tests.py b/geonode/upload/handlers/shapefile/tests.py index af266bc1a29..d90c0fc06e8 100644 --- a/geonode/upload/handlers/shapefile/tests.py +++ b/geonode/upload/handlers/shapefile/tests.py @@ -62,8 +62,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.publish_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 4) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["upload"]), 4) + self.assertTupleEqual(expected, self.handler.TASKS["upload"]) def test_copy_task_list_is_the_expected_one(self): expected = ( diff --git a/geonode/upload/handlers/sld/tests.py b/geonode/upload/handlers/sld/tests.py index 1ef0e421cd8..823f1c175fb 100644 --- a/geonode/upload/handlers/sld/tests.py +++ b/geonode/upload/handlers/sld/tests.py @@ -45,7 +45,7 @@ def setUpClass(cls): cls.valid_files = { "base_file": "/tmp/test_sld.sld", "sld_file": "/tmp/test_sld.sld", - "action": "resource_file_upload", + "action": "resource_sld_upload", } cls.owner = get_user_model().objects.first() cls.layer = create_single_dataset(name="sld_dataset", owner=cls.owner) @@ -59,8 +59,8 @@ def test_task_list_is_the_expected_one(self): "start_import", "geonode.upload.import_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 2) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["resource_sld_upload"]), 2) + self.assertTupleEqual(expected, self.handler.TASKS["resource_sld_upload"]) def test_is_valid_should_raise_exception_if_the_sld_is_invalid(self): with self.assertRaises(InvalidSldException) as _exc: diff --git a/geonode/upload/handlers/tiles3d/tests.py b/geonode/upload/handlers/tiles3d/tests.py index 7951be07065..612489b1352 100755 --- a/geonode/upload/handlers/tiles3d/tests.py +++ b/geonode/upload/handlers/tiles3d/tests.py @@ -58,8 +58,8 @@ def test_task_list_is_the_expected_one(self): "geonode.upload.import_resource", "geonode.upload.create_geonode_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 3) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["upload"]), 3) + self.assertTupleEqual(expected, self.handler.TASKS["upload"]) def test_task_list_is_the_expected_one_copy(self): expected = ( @@ -190,10 +190,14 @@ def test_supported_file_extension_config(self): """ expected = { "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", } actual = self.handler.supported_file_extension_config self.assertDictEqual(actual, expected) diff --git a/geonode/upload/handlers/xml/tests.py b/geonode/upload/handlers/xml/tests.py index 909778fc050..b96147f4d94 100644 --- a/geonode/upload/handlers/xml/tests.py +++ b/geonode/upload/handlers/xml/tests.py @@ -44,7 +44,7 @@ def setUpClass(cls): cls.valid_files = { "base_file": "/tmp/test_xml.xml", "xml_file": "/tmp/test_xml.xml", - "action": "resource_file_upload", + "action": "resource_metadata_upload", } cls.owner = get_user_model().objects.first() cls.layer = create_single_dataset(name="extruded_polygon", owner=cls.owner) @@ -58,8 +58,8 @@ def test_task_list_is_the_expected_one(self): "start_import", "geonode.upload.import_resource", ) - self.assertEqual(len(self.handler.TASKS["import"]), 2) - self.assertTupleEqual(expected, self.handler.TASKS["import"]) + self.assertEqual(len(self.handler.TASKS["resource_metadata_upload"]), 2) + self.assertTupleEqual(expected, self.handler.TASKS["resource_metadata_upload"]) def test_is_valid_should_raise_exception_if_the_xml_is_invalid(self): with self.assertRaises(InvalidXmlException) as _exc: diff --git a/geonode/upload/tests/end2end/test_end2end.py b/geonode/upload/tests/end2end/test_end2end.py index 3d93c65f075..bb75c0d0963 100644 --- a/geonode/upload/tests/end2end/test_end2end.py +++ b/geonode/upload/tests/end2end/test_end2end.py @@ -178,6 +178,7 @@ def test_import_geopackage(self): payload = { "base_file": open(self.valid_gkpg, "rb"), + "action": "upload" } initial_name = "stazioni_metropolitana" self._assertimport(payload, initial_name) @@ -190,11 +191,13 @@ def test_import_gpkg_overwrite(self): initial_name = "stazioni_metropolitana" payload = { "base_file": open(self.valid_gkpg, "rb"), + "action": "upload" } prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) payload = { "base_file": open(self.valid_gkpg, "rb"), + "action": "upload" } payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk @@ -212,6 +215,7 @@ def test_import_geopackage_with_no_crs_table(self): self._cleanup_layers(name="mattia_test") payload = { "base_file": open(self.no_crs_gpkg, "rb"), + "action": "upload" } initial_name = "mattia_test" with self.assertLogs(level="ERROR") as _log: @@ -238,6 +242,7 @@ def test_import_geopackage_with_no_crs_table_should_raise_error_if_all_layer_are payload = { "base_file": open(self.no_crs_gpkg, "rb"), "store_spatial_file": True, + "action": "upload" } with self.assertLogs(level="ERROR") as _log: @@ -263,6 +268,7 @@ def test_import_geojson(self): payload = { "base_file": open(self.valid_geojson, "rb"), + "action": "upload" } initial_name = "valid" self._assertimport(payload, initial_name) @@ -275,11 +281,13 @@ def test_import_geojson_overwrite(self): self._cleanup_layers(name="valid") payload = { "base_file": open(self.valid_geojson, "rb"), + "action": "upload" } initial_name = "valid" prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) payload = { "base_file": open(self.valid_geojson, "rb"), + "action": "upload" } payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk @@ -296,6 +304,7 @@ def test_import_geojson(self): payload = { "base_file": open(self.valid_csv, "rb"), + "action": "upload" } initial_name = "valid" self._assertimport(payload, initial_name) @@ -307,12 +316,14 @@ def test_import_csv_overwrite(self): self._cleanup_layers(name="valid") payload = { "base_file": open(self.valid_csv, "rb"), + "action": "upload" } initial_name = "valid" prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) payload = { "base_file": open(self.valid_csv, "rb"), + "action": "upload" } initial_name = "valid" payload["overwrite_existing_layer"] = True @@ -328,6 +339,7 @@ def test_import_kml(self): self._cleanup_layers(name="sample_point_dataset") payload = { "base_file": open(self.valid_kml, "rb"), + "action": "upload" } initial_name = "sample_point_dataset" self._assertimport(payload, initial_name) @@ -341,11 +353,13 @@ def test_import_kml_overwrite(self): self._cleanup_layers(name="sample_point_dataset") payload = { "base_file": open(self.valid_kml, "rb"), + "action": "upload" } prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) payload = { "base_file": open(self.valid_kml, "rb"), + "action": "upload" } payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk @@ -359,6 +373,7 @@ class ImporterShapefileImportTest(BaseImporterEndToEndTest): def test_import_shapefile(self): self._cleanup_layers(name="air_Runways") payload = {_filename: open(_file, "rb") for _filename, _file in self.valid_shp.items()} + payload['action'] = "upload" initial_name = "air_Runways" self._assertimport(payload, initial_name) self._cleanup_layers(name="air_Runways") @@ -369,11 +384,13 @@ def test_import_shapefile_overwrite(self): self._cleanup_layers(name="air_Runways") payload = {_filename: open(_file, "rb") for _filename, _file in self.valid_shp.items()} + payload['action'] = "upload" initial_name = "air_Runways" prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) payload = {_filename: open(_file, "rb") for _filename, _file in self.valid_shp.items()} payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk + payload['action'] = "upload" self._assertimport( payload, initial_name, overwrite=True, last_update=prev_dataset.last_updated, keep_resource=True ) @@ -388,6 +405,7 @@ def test_import_raster(self): payload = { "base_file": open(self.valid_tif, "rb"), + "action": "upload" } initial_name = "test_raster" self._assertimport(payload, initial_name) @@ -401,11 +419,13 @@ def test_import_raster_overwrite(self): self._cleanup_layers(name="test_raster") payload = { "base_file": open(self.valid_tif, "rb"), + "action": "upload" } prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) payload = { "base_file": open(self.valid_tif, "rb"), + "action": "upload" } initial_name = "test_raster" payload["overwrite_existing_layer"] = True @@ -422,6 +442,7 @@ def test_import_3dtiles(self): "url": "https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/main/1.1/TilesetWithFullMetadata/tileset.json", "title": "Remote Title", "type": "3dtiles", + "action": "upload" } initial_name = "remote_title" assert_payload = { @@ -438,6 +459,7 @@ def test_import_3dtiles_overwrite(self): "url": "https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/main/1.1/TilesetWithFullMetadata/tileset.json", "title": "Remote Title", "type": "3dtiles", + "action": "upload" } initial_name = "remote_title" assert_payload = { @@ -485,6 +507,7 @@ def test_import_wms(self): "type": "wms", "lookup": resource_to_take, "parse_remote_metadata": True, + "action": "upload" } initial_name = res.title assert_payload = { diff --git a/geonode/upload/tests/end2end/test_end2end_copy.py b/geonode/upload/tests/end2end/test_end2end_copy.py index 630e16962b4..b8e059e1935 100644 --- a/geonode/upload/tests/end2end/test_end2end_copy.py +++ b/geonode/upload/tests/end2end/test_end2end_copy.py @@ -85,6 +85,7 @@ def _assertCloning(self, initial_name): # defining the payload payload = QueryDict("", mutable=True) payload.update({"defaults": '{"title":"title_of_the_cloned_resource"}'}) + payload['action'] = "copy" # calling the endpoint response = self.client.put(_url, data=payload, content_type="application/json") @@ -113,6 +114,7 @@ def _assertCloning(self, initial_name): self.assertTrue(schema_entity.name in [y.name for y in resources]) def _import_resource(self, payload, initial_name): + payload['action'] = "upload" _url = reverse("importer_upload") self.client.force_login(get_user_model().objects.get(username="admin")) @@ -149,6 +151,7 @@ class ImporterCopyEnd2EndGpkgTest(BaseClassEnd2End): def test_copy_dataset_from_geopackage(self): payload = { "base_file": open(self.valid_gkpg, "rb"), + "action": "copy" } initial_name = "stazioni_metropolitana" # first we need to import a resource @@ -170,6 +173,7 @@ class ImporterCopyEnd2EndGeoJsonTest(BaseClassEnd2End): def test_copy_dataset_from_geojson(self): payload = { "base_file": open(self.valid_geojson, "rb"), + "action": "copy" } initial_name = "valid" # first we need to import a resource @@ -189,6 +193,7 @@ class ImporterCopyEnd2EndShapeFileTest(BaseClassEnd2End): @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_copy_dataset_from_shapefile(self): payload = {_filename: open(_file, "rb") for _filename, _file in self.valid_shp.items()} + payload['action'] = "copy" initial_name = "air_runways" # first we need to import a resource with transaction.atomic(): @@ -208,6 +213,7 @@ class ImporterCopyEnd2EndKMLTest(BaseClassEnd2End): def test_copy_dataset_from_kml(self): payload = { "base_file": open(self.valid_kml, "rb"), + "action": "copy" } initial_name = "sample_point_dataset" # first we need to import a resource diff --git a/geonode/upload/tests/unit/test_dastore.py b/geonode/upload/tests/unit/test_dastore.py index 361b67f028a..0dc8faa7ef1 100644 --- a/geonode/upload/tests/unit/test_dastore.py +++ b/geonode/upload/tests/unit/test_dastore.py @@ -37,7 +37,7 @@ def setUp(self): user=self.user, func_name="create", step="create", - action="import", + action="upload", input_params={ **{"handler_module_path": "geonode.upload.handlers.gpkg.handler.GPKGFileHandler"}, }, @@ -51,7 +51,7 @@ def setUp(self): user=self.user, func_name="create", step="create", - action="import", + action="upload", input_params={"url": "https://geosolutionsgroup.com"}, source="importer_copy", ) diff --git a/geonode/upload/tests/unit/test_orchestrator.py b/geonode/upload/tests/unit/test_orchestrator.py index a8ddf8efd5b..252ac1ef183 100644 --- a/geonode/upload/tests/unit/test_orchestrator.py +++ b/geonode/upload/tests/unit/test_orchestrator.py @@ -102,12 +102,13 @@ def test_create_execution_request(self): } exec_id = self.orchestrator.create_execution_request( user=get_user_model().objects.first(), - func_name=next(iter(handler.get_task_list(action="import"))), - step=next(iter(handler.get_task_list(action="import"))), + func_name=next(iter(handler.get_task_list(action="upload"))), + step=next(iter(handler.get_task_list(action="upload"))), input_params={ "files": {"base_file": "/tmp/file.txt"}, "store_spatial_files": True, }, + action='upload' ) exec_obj = ExecutionRequest.objects.filter(exec_id=exec_id).first() self.assertEqual(count + 1, ExecutionRequest.objects.count()) @@ -120,7 +121,7 @@ def test_perform_next_step(self, mock_celery): handler = self.orchestrator.load_handler("geonode.upload.handlers.gpkg.handler.GPKGFileHandler") _id = self.orchestrator.create_execution_request( user=get_user_model().objects.first(), - func_name=next(iter(handler.get_task_list(action="import"))), + func_name=next(iter(handler.get_task_list(action="upload"))), step="start_import", # adding the first step for the GPKG file input_params={ "files": {"base_file": "/tmp/file.txt"}, @@ -130,7 +131,7 @@ def test_perform_next_step(self, mock_celery): # test under tests self.orchestrator.perform_next_step( _id, - "import", + "upload", step="start_import", handler_module_path="geonode.upload.handlers.gpkg.handler.GPKGFileHandler", ) @@ -144,17 +145,18 @@ def test_perform_last_import_step(self, mock_celery): handler = self.orchestrator.load_handler("geonode.upload.handlers.gpkg.handler.GPKGFileHandler") _id = self.orchestrator.create_execution_request( user=get_user_model().objects.first(), - func_name=next(iter(handler.get_task_list(action="import"))), + func_name=next(iter(handler.get_task_list(action="upload"))), step="geonode.upload.create_geonode_resource", # adding the first step for the GPKG file input_params={ "files": {"base_file": "/tmp/file.txt"}, "store_spatial_files": True, }, + action='upload' ) # test under tests self.orchestrator.perform_next_step( _id, - "import", + "upload", step="geonode.upload.create_geonode_resource", handler_module_path="geonode.upload.handlers.gpkg.handler.GPKGFileHandler", ) @@ -167,7 +169,7 @@ def test_perform_with_error_set_invalid_status(self, mock_celery): handler = self.orchestrator.load_handler("geonode.upload.handlers.gpkg.handler.GPKGFileHandler") _id = self.orchestrator.create_execution_request( user=get_user_model().objects.first(), - func_name=next(iter(handler.get_task_list(action="import"))), + func_name=next(iter(handler.get_task_list(action="upload"))), step="start_import", # adding the first step for the GPKG file input_params={ "files": {"base_file": "/tmp/file.txt"}, @@ -178,7 +180,7 @@ def test_perform_with_error_set_invalid_status(self, mock_celery): with self.assertRaises(Exception): self.orchestrator.perform_next_step( _id, - "import", + "upload", step="start_import", handler_module_path="geonode.upload.handlers.gpkg.handler.GPKGFileHandler", ) diff --git a/geonode/upload/tests/unit/test_publisher.py b/geonode/upload/tests/unit/test_publisher.py index 0117d0a5760..9d7f7e06e10 100644 --- a/geonode/upload/tests/unit/test_publisher.py +++ b/geonode/upload/tests/unit/test_publisher.py @@ -60,7 +60,7 @@ def test_extract_resource_name_and_crs(self): """ values_found = self.publisher.extract_resource_to_publish( files={"base_file": self.gpkg_path}, - action="import", + action="upload", layer_name="stazioni_metropolitana", ) expected = {"crs": "EPSG:32632", "name": "stazioni_metropolitana"} @@ -75,7 +75,7 @@ def test_extract_resource_name_and_crs_return_empty_if_the_file_does_not_exists( """ values_found = self.publisher.extract_resource_to_publish( files={"base_file": "/wrong/path/file.gpkg"}, - action="import", + action="upload", layer_name="stazioni_metropolitana", ) self.assertListEqual([], values_found) diff --git a/geonode/upload/tests/unit/test_task.py b/geonode/upload/tests/unit/test_task.py index 09a90881620..6e67b186091 100644 --- a/geonode/upload/tests/unit/test_task.py +++ b/geonode/upload/tests/unit/test_task.py @@ -304,7 +304,7 @@ def test_create_geonode_resource(self, import_orchestrator): layer_name="foo_dataset", alternate="alternate_foo_dataset", handler_module_path="geonode.upload.handlers.gpkg.handler.GPKGFileHandler", - action="import", + action="upload", ) # Evaluation @@ -401,7 +401,7 @@ def test_rollback_works_as_expected_vector_step( user=get_user_model().objects.get(username=self.user), func_name="dummy_func", step=conf[0], # step name - action="import", + action="upload", input_params={ "files": {"base_file": self.existing_file}, "store_spatial_files": True, @@ -456,7 +456,7 @@ def test_rollback_works_as_expected_raster( user=get_user_model().objects.get(username=self.user), func_name="dummy_func", step=conf[0], # step name - action="import", + action="upload", input_params={ "files": {"base_file": "/tmp/filepath"}, "store_spatial_files": True, From 88770fc5b1591090492ff2efc6c64593a9dcd2a0 Mon Sep 17 00:00:00 2001 From: Mattia Date: Fri, 18 Oct 2024 12:20:54 +0200 Subject: [PATCH 6/9] [Fixes #12657] Refactor supported type, fix data retriever and refactor handlers configuration --- geonode/upload/api/tests.py | 17 ++-- geonode/upload/tests/end2end/test_end2end.py | 98 +++++-------------- .../upload/tests/end2end/test_end2end_copy.py | 21 ++-- .../upload/tests/unit/test_orchestrator.py | 4 +- 4 files changed, 38 insertions(+), 102 deletions(-) diff --git a/geonode/upload/api/tests.py b/geonode/upload/api/tests.py index a6a2897058e..95f722715c9 100644 --- a/geonode/upload/api/tests.py +++ b/geonode/upload/api/tests.py @@ -62,10 +62,7 @@ def test_upload_method_not_allowed(self): def test_raise_exception_if_file_is_not_a_handled(self): self.client.force_login(get_user_model().objects.get(username="admin")) - payload = { - "base_file": SimpleUploadedFile(name="file.invalid", content=b"abc"), - "action": "upload" - } + payload = {"base_file": SimpleUploadedFile(name="file.invalid", content=b"abc"), "action": "upload"} response = self.client.post(self.url, data=payload) self.assertEqual(500, response.status_code) @@ -77,7 +74,7 @@ def test_gpkg_raise_error_with_invalid_payload(self): content=b'{"type": "FeatureCollection", "content": "some-content"}', ), "store_spatial_files": "invalid", - "action": "upload" + "action": "upload", } expected = { "success": False, @@ -101,7 +98,7 @@ def test_gpkg_task_is_called(self, patch_upload): content=b'{"type": "FeatureCollection", "content": "some-content"}', ), "store_spatial_files": True, - "action": "upload" + "action": "upload", } response = self.client.post(self.url, data=payload) @@ -119,7 +116,7 @@ def test_geojson_task_is_called(self, patch_upload): content=b'{"type": "FeatureCollection", "content": "some-content"}', ), "store_spatial_files": True, - "action": "upload" + "action": "upload", } response = self.client.post(self.url, data=payload) @@ -137,7 +134,7 @@ def test_zip_file_is_unzip_and_the_handler_is_found(self, patch_upload): "base_file": open(f"{project_dir}/tests/fixture/valid.zip", "rb"), "zip_file": open(f"{project_dir}/tests/fixture/valid.zip", "rb"), "store_spatial_files": True, - "action": "upload" + "action": "upload", } response = self.client.post(self.url, data=payload) @@ -196,7 +193,7 @@ def test_asset_is_created_before_the_import_start(self, patch_upload): content=b'{"type": "FeatureCollection", "content": "some-content"}', ), "store_spatial_files": True, - "action": "upload" + "action": "upload", } response = self.client.post(self.url, data=payload) @@ -227,7 +224,7 @@ def test_asset_should_be_deleted_if_created_during_with_exception( content=b'{"type": "FeatureCollection", "content": "some-content"}', ), "store_spatial_files": True, - "action": "upload" + "action": "upload", } response = self.client.post(self.url, data=payload) diff --git a/geonode/upload/tests/end2end/test_end2end.py b/geonode/upload/tests/end2end/test_end2end.py index bb75c0d0963..f0a493b144e 100644 --- a/geonode/upload/tests/end2end/test_end2end.py +++ b/geonode/upload/tests/end2end/test_end2end.py @@ -176,10 +176,7 @@ class ImporterGeoPackageImportTest(BaseImporterEndToEndTest): def test_import_geopackage(self): self._cleanup_layers(name="stazioni_metropolitana") - payload = { - "base_file": open(self.valid_gkpg, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_gkpg, "rb"), "action": "upload"} initial_name = "stazioni_metropolitana" self._assertimport(payload, initial_name) self._cleanup_layers(name="stazioni_metropolitana") @@ -189,16 +186,10 @@ def test_import_geopackage(self): def test_import_gpkg_overwrite(self): self._cleanup_layers(name="stazioni_metropolitana") initial_name = "stazioni_metropolitana" - payload = { - "base_file": open(self.valid_gkpg, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_gkpg, "rb"), "action": "upload"} prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) - payload = { - "base_file": open(self.valid_gkpg, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_gkpg, "rb"), "action": "upload"} payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk self._assertimport(payload, initial_name, overwrite=True, last_update=prev_dataset.last_updated) @@ -213,10 +204,7 @@ class ImporterNoCRSImportTest(BaseImporterEndToEndTest): def test_import_geopackage_with_no_crs_table(self): self._cleanup_layers(name="mattia_test") - payload = { - "base_file": open(self.no_crs_gpkg, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.no_crs_gpkg, "rb"), "action": "upload"} initial_name = "mattia_test" with self.assertLogs(level="ERROR") as _log: self._assertimport(payload, initial_name) @@ -239,11 +227,7 @@ def test_import_geopackage_with_no_crs_table_should_raise_error_if_all_layer_are _select_valid_layers.return_value = [] self._cleanup_layers(name="mattia_test") - payload = { - "base_file": open(self.no_crs_gpkg, "rb"), - "store_spatial_file": True, - "action": "upload" - } + payload = {"base_file": open(self.no_crs_gpkg, "rb"), "store_spatial_file": True, "action": "upload"} with self.assertLogs(level="ERROR") as _log: self.client.force_login(self.admin) @@ -266,10 +250,7 @@ def test_import_geojson(self): self._cleanup_layers(name="valid") - payload = { - "base_file": open(self.valid_geojson, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_geojson, "rb"), "action": "upload"} initial_name = "valid" self._assertimport(payload, initial_name) @@ -279,16 +260,10 @@ def test_import_geojson(self): @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_import_geojson_overwrite(self): self._cleanup_layers(name="valid") - payload = { - "base_file": open(self.valid_geojson, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_geojson, "rb"), "action": "upload"} initial_name = "valid" prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) - payload = { - "base_file": open(self.valid_geojson, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_geojson, "rb"), "action": "upload"} payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk self._assertimport(payload, initial_name, overwrite=True, last_update=prev_dataset.last_updated) @@ -302,10 +277,7 @@ class ImporterGCSVImportTest(BaseImporterEndToEndTest): def test_import_geojson(self): self._cleanup_layers(name="valid") - payload = { - "base_file": open(self.valid_csv, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_csv, "rb"), "action": "upload"} initial_name = "valid" self._assertimport(payload, initial_name) self._cleanup_layers(name="valid") @@ -314,17 +286,11 @@ def test_import_geojson(self): @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_import_csv_overwrite(self): self._cleanup_layers(name="valid") - payload = { - "base_file": open(self.valid_csv, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_csv, "rb"), "action": "upload"} initial_name = "valid" prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) - payload = { - "base_file": open(self.valid_csv, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_csv, "rb"), "action": "upload"} initial_name = "valid" payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk @@ -337,10 +303,7 @@ class ImporterKMLImportTest(BaseImporterEndToEndTest): @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_import_kml(self): self._cleanup_layers(name="sample_point_dataset") - payload = { - "base_file": open(self.valid_kml, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_kml, "rb"), "action": "upload"} initial_name = "sample_point_dataset" self._assertimport(payload, initial_name) self._cleanup_layers(name="sample_point_dataset") @@ -351,16 +314,10 @@ def test_import_kml_overwrite(self): initial_name = "sample_point_dataset" self._cleanup_layers(name="sample_point_dataset") - payload = { - "base_file": open(self.valid_kml, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_kml, "rb"), "action": "upload"} prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) - payload = { - "base_file": open(self.valid_kml, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_kml, "rb"), "action": "upload"} payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk self._assertimport(payload, initial_name, overwrite=True, last_update=prev_dataset.last_updated) @@ -373,7 +330,7 @@ class ImporterShapefileImportTest(BaseImporterEndToEndTest): def test_import_shapefile(self): self._cleanup_layers(name="air_Runways") payload = {_filename: open(_file, "rb") for _filename, _file in self.valid_shp.items()} - payload['action'] = "upload" + payload["action"] = "upload" initial_name = "air_Runways" self._assertimport(payload, initial_name) self._cleanup_layers(name="air_Runways") @@ -384,13 +341,13 @@ def test_import_shapefile_overwrite(self): self._cleanup_layers(name="air_Runways") payload = {_filename: open(_file, "rb") for _filename, _file in self.valid_shp.items()} - payload['action'] = "upload" + payload["action"] = "upload" initial_name = "air_Runways" prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) payload = {_filename: open(_file, "rb") for _filename, _file in self.valid_shp.items()} payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk - payload['action'] = "upload" + payload["action"] = "upload" self._assertimport( payload, initial_name, overwrite=True, last_update=prev_dataset.last_updated, keep_resource=True ) @@ -403,10 +360,7 @@ class ImporterRasterImportTest(BaseImporterEndToEndTest): def test_import_raster(self): self._cleanup_layers(name="test_raster") - payload = { - "base_file": open(self.valid_tif, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_tif, "rb"), "action": "upload"} initial_name = "test_raster" self._assertimport(payload, initial_name) self._cleanup_layers(name="test_raster") @@ -417,16 +371,10 @@ def test_import_raster_overwrite(self): initial_name = "test_raster" self._cleanup_layers(name="test_raster") - payload = { - "base_file": open(self.valid_tif, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_tif, "rb"), "action": "upload"} prev_dataset = self._assertimport(payload, initial_name, keep_resource=True) - payload = { - "base_file": open(self.valid_tif, "rb"), - "action": "upload" - } + payload = {"base_file": open(self.valid_tif, "rb"), "action": "upload"} initial_name = "test_raster" payload["overwrite_existing_layer"] = True payload["resource_pk"] = prev_dataset.pk @@ -442,7 +390,7 @@ def test_import_3dtiles(self): "url": "https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/main/1.1/TilesetWithFullMetadata/tileset.json", "title": "Remote Title", "type": "3dtiles", - "action": "upload" + "action": "upload", } initial_name = "remote_title" assert_payload = { @@ -459,7 +407,7 @@ def test_import_3dtiles_overwrite(self): "url": "https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/main/1.1/TilesetWithFullMetadata/tileset.json", "title": "Remote Title", "type": "3dtiles", - "action": "upload" + "action": "upload", } initial_name = "remote_title" assert_payload = { @@ -507,7 +455,7 @@ def test_import_wms(self): "type": "wms", "lookup": resource_to_take, "parse_remote_metadata": True, - "action": "upload" + "action": "upload", } initial_name = res.title assert_payload = { diff --git a/geonode/upload/tests/end2end/test_end2end_copy.py b/geonode/upload/tests/end2end/test_end2end_copy.py index b8e059e1935..a66eacc09ca 100644 --- a/geonode/upload/tests/end2end/test_end2end_copy.py +++ b/geonode/upload/tests/end2end/test_end2end_copy.py @@ -85,7 +85,7 @@ def _assertCloning(self, initial_name): # defining the payload payload = QueryDict("", mutable=True) payload.update({"defaults": '{"title":"title_of_the_cloned_resource"}'}) - payload['action'] = "copy" + payload["action"] = "copy" # calling the endpoint response = self.client.put(_url, data=payload, content_type="application/json") @@ -114,7 +114,7 @@ def _assertCloning(self, initial_name): self.assertTrue(schema_entity.name in [y.name for y in resources]) def _import_resource(self, payload, initial_name): - payload['action'] = "upload" + payload["action"] = "upload" _url = reverse("importer_upload") self.client.force_login(get_user_model().objects.get(username="admin")) @@ -149,10 +149,7 @@ class ImporterCopyEnd2EndGpkgTest(BaseClassEnd2End): ) @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_copy_dataset_from_geopackage(self): - payload = { - "base_file": open(self.valid_gkpg, "rb"), - "action": "copy" - } + payload = {"base_file": open(self.valid_gkpg, "rb"), "action": "copy"} initial_name = "stazioni_metropolitana" # first we need to import a resource with transaction.atomic(): @@ -171,10 +168,7 @@ class ImporterCopyEnd2EndGeoJsonTest(BaseClassEnd2End): ) @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_copy_dataset_from_geojson(self): - payload = { - "base_file": open(self.valid_geojson, "rb"), - "action": "copy" - } + payload = {"base_file": open(self.valid_geojson, "rb"), "action": "copy"} initial_name = "valid" # first we need to import a resource with transaction.atomic(): @@ -193,7 +187,7 @@ class ImporterCopyEnd2EndShapeFileTest(BaseClassEnd2End): @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_copy_dataset_from_shapefile(self): payload = {_filename: open(_file, "rb") for _filename, _file in self.valid_shp.items()} - payload['action'] = "copy" + payload["action"] = "copy" initial_name = "air_runways" # first we need to import a resource with transaction.atomic(): @@ -211,10 +205,7 @@ class ImporterCopyEnd2EndKMLTest(BaseClassEnd2End): ) @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data") def test_copy_dataset_from_kml(self): - payload = { - "base_file": open(self.valid_kml, "rb"), - "action": "copy" - } + payload = {"base_file": open(self.valid_kml, "rb"), "action": "copy"} initial_name = "sample_point_dataset" # first we need to import a resource with transaction.atomic(): diff --git a/geonode/upload/tests/unit/test_orchestrator.py b/geonode/upload/tests/unit/test_orchestrator.py index 252ac1ef183..a1f11c1f6ae 100644 --- a/geonode/upload/tests/unit/test_orchestrator.py +++ b/geonode/upload/tests/unit/test_orchestrator.py @@ -108,7 +108,7 @@ def test_create_execution_request(self): "files": {"base_file": "/tmp/file.txt"}, "store_spatial_files": True, }, - action='upload' + action="upload", ) exec_obj = ExecutionRequest.objects.filter(exec_id=exec_id).first() self.assertEqual(count + 1, ExecutionRequest.objects.count()) @@ -151,7 +151,7 @@ def test_perform_last_import_step(self, mock_celery): "files": {"base_file": "/tmp/file.txt"}, "store_spatial_files": True, }, - action='upload' + action="upload", ) # test under tests self.orchestrator.perform_next_step( From 005a00dbf48540ca36220036c09fd483824700fd Mon Sep 17 00:00:00 2001 From: Mattia Date: Fri, 18 Oct 2024 12:51:49 +0200 Subject: [PATCH 7/9] [Fixes #12657] Refactor supported type, fix data retriever and refactor handlers configuration --- geonode/resource/api/tests.py | 4 +--- geonode/resource/models.py | 2 -- geonode/security/tests.py | 4 +--- geonode/upload/api/views.py | 1 - geonode/upload/handlers/remote/tests/test_wms.py | 4 +--- geonode/upload/handlers/tiles3d/tests.py | 2 +- geonode/upload/orchestrator.py | 1 - geonode/upload/tests/end2end/test_end2end.py | 6 ++---- geonode/upload/tests/unit/test_dastore.py | 2 -- 9 files changed, 6 insertions(+), 20 deletions(-) diff --git a/geonode/resource/api/tests.py b/geonode/resource/api/tests.py index a93af1ffe0e..72756f2179a 100644 --- a/geonode/resource/api/tests.py +++ b/geonode/resource/api/tests.py @@ -157,9 +157,7 @@ def test_endpoint_should_raise_error_if_pk_is_not_passed(self): def test_endpoint_should_return_the_source(self): # creating dummy execution request - obj = ExecutionRequest.objects.create( - user=self.superuser, func_name="import_new_resource", action="upload", source="upload_workflow" - ) + obj = ExecutionRequest.objects.create(user=self.superuser, func_name="import_new_resource", action="upload") self.client.force_login(self.superuser) _url = f"{reverse('executionrequest-list')}/{obj.exec_id}" diff --git a/geonode/resource/models.py b/geonode/resource/models.py index 791b9f65d0f..f6993492225 100644 --- a/geonode/resource/models.py +++ b/geonode/resource/models.py @@ -60,5 +60,3 @@ class ExecutionRequest(models.Model): action = models.CharField( max_length=50, choices=ACTION_CHOICES, default=ExecutionRequestAction.UNKNOWN.value, null=True ) - - source = models.CharField(max_length=250, null=True, default=None) diff --git a/geonode/security/tests.py b/geonode/security/tests.py index d2707531bad..2c634ecabea 100644 --- a/geonode/security/tests.py +++ b/geonode/security/tests.py @@ -752,9 +752,7 @@ def test_dataset_permissions(self): bobby = get_user_model().objects.get(username="bobby") self.client.force_login(get_user_model().objects.get(username="admin")) - payload = { - "base_file": open(f"{project_dir}/tests/fixture/valid.geojson", "rb"), - } + payload = {"base_file": open(f"{project_dir}/tests/fixture/valid.geojson", "rb"), "action": "upload"} response = self.client.post(reverse("importer_upload"), data=payload) layer = ResourceHandlerInfo.objects.filter(execution_request=response.json()["execution_id"]).first().resource if layer is None: diff --git a/geonode/upload/api/views.py b/geonode/upload/api/views.py index d3122d0d99b..67fafe6a300 100644 --- a/geonode/upload/api/views.py +++ b/geonode/upload/api/views.py @@ -324,7 +324,6 @@ def copy(self, request, *args, **kwargs): **{"handler_module_path": handler_module_path}, **extracted_params, }, - source="importer_copy", ) sig = import_orchestrator.s( diff --git a/geonode/upload/handlers/remote/tests/test_wms.py b/geonode/upload/handlers/remote/tests/test_wms.py index 7099f72264f..1bb00c1a71a 100644 --- a/geonode/upload/handlers/remote/tests/test_wms.py +++ b/geonode/upload/handlers/remote/tests/test_wms.py @@ -35,9 +35,7 @@ class TestRemoteWMSResourceHandler(TestCase): def setUpClass(cls): super().setUpClass() cls.handler = RemoteWMSResourceHandler() - cls.valid_url = ( - "https://development.demo.geonode.org/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities" - ) + cls.valid_url = "http://geoserver:8080/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities" cls.user, _ = get_user_model().objects.get_or_create(username="admin") cls.invalid_payload = { "url": "http://invalid.com", diff --git a/geonode/upload/handlers/tiles3d/tests.py b/geonode/upload/handlers/tiles3d/tests.py index 612489b1352..225fcadf0fc 100755 --- a/geonode/upload/handlers/tiles3d/tests.py +++ b/geonode/upload/handlers/tiles3d/tests.py @@ -196,7 +196,7 @@ def test_supported_file_extension_config(self): "required_ext": ["zip"], } ], - "actions": list(self.TASKS.keys()), + "actions": list(Tiles3DFileHandler.TASKS.keys()), "type": "vector", } actual = self.handler.supported_file_extension_config diff --git a/geonode/upload/orchestrator.py b/geonode/upload/orchestrator.py index fdb146b44bc..a3d9ecab88a 100644 --- a/geonode/upload/orchestrator.py +++ b/geonode/upload/orchestrator.py @@ -310,7 +310,6 @@ def create_execution_request( input_params=input_params, action=action, name=name, - source=source, ) return execution.exec_id diff --git a/geonode/upload/tests/end2end/test_end2end.py b/geonode/upload/tests/end2end/test_end2end.py index f0a493b144e..c574214252b 100644 --- a/geonode/upload/tests/end2end/test_end2end.py +++ b/geonode/upload/tests/end2end/test_end2end.py @@ -444,13 +444,11 @@ class ImporterWMSImportTest(BaseImporterEndToEndTest): @mock.patch.dict(os.environ, {"GEONODE_GEODATABASE": "test_geonode_data", "ASYNC_SIGNALS": "False"}) @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data", ASYNC_SIGNALS=False) def test_import_wms(self): - _, wms = WebMapService( - "https://development.demo.geonode.org/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities" - ) + _, wms = WebMapService("http://geoserver:8080/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities") resource_to_take = next(iter(wms.contents)) res = wms[next(iter(wms.contents))] payload = { - "url": "https://development.demo.geonode.org/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities", + "url": "http://geoserver:8080/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities", "title": "Remote Title", "type": "wms", "lookup": resource_to_take, diff --git a/geonode/upload/tests/unit/test_dastore.py b/geonode/upload/tests/unit/test_dastore.py index 0dc8faa7ef1..fd9b504c3cf 100644 --- a/geonode/upload/tests/unit/test_dastore.py +++ b/geonode/upload/tests/unit/test_dastore.py @@ -41,7 +41,6 @@ def setUp(self): input_params={ **{"handler_module_path": "geonode.upload.handlers.gpkg.handler.GPKGFileHandler"}, }, - source="importer_copy", ) self.datastore = DataStoreManager( self.files, "geonode.upload.handlers.gpkg.handler.GPKGFileHandler", self.user, execution_id @@ -53,7 +52,6 @@ def setUp(self): step="create", action="upload", input_params={"url": "https://geosolutionsgroup.com"}, - source="importer_copy", ) self.datastore_url = DataStoreManager( self.files, "geonode.upload.handlers.common.remote.BaseRemoteResourceHandler", self.user, execution_id_url From 544b58f233b32e677bb958b8c84b6efc89ffb3d2 Mon Sep 17 00:00:00 2001 From: Mattia Date: Fri, 18 Oct 2024 16:21:36 +0200 Subject: [PATCH 8/9] [Fixes #12657] Refactor supported type, fix data retriever and refactor handlers configuration --- ...remove_executionrequest_source_and_more.py | 37 +++++++++++++++++++ geonode/upload/handlers/sld/handler.py | 4 +- geonode/upload/handlers/sld/tests.py | 6 +-- geonode/upload/utils.py | 2 +- geonode/utils.py | 2 +- 5 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 geonode/resource/migrations/0009_remove_executionrequest_source_and_more.py diff --git a/geonode/resource/migrations/0009_remove_executionrequest_source_and_more.py b/geonode/resource/migrations/0009_remove_executionrequest_source_and_more.py new file mode 100644 index 00000000000..c547801136b --- /dev/null +++ b/geonode/resource/migrations/0009_remove_executionrequest_source_and_more.py @@ -0,0 +1,37 @@ +# Generated by Django 4.2.9 on 2024-10-18 10:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("resource", "0008_executionrequest_source"), + ] + + operations = [ + migrations.RemoveField( + model_name="executionrequest", + name="source", + ), + migrations.AlterField( + model_name="executionrequest", + name="action", + field=models.CharField( + choices=[ + ("import", "import"), + ("upload", "upload"), + ("create", "create"), + ("copy", "copy"), + ("delete", "delete"), + ("permissions", "permissions"), + ("update", "update"), + ("ingest", "ingest"), + ("unknown", "unknown"), + ], + default="unknown", + max_length=50, + null=True, + ), + ), + ] diff --git a/geonode/upload/handlers/sld/handler.py b/geonode/upload/handlers/sld/handler.py index 9dc62364c78..14c5efb736f 100644 --- a/geonode/upload/handlers/sld/handler.py +++ b/geonode/upload/handlers/sld/handler.py @@ -34,7 +34,7 @@ class SLDFileHandler(MetadataFileHandler): """ TASKS = { - ira.RESOURCE_SLD_UPLOAD.value: ("start_import", "geonode.upload.import_resource"), + ira.RESOURCE_STYLE_UPLOAD.value: ("start_import", "geonode.upload.import_resource"), ira.ROLLBACK.value: ( "start_rollback", "geonode.upload.rollback", @@ -66,7 +66,7 @@ def can_handle(_data) -> bool: return False return (base.endswith(".sld") if isinstance(base, str) else base.name.endswith(".sld")) and _data.get( "action", None - ) == ira.RESOURCE_SLD_UPLOAD.value + ) == ira.RESOURCE_STYLE_UPLOAD.value @staticmethod def is_valid(files, user, **kwargs): diff --git a/geonode/upload/handlers/sld/tests.py b/geonode/upload/handlers/sld/tests.py index 823f1c175fb..2cbc7931382 100644 --- a/geonode/upload/handlers/sld/tests.py +++ b/geonode/upload/handlers/sld/tests.py @@ -45,7 +45,7 @@ def setUpClass(cls): cls.valid_files = { "base_file": "/tmp/test_sld.sld", "sld_file": "/tmp/test_sld.sld", - "action": "resource_sld_upload", + "action": "resource_style_upload", } cls.owner = get_user_model().objects.first() cls.layer = create_single_dataset(name="sld_dataset", owner=cls.owner) @@ -59,8 +59,8 @@ def test_task_list_is_the_expected_one(self): "start_import", "geonode.upload.import_resource", ) - self.assertEqual(len(self.handler.TASKS["resource_sld_upload"]), 2) - self.assertTupleEqual(expected, self.handler.TASKS["resource_sld_upload"]) + self.assertEqual(len(self.handler.TASKS["resource_style_upload"]), 2) + self.assertTupleEqual(expected, self.handler.TASKS["resource_style_upload"]) def test_is_valid_should_raise_exception_if_the_sld_is_invalid(self): with self.assertRaises(InvalidSldException) as _exc: diff --git a/geonode/upload/utils.py b/geonode/upload/utils.py index 0dbcb246864..0e3750e2ece 100644 --- a/geonode/upload/utils.py +++ b/geonode/upload/utils.py @@ -51,7 +51,7 @@ def get_max_upload_parallelism_limit(slug): class ImporterRequestAction(enum.Enum): ROLLBACK = _("rollback") RESOURCE_METADATA_UPLOAD = _("resource_metadata_upload") - RESOURCE_SLD_UPLOAD = _("resource_sld_upload") + RESOURCE_STYLE_UPLOAD = _("resource_style_upload") REPLACE = _("replace") diff --git a/geonode/utils.py b/geonode/utils.py index bb63c8ece31..60261075fa6 100755 --- a/geonode/utils.py +++ b/geonode/utils.py @@ -1728,7 +1728,7 @@ def get_supported_datasets_file_types(): "optional_ext": ["xml", "sld"], } ], - "action": ["upload", "replace"], + "actions": ["upload", "replace"], "type": "archive", } ] From 50f74615a48d56cd282608a0e4c1919bc63f2a20 Mon Sep 17 00:00:00 2001 From: Mattia Date: Fri, 18 Oct 2024 18:05:22 +0200 Subject: [PATCH 9/9] [Fixes #12657] Refactor supported type, fix data retriever and refactor handlers configuration --- geonode/upload/tests/end2end/test_end2end.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/geonode/upload/tests/end2end/test_end2end.py b/geonode/upload/tests/end2end/test_end2end.py index c574214252b..f0a493b144e 100644 --- a/geonode/upload/tests/end2end/test_end2end.py +++ b/geonode/upload/tests/end2end/test_end2end.py @@ -444,11 +444,13 @@ class ImporterWMSImportTest(BaseImporterEndToEndTest): @mock.patch.dict(os.environ, {"GEONODE_GEODATABASE": "test_geonode_data", "ASYNC_SIGNALS": "False"}) @override_settings(GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data", ASYNC_SIGNALS=False) def test_import_wms(self): - _, wms = WebMapService("http://geoserver:8080/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities") + _, wms = WebMapService( + "https://development.demo.geonode.org/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities" + ) resource_to_take = next(iter(wms.contents)) res = wms[next(iter(wms.contents))] payload = { - "url": "http://geoserver:8080/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities", + "url": "https://development.demo.geonode.org/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities", "title": "Remote Title", "type": "wms", "lookup": resource_to_take,