From 1d3df5795cc432e606aff3839e0929a0dee8aa5a Mon Sep 17 00:00:00 2001
From: Florian Spreckelsen <f.spreckelsen@indiscale.com>
Date: Fri, 21 Mar 2025 15:21:27 +0100
Subject: [PATCH] FEAT: Raise error when identifying event properties are
 missing

---
 .../sample_upload_column_definitions.py           |  2 +-
 .../bin/sample_helpers/sample_upload_get_event.py | 15 +++++++++++++++
 .../scripting/bin/upload_sample_template.py       |  7 +++----
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_column_definitions.py b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_column_definitions.py
index 3bd2b85..251f5f1 100644
--- a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_column_definitions.py
+++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_column_definitions.py
@@ -91,7 +91,7 @@ COLUMN_CONVERTER = use_custom_names({
     "Collector": semicolon_separated_list,
     "Curator": semicolon_separated_list,
     "Embargo": _embargo_converter,
-    "Event responsible": semicolon_separated_list,
+    "responsible_person_event": semicolon_separated_list,
     "Sphere": semicolon_separated_list,
 })
 
diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_event.py b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_event.py
index 1949541..3bc4947 100644
--- a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_event.py
+++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_event.py
@@ -15,6 +15,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program. If not, see <https://www.gnu.org/licenses/>.
 #
+
 import linkahead as db
 import pandas as pd
 
@@ -85,6 +86,20 @@ def add_event_to_sample(sample: db.Record, data: pd.Series) -> db.Record:
 
     # only add if there was any event data at all:
     if len(event.properties) > 0:
+        # Start date and position are identifying event properties
+        if event.get_property(get_entity_name("start_date_prop")) is None:
+            raise DataInconsistencyError(
+                f"Sample with {get_column_header_name('entity_id')} {sample.id} has an "
+                f"{get_entity_name('event_rt')} but is missing a {
+                    get_column_header_name('start_date_prop')} "
+                "which is required."
+            )
+        if event.get_property(get_entity_name(position_prop.name)) is None:
+            raise DataInconsistencyError(
+                f"Sample with {get_column_header_name('entity_id')} {sample.id} has an "
+                f"{get_entity_name('event_rt')} but is missing start position information "
+                "which is required."
+            )
 
         sample = update_property(sample, event_rt.id, event, property_name=event_rt.name)
 
diff --git a/sample-management-custom/caosdb-server/scripting/bin/upload_sample_template.py b/sample-management-custom/caosdb-server/scripting/bin/upload_sample_template.py
index db9aa64..1e25408 100755
--- a/sample-management-custom/caosdb-server/scripting/bin/upload_sample_template.py
+++ b/sample-management-custom/caosdb-server/scripting/bin/upload_sample_template.py
@@ -40,8 +40,7 @@ from caosadvancedtools.serverside import helper
 from caosadvancedtools.table_importer import CSVImporter
 from caoscrawler.logging import configure_server_side_logging
 
-from bis_utils import (replace_entity_urls_by_ids,
-                       whitespace_cleanup_in_df)
+from bis_utils import (replace_entity_urls_by_ids)
 from sample_helpers.sample_upload_column_definitions import (
     COLUMN_CONVERTER, DATATYPE_DEFINITIONS,
     OBLIGATORY_COLUMNS, OBLIGATORY_COLUMNS_CHILD, SPECIAL_TREATMENT_SAMPLE)
@@ -96,8 +95,8 @@ def read_data_from_file(filename):
         )
         raise DataInconsistencyError("There was a problem with the CSV upload.")
 
-    # strip leading and trailing whitespaces
-    return whitespace_cleanup_in_df(df)
+    # TODO: strip leading and trailing whitespaces
+    return df
 
 
 def _get_converter_from_property_datatype(dt):
-- 
GitLab