From d0b3ecad42f234430b6a6385994ca932b0697af2 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 14 Nov 2024 18:29:32 +0500 Subject: [PATCH] csv2ifc - add header validation --- src/ifc4d/ifc4d/csv2ifc.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ifc4d/ifc4d/csv2ifc.py b/src/ifc4d/ifc4d/csv2ifc.py index 3d69a0e72b..fca4e98a91 100644 --- a/src/ifc4d/ifc4d/csv2ifc.py +++ b/src/ifc4d/ifc4d/csv2ifc.py @@ -86,12 +86,23 @@ class Csv2Ifc: if not row[0]: continue if row[0] == "HIERARCHY": + missing_columns = set(self.SUPPORTED_COLUMNS) - set(row) + if missing_columns: + raise Exception( + f"Header is missing some of the required columns: {', '.join(missing_columns)}." + ) + for i, col in enumerate(row): if not col: continue self.headers[col] = i continue + if not self.headers: + raise Exception( + f"No header found in CSV file before data row: '{row}'. Note that header should start with 'HIERARCHY' column." + ) + resource_data = self.get_row_resource_data(row) hierarchy_key = int(row[0]) if hierarchy_key == 1: