diff --git a/sample-management-custom/caosdb-server/scripting/bin/register_new_samples.py b/sample-management-custom/caosdb-server/scripting/bin/register_new_samples.py index 15e22bd9c17a67098519e38f6fc8f9c976f09718..a320c0d9aabb7af53d780a0e35c9065773ff7085 100755 --- a/sample-management-custom/caosdb-server/scripting/bin/register_new_samples.py +++ b/sample-management-custom/caosdb-server/scripting/bin/register_new_samples.py @@ -13,6 +13,7 @@ from bis_utils import (create_email_with_link_text, get_options_row, send_mail_with_defaults) from sample_helpers.sample_registration_get_person_identifier import get_person_identifier from sample_helpers.sample_registration_post_processing import post_process_samples +from sample_helpers.sample_registration_check_column_names import check_column_names from sample_helpers.utils import CONSTANTS, get_column_header_name, get_entity_name ERROR_PREFIX = CONSTANTS["error_prefix"] @@ -34,8 +35,9 @@ def get_column_names(data): other_names = data["required_column_names"].split(',') + data["column_names"] starting_names.extend([name.strip() for name in other_names if name.strip() not in starting_names]) - return [get_column_header_name(name) for name in starting_names] - + cnames = [get_column_header_name(name) for name in starting_names] + check_column_names(cnames) + return cnames def create_sample_entities(data): responsible_person_id = int(data["responsible_person"]) diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_registration_check_column_names.py b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_registration_check_column_names.py new file mode 100644 index 0000000000000000000000000000000000000000..79f62ddf697619f8300b5d680e5092926974f74e --- /dev/null +++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_registration_check_column_names.py @@ -0,0 +1,68 @@ +# +# Copyright (C) 2025 Indiscale GmbH <info@indiscale.com> +# Copyright (C) 2025 Henrik tom Wörden <h.tomwoerden@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 logging + +from caosadvancedtools.datainconsistency import DataInconsistencyError + +from .utils import CONSTANTS, get_column_header_name, get_entity_name +from .sample_upload_column_definitions import use_custom_names + +logger = logging.getLogger("caosadvancedtools") + +def check_column_names(names: list[str]) -> None: + event_and_position_properties = use_custom_names([ + "Campaign", + "Biome", + "Device", + "Elevation start", + "Elevation stop", + "End date", + "responsible_person_event", + "igsn_doi_prop", + "Latitude start", + "Latitude stop", + "Level", + "locality_description_prop", + "locality_name_prop", + "Longitude start", + "Longitude stop", + "Sphere", + "Start date", + ]) + needs_events = False + for name in names: + if name in event_and_position_properties: + needs_events = True + appended = [] + if needs_events: + for name in use_custom_names([ + "Longitude start", + "Latitude start", + "Elevation start", + "Start date", + ]): + if name not in names: + names.append(name) + appended.append(name) + + if appended: + logger.warning( + "The following columns were added in order to allow consitent data insertion:\n" + f"{', '.join(appended)}" + )