Skip to content
Snippets Groups Projects
Commit 1a9e1857 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

ENH: Add separate module for container identification

parent 0fbb980a
No related branches found
No related tags found
1 merge request!1F awi sams
......@@ -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
......@@ -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",
......
#
# 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}."
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment