Skip to content
Snippets Groups Projects
Commit 2c57c5e6 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

wip

parent b60ece3a
No related branches found
No related tags found
2 merge requests!91Release 0.3,!67MAINT: introduce an identifiable class
...@@ -161,56 +161,46 @@ class IdentifiableAdapter(metaclass=ABCMeta): ...@@ -161,56 +161,46 @@ class IdentifiableAdapter(metaclass=ABCMeta):
identifiable identifiable
""" """
path = None
if record.role == "File":
path = record.path
registered_identifiable = self.get_registered_identifiable(record) registered_identifiable = self.get_registered_identifiable(record)
if registered_identifiable is None:
if path is not None:
return Identifiable(path=path)
return None
if len(registered_identifiable.parents) != 1:
raise RuntimeError("Multiple parents for identifiables"
"not supported.")
property_name_list_A = [] property_name_list_A = []
property_name_list_B = [] property_name_list_B = []
identifiable_props = {} identifiable_props = {}
# fill the values: if registered_identifiable is not None:
for prop in registered_identifiable.properties: # fill the values:
if prop.name == "name": for prop in registered_identifiable.properties:
# The name can be an identifiable, but it isn't a property if prop.name == "name":
continue # The name can be an identifiable, but it isn't a property
# problem: what happens with multi properties? continue
# case A: in the registered identifiable # problem: what happens with multi properties?
# case B: in the identifiable # case A: in the registered identifiable
# case B: in the identifiable
record_prop = record.get_property(prop.name)
if record_prop is None: record_prop = record.get_property(prop.name)
# TODO: how to handle missing values in identifiables if record_prop is None:
# raise an exception? # TODO: how to handle missing values in identifiables
raise NotImplementedError( # raise an exception?
f"The following record is missing an identifying property:" raise NotImplementedError(
f"RECORD\n{record}\nIdentifying PROPERTY\n{prop.name}" f"The following record is missing an identifying property:"
) f"RECORD\n{record}\nIdentifying PROPERTY\n{prop.name}"
identifiable_props[record_prop.name] = record_prop.value )
property_name_list_A.append(prop.name) identifiable_props[record_prop.name] = record_prop.value
property_name_list_A.append(prop.name)
# check for multi properties in the record:
for prop in property_name_list_A: # check for multi properties in the record:
property_name_list_B.append(prop) for prop in property_name_list_A:
if (len(set(property_name_list_B)) != len(property_name_list_B) or len( property_name_list_B.append(prop)
set(property_name_list_A)) != len(property_name_list_A)): if (len(set(property_name_list_B)) != len(property_name_list_B) or len(
raise RuntimeError( set(property_name_list_A)) != len(property_name_list_A)):
"Multi properties used in identifiables could cause unpredictable results and are" raise RuntimeError(
" not allowed. You might want to consider a Property with a list as value.") "Multi properties used in identifiables could cause unpredictable results and are"
" not allowed. You might want to consider a Property with a list as value.")
return Identifiable(record_type=registered_identifiable.parents[0].name, return Identifiable(record_type=registered_identifiable.parents[0].name,
name=record.name, name=record.name,
properties=identifiable_props, properties=identifiable_props,
path=path path=record.path
) )
@abstractmethod @abstractmethod
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment