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 edda83430c5ebc1dc935bf9b520416d54f8aebbb..22423058f41d0f27d646b78529b055531b223370 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 @@ -20,7 +20,9 @@ import pandas as pd from caosadvancedtools.datainconsistency import DataInconsistencyError -from .utils import get_column_header_name, get_entity_name +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 @@ -30,6 +32,18 @@ def add_special_properties(sample: db.Record, data: pd.Series) -> db.Record: """ - # TODO Add special treatment properties to sample + main_user_prop = db.get_entity_by_name(get_entity_name("Main User")) + container_rt = db.get_entity_name(get_entity_name("container_rt")) + + if (get_column_header_name("Main User") in data and + return_value_if_not_none(data[get_column_header_name("Main User")]) is not None): + main_user = get_person(return_value_if_not_none(data[get_column_header_name("Main User")])) + sample = update_property(sample, main_user_prop.id, main_user) + + if (get_column_header_name("Storage ID") in data and + return_value_if_not_none(data[get_column_header_name("Storage ID")]) is not None): + container = get_container(return_value_if_not_none( + data[get_column_header_name("Storage ID")])) + sample = update_property(sample, container_rt.id, contianer) return sample 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 c4c4c8205d3898ec7223ce15f5dabfd61af08237..8384ed934c1449d7b27ca5d6681de95e6d723d6f 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 @@ -95,8 +95,11 @@ COLUMN_CONVERTER = _use_custom_names({ SPECIAL_TREATMENT_SAMPLE = _use_custom_names([ "Biome", "Campaign", + "Collector", + "Curator", "Elevation start", "Elevation stop", + "Embargo", "End date", "Event responsible", "IGSN DOI", @@ -111,7 +114,6 @@ SPECIAL_TREATMENT_SAMPLE = _use_custom_names([ "PDFReport", "Parent Linkahead ID", "Sphere", - "Sphere", "Start date", "Storage ID", "entity_id", diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_container.py b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_container.py new file mode 100644 index 0000000000000000000000000000000000000000..40e2e735fa97fafced6410403c19b57decd19ebb --- /dev/null +++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_container.py @@ -0,0 +1,43 @@ +# +# 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 + +from caosadvancedtools.datainconsistency import DataInconsistencyError + +from .utils import get_entity_name + + +def get_container(identifier: str) -> db.Record: + """Return the container record for a given identifier string. By + default, that's simply the id but may be overwritten for + customization. + + """ + try: + return db.cached.cached_get_entity_by( + query=f"FIND '{get_entity_name('container_rt')}' WITH ID='{identifier}'" + ) + except db.EmptyUniqueQueryError: + try: + return db.cached.cached_get_entity_by( + query=f"FIND '{get_entity_name('container_rt')}' WITH name='{identifier}'" + ) + except db.EmptyUniqueQueryError: + raise DataInconsistencyError( + f"Couldn't find a {get_entity_name('container_rt')} with name or id {identifier}." + )