diff --git a/importer/handlers/tiles3d/handler.py b/importer/handlers/tiles3d/handler.py index b727363..b0ff203 100755 --- a/importer/handlers/tiles3d/handler.py +++ b/importer/handlers/tiles3d/handler.py @@ -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 @@ -90,18 +89,7 @@ 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) @@ -109,6 +97,21 @@ def is_valid(files, user): 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): @@ -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(