From 77930b323719781319309fab271774692aba1ac5 Mon Sep 17 00:00:00 2001
From: Florian Spreckelsen <f.spreckelsen@indiscale.com>
Date: Fri, 7 Feb 2025 17:28:34 +0100
Subject: [PATCH] FIX: Typos

---
 .../caosdb-server/scripting/bin/bis_utils.py   | 18 +-----------------
 .../sample_upload_add_special_properties.py    |  3 +--
 .../sample_helpers/sample_upload_get_event.py  |  3 +--
 .../sample_helpers/sample_upload_get_person.py |  8 ++++----
 .../scripting/bin/sample_helpers/utils.py      | 17 +++++++++++++++++
 .../scripting/bin/upload_sample_template.py    |  3 +++
 6 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/sample-management-custom/caosdb-server/scripting/bin/bis_utils.py b/sample-management-custom/caosdb-server/scripting/bin/bis_utils.py
index 1bcc322..00699e5 100644
--- a/sample-management-custom/caosdb-server/scripting/bin/bis_utils.py
+++ b/sample-management-custom/caosdb-server/scripting/bin/bis_utils.py
@@ -34,7 +34,7 @@ from linkahead import get_entity_by_name
 
 from sample_helpers.sample_upload_column_definitions import (
     IGNORED_COLUMN_NAMES_SAMPLE, SPECIAL_TREATMENT_SAMPLE)
-from sample_helpers.utils import CONSTANTS
+from sample_helpers.utils import CONSTANTS, return_value_if_not_none
 
 
 COLUMN_DESCRIPTIONS = CONSTANTS["csv_column_descriptions"]
@@ -131,22 +131,6 @@ def replace_entity_urls_by_ids(data: pd.DataFrame, eid_columns: list[str] = ["BI
     return data
 
 
-def return_value_if_not_none(val):
-    """Workaround for somewhat weird pandas behavior. Return value if actual
-    value, otherwise, return None.
-
-    """
-    if isinstance(val, list):
-        if len(val) == 0:
-            return None
-        if len(val) == 1:
-            if pd.isnull(val[0]) or val[0] is None or f"{val[0]}".lower() == "nan" or f"{val[0]}" == "":
-                return None
-    elif pd.isnull(val) or val is None or f"{val}".lower() == "nan" or f"{val}" == "":
-        return None
-    return val
-
-
 def whitespace_cleanup_in_df(df: pd.DataFrame):
     """Strip all leading and trailing whitespaces from all str values in df."""
 
diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_add_special_properties.py b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_add_special_properties.py
index d32c3de..cb7ce01 100644
--- a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_add_special_properties.py
+++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_add_special_properties.py
@@ -22,8 +22,7 @@ from caosadvancedtools.datainconsistency import DataInconsistencyError
 
 from .sample_upload_get_container import get_container
 from .sample_upload_get_person import get_person
-from .utils import get_column_header_name, get_entity_name, update_property
-from ..bis_utils import return_value_if_not_none
+from .utils import get_column_header_name, get_entity_name, update_property, return_value_if_not_none
 
 
 def add_special_properties(sample: db.Record, data: pd.Series) -> db.Record:
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 cf02752..39ca204 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
@@ -21,8 +21,7 @@ import pandas as pd
 from caosadvancedtools.datainconsistency import DataInconsistencyError
 
 from .sample_upload_get_person import get_person
-from .utils import get_column_header_name, get_entity_name, update_property
-from ..bis_utils import return_value_if_not_none
+from .utils import get_column_header_name, get_entity_name, update_property, return_value_if_not_none
 
 
 def add_event_to_sample(sample: db.Record, data: pd.Series) -> db.Record:
diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_person.py b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_person.py
index 49c34f6..1872f62 100644
--- a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_person.py
+++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_person.py
@@ -44,16 +44,16 @@ def get_person(text: str) -> db.Record:
 def _get_person_by_fullname(first_name: str, last_name: str) -> db.Record:
     # seach for person in db
     res = db.execute_query(
-        f"FIND '{get_entity_name('Person')}' WITH '{
-            get_entity_name('first_name_prop')}'='{first_name}' "
+        f"FIND '{get_entity_name('Person')}' WITH "
+        f"'{get_entity_name('first_name_prop')}'='{first_name}' "
         f"AND '{get_entity_name('last_name_prop')}'='{last_name}'"
     )
     # if person doesn't exist in database...
     if len(res) == 0:
         # There is not enought data in the template to create a new Person record. Hence, we have to raise an Exception
         error_msg = (
-            f"There is no person Record with '{get_entity_name('first_name_prop')}' = '{
-                first_name}' "
+            f"There is no person Record with '{get_entity_name('first_name_prop')}' "
+            f"= '{first_name}' "
             f"AND '{get_entity_name('last_name_prop')}' = '{last_name}' in the database. ")
         raise DataInconsistencyError(error_msg)
     else:
diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/utils.py b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/utils.py
index 11d4683..c482eee 100644
--- a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/utils.py
+++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/utils.py
@@ -4,6 +4,7 @@ import yaml
 from pathlib import Path
 
 import linkahead as db
+import pandas as pd
 
 with open(os.path.join(Path(__file__).parent, "default_constants.yml")) as yaml_file:
     CONSTANTS = yaml.safe_load(yaml_file)
@@ -64,3 +65,19 @@ def update_property(entity: db.Record, property_id: int, value, property_name=""
         logger.debug("{}: Setting {} = {}".format(entity.id, property_id, value.id if
                                                   isinstance(value, db.Entity) else value))
     return entity
+
+
+def return_value_if_not_none(val):
+    """Workaround for somewhat weird pandas behavior. Return value if actual
+    value, otherwise, return None.
+
+    """
+    if isinstance(val, list):
+        if len(val) == 0:
+            return None
+        if len(val) == 1:
+            if pd.isnull(val[0]) or val[0] is None or f"{val[0]}".lower() == "nan" or f"{val[0]}" == "":
+                return None
+    elif pd.isnull(val) or val is None or f"{val}".lower() == "nan" or f"{val}" == "":
+        return None
+    return val
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 484e651..4551b35 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
@@ -42,6 +42,9 @@ from caoscrawler.logging import configure_server_side_logging
 
 from bis_utils import (replace_entity_urls_by_ids,
                        SPECIAL_TREATMENT_SAMPLE, whitespace_cleanup_in_df)
+from sample_helpers.sample_upload_column_definitions import (
+    COLUMN_CONVERTER, DATATYPE_DEFINITIONS,
+    OBLIGATORY_COLUMNS, OBLIGATORY_COLUMNS_CHILD, SPECIAL_TREATMENT_SAMPLE)
 from sample_helpers.utils import CONSTANTS, get_column_header_name
 
 # suppress warning of diff function
-- 
GitLab