diff --git a/sample-management-custom/caosdb-server/scripting/bin/register_new_containers.py b/sample-management-custom/caosdb-server/scripting/bin/register_new_containers.py index d3e87dc36caf1666c72192cd3b2baf2ab8f71ab9..d855196273354da6a790f0efa2bc1696da4804c7 100755 --- a/sample-management-custom/caosdb-server/scripting/bin/register_new_containers.py +++ b/sample-management-custom/caosdb-server/scripting/bin/register_new_containers.py @@ -36,11 +36,11 @@ from bis_utils import (create_email_with_link_text, get_description_row, get_email_from_username, get_options_row, send_mail_with_defaults) from sample_helpers.container_name import get_container_name_prefix +from sample_helpers.utils import CONSTANTS, get_entity_name -ERROR_PREFIX = 'Something went wrong: ' -ERROR_SUFFIX = ' Please conatct <a href="mailto:biosamples@geomar.de">biosamples@geomar.de</a> if you encounter this issue.' -BIS_URL = 'https://biosamples.geomar.de/Entity/' +ERROR_PREFIX = CONSTANTS["error_prefix"] +ERROR_SUFFIX = CONSTANTS["error_suffix"] logger = logging.getLogger("caosadvancedtools") @@ -58,16 +58,6 @@ def get_current_year(): return year -def get_abbreviation(id): - try: - rd = db.execute_query("FIND {}".format(id))[0] - return rd.get_property("Abbreviation").value - except: - entity_url = BIS_URL + str(id) - logger.error('{}There was a problem while querying for the abbreviation of <a href="{}">this BIS Entity</a>.{}'.format( - ERROR_PREFIX, entity_url, ERROR_SUFFIX)) - - def create_new_label_counter(container_type_id, value=1): counter = db.Record() counter.add_parent(name="LabelCounter") @@ -109,25 +99,19 @@ def create_container_entities(responsible_id, container_type_id, container_size, batch = db.Container() # Get BIS Label for responsible person responsible_entity = db.execute_query("FIND {}".format(responsible_id))[0] - container_type_abbreviation = get_abbreviation(container_type_id) bis_label_prefix = get_container_name_prefix(responsible_id, container_type_id) bis_label_counter = get_label_counter(container_type_id) for i in range(number_of_containers): bis_label = f"{bis_label_prefix}_{bis_label_counter+i}" container = db.Record(bis_label) - container.add_parent(name="Container") - container.add_property(name="Responsible", value=responsible_id) - container.add_property(name="ContainerType", value=container_type_id) - container.add_property(name="Container size", value=container_size) - container.add_property(name="BIS label", value=bis_label) - container.add_property(name="Child container", value=[]) + container.add_parent(name=get_entity_name("Container")) + container.add_property(name=get_entity_name("Responsible"), value=responsible_id) + container.add_property(name=get_entity_name("ContainerType"), value=container_type_id) + container.add_property(name=get_entity_name("Container size"), value=container_size) + container.add_property(name=get_entity_name("Child container"), value=[]) batch += [container] try: batch.insert() - for ent in batch: - ent.retrieve_acl() - ent.grant(role='Stock Manager', priority=False, permission="EDIT:ACL") - ent.update_acl() except: logger.error("{}The registered containers could not be imported to the system.{}".format( ERROR_PREFIX, ERROR_SUFFIX)) diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/container_name.py b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/container_name.py index cc64a4280a1410d22043ba74795c82814528810b..0d458345b259f5efa2921c4491199d78c9e8ca84 100644 --- a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/container_name.py +++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/container_name.py @@ -24,6 +24,7 @@ import linkahead as db from .utils import get_entity_name + def get_record_string(rec: db.Record) -> str: if rec.get_property(get_entity_name("abbreviation_prop")) is not None and rec.get_property(get_entity_name("abbreviation_prop")).value: @@ -34,6 +35,7 @@ def get_record_string(rec: db.Record) -> str: return "" + def get_container_name_prefix(responsible_id: int, container_type_id: int) -> str: """Generate a container name prefix from the container type and the responsible entity. @@ -55,7 +57,7 @@ def get_container_name_prefix(responsible_id: int, container_type_id: int) -> st """ resp = db.cached_get_entity_by(eid=responsible_id) ct = db.cached_get_entity_by(eid=container_type_id) - + resp_str = get_record_string(resp) ct_str = get_record_string(ct) diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/default_constants.yml b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/default_constants.yml index 7c6d8addb5883087b376fec8227b301a7e74526b..79d084db60b116c3dc7c786ef51d7a9be7717cb1 100644 --- a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/default_constants.yml +++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/default_constants.yml @@ -22,3 +22,6 @@ entity_names: labelcounter_prop: Counter container_label_prop: container_label abbreviation_prop: Abbreviation + +error_prefix: "Something went wrong:" +error_suffix: "Please contact your administrator(s)."