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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions geonode/upload/handlers/tiles3d/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@
the handler is able to handle the file or not
"""
base = _data.get("base_file")
if not base:
try:
base = _data.get("base_file")
if not base:
return False
ext = base.split(".")[-1] if isinstance(base, str) else base.name.split(".")[-1]
if ext in ["json"] and Tiles3DFileHandler.is_3dtiles_json(base):
return True
except Exception:

Check warning on line 89 in geonode/upload/handlers/tiles3d/handler.py

View check run for this annotation

Codecov / codecov/patch

geonode/upload/handlers/tiles3d/handler.py#L89

Added line #L89 was not covered by tests
return False
ext = base.split(".")[-1] if isinstance(base, str) else base.name.split(".")[-1]
if ext in ["json"] and Tiles3DFileHandler.is_3dtiles_json(base):
return True
return False

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated by Django 3.2.15 on 2022-10-04 13:03

import logging
from django.db import migrations
from geonode.upload.orchestrator import orchestrator
from geonode.layers.models import Dataset
from geonode.assets.utils import get_default_asset
from geonode.utils import get_allowed_extensions

logger = logging.getLogger("django")

def dataset_migration(apps, _):
NewResources = apps.get_model("upload", "ResourceHandlerInfo")
for old_resource in Dataset.objects.exclude(
pk__in=NewResources.objects.values_list("resource_id", flat=True)
).exclude(subtype__in=["remote", None]):
# generating orchestrator expected data file
if old_resource.resourcehandlerinfo_set.first() is None:
if get_default_asset(old_resource):
available_choices = get_allowed_extensions()
not_main_files = ["xml", "sld", "zip", "kmz"]

Check warning on line 21 in geonode/upload/migrations/0051__align_resourcehandler_with_asset.py

View check run for this annotation

Codecov / codecov/patch

geonode/upload/migrations/0051__align_resourcehandler_with_asset.py#L20-L21

Added lines #L20 - L21 were not covered by tests
base_file_choices = set(x for x in available_choices if x not in not_main_files)
output_files = dict()

Check warning on line 23 in geonode/upload/migrations/0051__align_resourcehandler_with_asset.py

View check run for this annotation

Codecov / codecov/patch

geonode/upload/migrations/0051__align_resourcehandler_with_asset.py#L23

Added line #L23 was not covered by tests
for _file in get_default_asset(old_resource).location:
if _file.split(".")[-1] in base_file_choices:
output_files.update({"base_file": _file})
break

Check warning on line 27 in geonode/upload/migrations/0051__align_resourcehandler_with_asset.py

View check run for this annotation

Codecov / codecov/patch

geonode/upload/migrations/0051__align_resourcehandler_with_asset.py#L26-L27

Added lines #L26 - L27 were not covered by tests
else:
if old_resource.is_vector():
output_files = {"base_file": "placeholder.shp"}

Check warning on line 30 in geonode/upload/migrations/0051__align_resourcehandler_with_asset.py

View check run for this annotation

Codecov / codecov/patch

geonode/upload/migrations/0051__align_resourcehandler_with_asset.py#L30

Added line #L30 was not covered by tests
else:
output_files = {"base_file": "placeholder.tiff"}

Check warning on line 32 in geonode/upload/migrations/0051__align_resourcehandler_with_asset.py

View check run for this annotation

Codecov / codecov/patch

geonode/upload/migrations/0051__align_resourcehandler_with_asset.py#L32

Added line #L32 was not covered by tests

handler = orchestrator.get_handler(output_files)

Check warning on line 34 in geonode/upload/migrations/0051__align_resourcehandler_with_asset.py

View check run for this annotation

Codecov / codecov/patch

geonode/upload/migrations/0051__align_resourcehandler_with_asset.py#L34

Added line #L34 was not covered by tests
if handler is None:
logger.error(f"Handler not found for resource: {old_resource}")
continue
handler.create_resourcehandlerinfo(

Check warning on line 38 in geonode/upload/migrations/0051__align_resourcehandler_with_asset.py

View check run for this annotation

Codecov / codecov/patch

geonode/upload/migrations/0051__align_resourcehandler_with_asset.py#L36-L38

Added lines #L36 - L38 were not covered by tests
handler_module_path=str(handler),
resource=old_resource,
execution_id=None
)
else:
logger.debug(f"resourcehandler info already exists for the resource")

Check warning on line 44 in geonode/upload/migrations/0051__align_resourcehandler_with_asset.py

View check run for this annotation

Codecov / codecov/patch

geonode/upload/migrations/0051__align_resourcehandler_with_asset.py#L44

Added line #L44 was not covered by tests


class Migration(migrations.Migration):
dependencies = [
("upload", "0050_alter_uploadsizelimit_max_size"),
]

operations = [
migrations.RunPython(dataset_migration),
]
Loading