Skip to content

Commit

Permalink
Merge branch 'ISSUE_247' of github.com:GeoNode/geonode-importer into …
Browse files Browse the repository at this point in the history
…ISSUE_246
  • Loading branch information
mattiagiupponi committed Jun 20, 2024
2 parents cf51cdd + 5c6596a commit 959834c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM geonode/geonode-base:latest-ubuntu-22.04
RUN rm -rf /usr/src/geonode
RUN git clone https://github.com/GeoNode/geonode.git /usr/src/geonode
RUN cd /usr/src/geonode && git fetch --all && git checkout 12226_directory_assets_3 && cd -
RUN cd /usr/src/geonode && git fetch --all && git checkout assets_master && cd -
RUN mkdir -p /usr/src/importer

RUN cd ..
Expand Down
2 changes: 1 addition & 1 deletion importer/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def generate_asset_and_retrieve_paths(self, request, storage_manager, handler):
title="Original",
owner=request.user,
description=None,
type=str(handler),
type=handler.id,
files=list(set(_files.values())),
clone_files=False,
)
Expand Down
12 changes: 11 additions & 1 deletion importer/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from geonode.resource.enumerator import ExecutionRequestAction as exa
from geonode.layers.models import Dataset
from importer.api.exception import ImportException
from importer.utils import ImporterRequestAction as ira
from django_celery_results.models import TaskResult
from django.db.models import Q
Expand Down Expand Up @@ -56,9 +57,18 @@ def get_task_list(cls, action) -> tuple:
def default_geometry_column_name(self):
return "geometry"

@property
def id(self):
pk = self.supported_file_extension_config.get("id", None)
if pk is None:
raise ImportException(
"PK must be defined, check that supported_file_extension_config had been correctly defined, it cannot be empty"
)
return pk

@property
def supported_file_extension_config(self):
return NotImplementedError
return {}

@property
def can_handle_xml_file(self) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion importer/handlers/gpkg/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_single_message_error_handler(self):
title="Original",
owner=user,
description=None,
type="importer.handlers.gpkg.handler.GPKGFileHandler",
type="gpkg",
files=["/tmp/valid.gpkg"],
clone_files=False,
)
Expand Down
7 changes: 7 additions & 0 deletions importer/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def load_handler(self, module_path):
except Exception:
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():
if handler().id == handler_id:
return handler
logger.error("Handler not found")
return None

def get_execution_object(self, exec_id):
"""
Returns the ExecutionRequest object with the detail about the
Expand Down
8 changes: 6 additions & 2 deletions importer/tests/unit/test_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def test_load_handler(self):
)
self.assertIsInstance(actual(), BaseHandler)

def test_load_handler_by_id(self):
actual = self.orchestrator.load_handler_by_id("gpkg")
self.assertIsInstance(actual(), BaseHandler)

def test_get_execution_object_raise_exp_if_not_exists(self):
with self.assertRaises(ImportException) as _exc:
self.orchestrator.get_execution_object(str(uuid.uuid4()))
Expand Down Expand Up @@ -197,7 +201,7 @@ def test_set_as_failed(self):
title="Original",
owner=user,
description=None,
type="importer.handlers.gpkg.handler.GPKGFileHandler",
type="gpkg",
files=[fake_path],
clone_files=False,
)
Expand Down Expand Up @@ -345,7 +349,7 @@ def test_evaluate_execution_progress_should_fail_if_one_task_is_failed(self):
title="Original",
owner=user,
description=None,
type="importer.handlers.gpkg.handler.GPKGFileHandler",
type="gpkg",
files=[fake_path],
clone_files=False,
)
Expand Down
2 changes: 1 addition & 1 deletion importer/tests/unit/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def setUp(self):
title="Original",
owner=self.user,
description=None,
type="importer.handlers.gpkg.handler.GPKGFileHandler",
type="gpkg",
files=[self.existing_file],
clone_files=False,
)
Expand Down

0 comments on commit 959834c

Please sign in to comment.