Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return detail_url for SLD and XML and prepare for the new input params #230

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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

base_file = serializers.FileField()
Expand All @@ -23,3 +24,4 @@ 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')
2 changes: 1 addition & 1 deletion importer/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def create(self, request, *args, **kwargs):
legacy_upload_name=_file.name,
action=action,
name=_file.name,
source="upload",
source=extracted_params.get('source'),
)

sig = import_orchestrator.s(
Expand Down
27 changes: 25 additions & 2 deletions importer/handlers/common/metadata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from geonode.resource.enumerator import ExecutionRequestAction as exa
from importer.handlers.base import BaseHandler
from importer.models import ResourceHandlerInfo
from importer.handlers.xml.serializer import MetadataFileSerializer
from importer.utils import ImporterRequestAction as ira
from importer.orchestrator import orchestrator
Expand Down Expand Up @@ -49,22 +50,44 @@ def extract_params_from_data(_data, action=None):
"skip_existing_layers": _data.pop("skip_existing_layers", "False"),
"overwrite_existing_layer": _data.pop("overwrite_existing_layer", "False"),
"store_spatial_file": _data.pop("store_spatial_files", "True"),
"source": _data.pop("source", "True"),
}, _data

@staticmethod
def perform_last_step(execution_id):
pass
_exec = orchestrator.get_execution_object(execution_id)

_exec.output_params.update(
**{
"detail_url": [
x.resource.detail_url
for x in ResourceHandlerInfo.objects.filter(execution_request=_exec)
]
}
)
_exec.save()

def import_resource(self, files: dict, execution_id: str, **kwargs):
_exec = orchestrator.get_execution_object(execution_id)
# getting the dataset
alternate = _exec.input_params.get("dataset_title")
dataset = get_object_or_404(Dataset, alternate=alternate)
resource_id = _exec.input_params.get("resource_id")
if resource_id:
dataset = get_object_or_404(Dataset, pk=resource_id)
elif alternate:
dataset = get_object_or_404(Dataset, alternate=alternate)

# retrieving the handler used for the dataset
original_handler = orchestrator.load_handler(
dataset.resourcehandlerinfo_set.first().handler_module_path
)()

ResourceHandlerInfo.objects.create(
handler_module_path=dataset.resourcehandlerinfo_set.first().handler_module_path,
resource=dataset,
execution_request=_exec,
kwargs=kwargs.get("kwargs", {}) or kwargs,
)

self.handle_metadata_resource(_exec, dataset, original_handler)

Expand Down
1 change: 1 addition & 0 deletions importer/handlers/common/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def extract_params_from_data(_data, action=None):
"skip_existing_layers": _data.pop("skip_existing_layers", "False"),
"overwrite_existing_layer": _data.pop("overwrite_existing_layer", "False"),
"store_spatial_file": _data.pop("store_spatial_files", "True"),
"source": _data.pop("source", "upload"),
}, _data

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions importer/handlers/common/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def extract_params_from_data(_data, action=None):
"skip_existing_layers": _data.pop("skip_existing_layers", "False"),
"overwrite_existing_layer": _data.pop("overwrite_existing_layer", "False"),
"store_spatial_file": _data.pop("store_spatial_files", "True"),
"source": _data.pop("source", "upload"),
}, _data

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions importer/handlers/shapefile/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def extract_params_from_data(_data, action=None):
"skip_existing_layers": _data.pop("skip_existing_layers", "False"),
"overwrite_existing_layer": _data.pop("overwrite_existing_layer", "False"),
"store_spatial_file": _data.pop("store_spatial_files", "True"),
"source": _data.pop("source", "upload"),
}

return additional_params, _data
Expand Down
2 changes: 2 additions & 0 deletions importer/handlers/shapefile/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Meta:
"store_spatial_files",
"overwrite_existing_layer",
"skip_existing_layers",
"source"
)

base_file = serializers.FileField()
Expand All @@ -29,3 +30,4 @@ 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')
3 changes: 2 additions & 1 deletion importer/handlers/xml/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class Meta:
ref_name = "MetadataFileSerializer"
model = Upload
view_name = "importer_upload"
fields = ("dataset_title", "base_file")
fields = ("dataset_title", "base_file", "source")

base_file = serializers.FileField()
dataset_title = serializers.CharField(required=True)
source = serializers.CharField(required=False, default='resource_file_upload')