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 063b15338500e87bead67e27e4c8849431495fcb..804e8e44afad2012b9af6d72bcf8bf12107df680 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 @@ -47,6 +47,7 @@ from bis_utils import (get_do_not_insert_type_names, return_value_if_not_none, send_mail_with_defaults, SPECIAL_TREATMENT_SAMPLE) +from sample_helpers.sample_upload_add_special_properties import add_special_properties from sample_helpers.sample_upload_get_event import add_event_to_sample from sample_helpers.sample_upload_get_person import get_person from sample_helpers.sample_upload_post_processing import post_process_samples @@ -369,29 +370,8 @@ def update_sample_records(data, htmluserlog_public): msg = "There is no Sample with ID = {} in the system.".format(row["BIS ID"]) raise DataInconsistencyError(msg) - sample = _update_property(entity=sample, property_id=person_property_id, - property_name="Main User", - value=get_person(row["Main User"])) - if "Parent BIS ID" in row and return_value_if_not_none(row["Parent BIS ID"]) is not None: - sample = _update_property(entity=sample, property_id=parent_sample_property_id, - value=row["Parent BIS ID"]) - if ("Sampling Person" in row - and return_value_if_not_none(row["Sampling Person"]) is not None): - sample = _update_property(entity=sample, property_id=sampling_person_property_id, - property_name="Sampling Person", - value=get_person(row["Sampling Person"])) - if "PI" in row and return_value_if_not_none(row["PI"]) is not None: - sample = _update_property(entity=sample, property_id=db.get_entity_by_name("PI").id, - property_name="PI", - value=get_person(row["PI"])) - if "Storage ID" in row and return_value_if_not_none(row["Storage ID"]) is not None: - sample = _update_property(entity=sample, property_id=container_property_id, - property_name="Container", - value=get_container(row)) - - if "PDFReport" in data.columns: - sample = _update_property( - entity=sample, property_id=pdfreport_property_id, property_name="PDFReport", value=row["PDFReport"]) + # All special properties are added here + sample = add_special_properties(sample, row) # Add additional properties for property_name in additional_property_ids.keys(): 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 new file mode 100644 index 0000000000000000000000000000000000000000..edda83430c5ebc1dc935bf9b520416d54f8aebbb --- /dev/null +++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_add_special_properties.py @@ -0,0 +1,35 @@ +# +# Copyright (C) 2025 Indiscale GmbH <info@indiscale.com> +# Copyright (C) 2025 Florian Spreckelsen <f.spreckelsen@indiscale.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# 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 + +from caosadvancedtools.datainconsistency import DataInconsistencyError + +from .utils import get_column_header_name, get_entity_name +from ..bis_utils import return_value_if_not_none + + +def add_special_properties(sample: db.Record, data: pd.Series) -> db.Record: + """This function adds all the properties that can not be added + trivially from the given data row to the sample. + + """ + + # TODO Add special treatment properties to sample + + return sample