Skip to content

Commit

Permalink
[Fixes #12789] Improve 3dtiles filename handling (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi authored Jan 15, 2025
1 parent fe4ccb5 commit f9e7a74
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions importer/handlers/tiles3d/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def can_handle(_data) -> bool:
if not base:
return False
ext = base.split(".")[-1] if isinstance(base, str) else base.name.split(".")[-1]
input_filename = os.path.basename(base if isinstance(base, str) else base.name)
if ext in ["json"] and "tileset.json" in input_filename:
if ext in ["json"] and Tiles3DFileHandler.is_3dtiles_json(base):
return True
return False

Expand Down Expand Up @@ -90,25 +89,29 @@ def is_valid(files, user):
)

try:
with open(_file, "r") as _readed_file:
_file = json.loads(_readed_file.read())
# required key described in the specification of 3dtiles
# https://docs.ogc.org/cs/22-025r4/22-025r4.html#toc92
is_valid = all(
key in _file.keys() for key in ("asset", "geometricError", "root")
)

if not is_valid:
raise Invalid3DTilesException(
"The provided 3DTiles is not valid, some of the mandatory keys are missing. Mandatory keys are: 'asset', 'geometricError', 'root'"
)
_file = Tiles3DFileHandler.is_3dtiles_json(_file)

Tiles3DFileHandler.validate_3dtile_payload(payload=_file)

except Exception as e:
raise Invalid3DTilesException(e)

return True

@staticmethod
def is_3dtiles_json(_file):
with open(_file, "r") as _readed_file:
_file = json.loads(_readed_file.read())
# required key described in the specification of 3dtiles
# https://docs.ogc.org/cs/22-025r4/22-025r4.html#toc92
is_valid = all(key in _file.keys() for key in ("asset", "geometricError", "root"))

if not is_valid:
raise Invalid3DTilesException(
"The provided 3DTiles is not valid, some of the mandatory keys are missing. Mandatory keys are: 'asset', 'geometricError', 'root'"
)

return _file

@staticmethod
def validate_3dtile_payload(payload):
Expand Down Expand Up @@ -212,7 +215,7 @@ def create_geonode_resource(
asset=None,
):
# we want just the tileset.json as location of the asset
asset.location = [path for path in asset.location if "tileset.json" in path]
asset.location = [path for path in asset.location if path.endswith(".json")]
asset.save()

resource = super().create_geonode_resource(
Expand Down

0 comments on commit f9e7a74

Please sign in to comment.