diff --git a/src/caoscrawler/identifiable_adapters.py b/src/caoscrawler/identifiable_adapters.py index 4b2d2ffc5ff850174043d20c707e3fed4031a904..9be469738d612e83a8706f8e38da0274d6166888 100644 --- a/src/caoscrawler/identifiable_adapters.py +++ b/src/caoscrawler/identifiable_adapters.py @@ -161,56 +161,46 @@ class IdentifiableAdapter(metaclass=ABCMeta): identifiable """ - path = None - if record.role == "File": - path = record.path - 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_B = [] identifiable_props = {} - # fill the values: - for prop in registered_identifiable.properties: - if prop.name == "name": - # The name can be an identifiable, but it isn't a property - continue - # problem: what happens with multi properties? - # case A: in the registered identifiable - # case B: in the identifiable - - record_prop = record.get_property(prop.name) - if record_prop is None: - # TODO: how to handle missing values in identifiables - # raise an exception? - raise NotImplementedError( - 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) - - # check for multi properties in the record: - for prop in property_name_list_A: - property_name_list_B.append(prop) - if (len(set(property_name_list_B)) != len(property_name_list_B) or len( - set(property_name_list_A)) != len(property_name_list_A)): - raise RuntimeError( - "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.") + if registered_identifiable is not None: + # fill the values: + for prop in registered_identifiable.properties: + if prop.name == "name": + # The name can be an identifiable, but it isn't a property + continue + # problem: what happens with multi properties? + # case A: in the registered identifiable + # case B: in the identifiable + + record_prop = record.get_property(prop.name) + if record_prop is None: + # TODO: how to handle missing values in identifiables + # raise an exception? + raise NotImplementedError( + 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) + + # check for multi properties in the record: + for prop in property_name_list_A: + property_name_list_B.append(prop) + if (len(set(property_name_list_B)) != len(property_name_list_B) or len( + set(property_name_list_A)) != len(property_name_list_A)): + raise RuntimeError( + "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, name=record.name, properties=identifiable_props, - path=path + path=record.path ) @abstractmethod