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

ENH: Make more rt and property names configurable

parent 67b31746
No related branches found
No related tags found
1 merge request!1F awi sams
......@@ -211,64 +211,60 @@ def main():
logger.warning(f"There is no PI with ID or {get_entity_name('abbreviation_prop')} {pi}. Skipping.")
# Collection(s)
if _value_in_row("Collection", row):
collection_rt = cached_get_entity_by(query="FIND RECORDTYPE Collection")
if not ";" in str(row["Collection"]):
collections = [row["Collection"]]
if _value_in_row(get_column_header_name("Collection"), row):
collection_rt = cached_get_entity_by(query=f"FIND RECORDTYPE '{get_entity_name('Collection')}'")
if not ";" in str(row[get_column_header_name("Collection")]):
collections = [row[get_column_header_name("Collection")]]
else:
collections = [coll.strip() for coll in str(row["Collection"]).split(';')]
collections = [coll.strip() for coll in str(row[get_column_header_name("Collection")]).split(';')]
prop_val = []
for coll in collections:
try:
query = f"FIND RECORD Collection WITH ID={int(coll)}"
query = f"FIND '{collection_rt.name}' WITH ID={int(coll)}"
except ValueError:
query = f"FIND RECORD Collection WITH name='{coll}'"
query = f"FIND RECORD '{collection_rt.name}' WITH name='{coll}'"
try:
coll_rec = cached_get_entity_by(query=query)
prop_val.append(coll_rec.id)
except db.EmptyUniqueQueryError:
logger.warning(f"There is no collection with name or BIS ID {coll}. Skipping.")
logger.warning(f"There is no {collection_rt.name} with name or ID {coll}. Skipping.")
continue
if prop_val:
if child.get_property("Collection") is not None:
child.get_property("Collection").datatype = db.LIST("Collection")
child.get_property("Collection").value = prop_val
if child.get_property(collection_rt.name) is not None:
child.get_property(collection_rt.name).datatype = db.LIST(collection_rt.name)
child.get_property(collection_rt.name).value = prop_val
else:
child.add_property(id=collection_rt.id, name=collection_rt.name, datatype=db.LIST(
"Collection"), value=prop_val)
collection_rt.name), value=prop_val)
# Treat Container Contents
if _value_in_row("Container Contents", row):
if not (_value_in_row("PI", row) and _value_in_row("Collection", row)):
logger.error(
f"Container Contents are given for container {child.id} but it "
"is missing PI and/or Collection info. No updates have been performed."
)
return 1
contents_prop = cached_get_entity_by(query="FIND PROPERTY 'Container Contents'")
if _value_in_row(get_column_header_name("Container Contents"), row):
contents_prop = cached_get_entity_by(
query=f"FIND PROPERTY '{get_entity_name('Container Contents')}'"
)
if child.get_property(contents_prop.name) is not None:
child.get_property(contents_prop.name).value = row["Container Contents"]
child.get_property(contents_prop.name).value = row[get_column_header_name("Container Contents")]
else:
child.add_property(id=contents_prop.id, name=contents_prop.name,
value=row["Container Contents"])
value=row[get_column_header_name("Container Contents")])
# Treat PDF Report
if _value_in_row("PDFReport", row):
pdf_id = row["PDFReport"]
if _value_in_row(get_column_header_name("PDFReport"), row):
pdf_id = row[get_column_header_name("PDFReport")]
try:
pdf_id = int(pdf_id)
pdf_rec = cached_query(f"FIND FILE PDFReport WITH ID={pdf_id}")
pdf_rec = cached_query(f"FIND FILE {get_entity_name('PDFReport')} WITH ID={pdf_id}")
if not pdf_rec:
logger.warning(
f"There is no PDFReport with Bis ID {pdf_id}, so no PDF is attached to container {child.id}.")
f"There is no PDFReport with ID {pdf_id}, so no PDF is attached to container {child.id}.")
else:
if child.get_property("PDFReport") is not None:
child.get_property("PDFReport").value = pdf_id
if child.get_property(get_entity_name("PDFReport")) is not None:
child.get_property(get_property("PDFReport")).value = pdf_id
else:
child.add_property(id=pdf_rt.id, name=pdf_rt.name, value=pdf_id)
except ValueError:
logger.warning(
f"There is no valid Bis ID provided for container {child.id}."
f"There is no valid ID provided for container {child.id}."
f"Provided was {pdf_id}. Skipping")
# This is a workaround for weird merging errors in the
......@@ -276,13 +272,13 @@ def main():
# following release.
merged = []
for par in parent_containers:
if (data['BIS ID'] == par.id).any():
if (data[id_column_name] == par.id).any():
# A container to be updated is used as another containers parent:
child = child_containers.get_entity_by_id(par.id)
# All parents have a child sample property with a value (which may
# be empty). No child sample has this property, so the following is
# okay without checks:
prop = par.get_property("Child container")
prop = par.get_property(child_container_prop.name)
child.add_property(name=prop.name, id=prop.id, value=prop.value)
merged.append(par)
for par in merged:
......
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