@@ -82,8 +82,7 @@ def can_handle(_data) -> bool:
8282 if not base :
8383 return False
8484 ext = base .split ("." )[- 1 ] if isinstance (base , str ) else base .name .split ("." )[- 1 ]
85- input_filename = os .path .basename (base if isinstance (base , str ) else base .name )
86- if ext in ["json" ] and "tileset.json" in input_filename :
85+ if ext in ["json" ] and Tiles3DFileHandler .is_3dtiles_json (base ):
8786 return True
8887 return False
8988
@@ -110,16 +109,7 @@ def is_valid(files, user, **kwargs):
110109 raise Invalid3DTilesException ("Please remove the additional dots in the filename" )
111110
112111 try :
113- with open (_file , "r" ) as _readed_file :
114- _file = json .loads (_readed_file .read ())
115- # required key described in the specification of 3dtiles
116- # https://docs.ogc.org/cs/22-025r4/22-025r4.html#toc92
117- is_valid = all (key in _file .keys () for key in ("asset" , "geometricError" , "root" ))
118-
119- if not is_valid :
120- raise Invalid3DTilesException (
121- "The provided 3DTiles is not valid, some of the mandatory keys are missing. Mandatory keys are: 'asset', 'geometricError', 'root'"
122- )
112+ _file = Tiles3DFileHandler .is_3dtiles_json (_file )
123113
124114 Tiles3DFileHandler .validate_3dtile_payload (payload = _file )
125115
@@ -128,6 +118,21 @@ def is_valid(files, user, **kwargs):
128118
129119 return True
130120
121+ @staticmethod
122+ def is_3dtiles_json (_file ):
123+ with open (_file , "r" ) as _readed_file :
124+ _file = json .loads (_readed_file .read ())
125+ # required key described in the specification of 3dtiles
126+ # https://docs.ogc.org/cs/22-025r4/22-025r4.html#toc92
127+ is_valid = all (key in _file .keys () for key in ("asset" , "geometricError" , "root" ))
128+
129+ if not is_valid :
130+ raise Invalid3DTilesException (
131+ "The provided 3DTiles is not valid, some of the mandatory keys are missing. Mandatory keys are: 'asset', 'geometricError', 'root'"
132+ )
133+
134+ return _file
135+
131136 @staticmethod
132137 def validate_3dtile_payload (payload ):
133138 # if the keys are there, let's check if the mandatory child are there too
@@ -216,7 +221,7 @@ def create_geonode_resource(
216221 asset = None ,
217222 ):
218223 # we want just the tileset.json as location of the asset
219- asset .location = [path for path in asset .location if "tileset .json" in path ]
224+ asset .location = [path for path in asset .location if path . endswith ( " .json") ]
220225 asset .save ()
221226
222227 resource = super ().create_geonode_resource (layer_name , alternate , execution_id , ResourceBase , asset )
0 commit comments