From 9f91ac71dd8b505bb7f35dc49c8fceea5ccba30b Mon Sep 17 00:00:00 2001
From: Florian Spreckelsen <f.spreckelsen@indiscale.com>
Date: Fri, 21 Mar 2025 11:16:55 +0100
Subject: [PATCH] FEAT(sample_upload): Add special treatment for sample names

---
 .../caosdb-server/scripting/bin/crawl_sample_data_async.py  | 6 ++++++
 .../bin/sample_helpers/sample_upload_column_definitions.py  | 1 +
 .../caosdb-server/scripting/bin/upload_sample_template.py   | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/sample-management-custom/caosdb-server/scripting/bin/crawl_sample_data_async.py b/sample-management-custom/caosdb-server/scripting/bin/crawl_sample_data_async.py
index ace23ee..a786927 100755
--- a/sample-management-custom/caosdb-server/scripting/bin/crawl_sample_data_async.py
+++ b/sample-management-custom/caosdb-server/scripting/bin/crawl_sample_data_async.py
@@ -145,6 +145,12 @@ def update_sample_records(data, htmluserlog_public):
             raise DataInconsistencyError(msg)
 
         # All special properties are added here
+        if get_column_header_name("sample_name") in data:
+            # We want to allow to overwrite the name with empty
+            # values. Note that this is cureently broken in the
+            # crawler and needs to be fixed there.
+            sample.name = return_value_if_not_none(row[get_column_header_name("sample_name")])
+
         sample = add_special_properties(sample, row)
 
         # Add additional properties
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 1ad1ade..3bd2b85 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
@@ -69,6 +69,7 @@ DATATYPE_DEFINITIONS = use_custom_names({
     "Longitude stop": float,
     "PI": str,
     "Parent LinkAhead ID": str,
+    "sample_name": str,
     "SampleMethod": str,
     "SampleType": str,
     "Start date": str,
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 7160007..db9aa64 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
@@ -41,7 +41,7 @@ from caosadvancedtools.table_importer import CSVImporter
 from caoscrawler.logging import configure_server_side_logging
 
 from bis_utils import (replace_entity_urls_by_ids,
-                       SPECIAL_TREATMENT_SAMPLE, whitespace_cleanup_in_df)
+                       whitespace_cleanup_in_df)
 from sample_helpers.sample_upload_column_definitions import (
     COLUMN_CONVERTER, DATATYPE_DEFINITIONS,
     OBLIGATORY_COLUMNS, OBLIGATORY_COLUMNS_CHILD, SPECIAL_TREATMENT_SAMPLE)
-- 
GitLab