Skip to content
Snippets Groups Projects
Commit e063a70e authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

ENH: refactored confusing names of identifiable adapter

parent 794cc096
Branches
Tags
1 merge request!53Release 0.1
......@@ -355,7 +355,7 @@ class Crawler(object):
# TODO: can the following be removed at some point
for ent in flat:
if len(ent.parents) == 0:
if ent.role == "Record" and len(ent.parents) == 0:
raise RuntimeError("Records must have a parent.")
resolved_references = True
......@@ -398,7 +398,7 @@ class Crawler(object):
# Check remotely
# TODO: remove deepcopy?
identified_record = self.identifiableAdapter.retrieve_identifiable(
identified_record = self.identifiableAdapter.retrieve_identifiable_for_record(
deepcopy(record))
if identified_record is None:
# identifiable does not exist remotely
......@@ -512,7 +512,7 @@ class Crawler(object):
for el in to_be_updated:
self.replace_entities_by_ids(el)
identified_records = [self.identifiableAdapter.retrieve_identifiable(record) for record
identified_records = [self.identifiableAdapter.retrieve_identifiable_for_record(record) for record
in to_be_updated]
self.remove_unnecessary_updates(to_be_updated, identified_records)
......
......@@ -128,11 +128,23 @@ class IdentifiableAdapter(metaclass=ABCMeta):
def resolve_reference(self, record: db.Record):
pass
@abstractmethod
def get_file(self, record: db.File):
pass
def get_identifiable(self, record: db.Record):
"""
retrieve the registred identifiable and fill the property values to create an
identifiable
"""
# TODO: this is incorrect
# The identifiable of a File is a file object with a path set.
# This needs to be taken into account also for retrieving the
# actually identified record.
if record.role == "File":
return self.get_file(record)
registered_identifiable = self.get_registered_identifiable(record)
if registered_identifiable is None:
......@@ -182,7 +194,7 @@ class IdentifiableAdapter(metaclass=ABCMeta):
return identifiable
@abstractmethod
def retrieve_identified_record(self, identifiable: db.Record):
def retrieve_identified_record_for_identifiable(self, identifiable: db.Record):
"""
Retrieve identifiable record for a given identifiable.
......@@ -191,9 +203,8 @@ class IdentifiableAdapter(metaclass=ABCMeta):
"""
pass
# TODO: the name is confusing. it returns the identified record
# TODO: remove side effect
def retrieve_identifiable(self, record: db.Record):
def retrieve_identifiable_for_record(self, record: db.Record):
"""
This function combines all functionality of the IdentifierAdapter by
returning the identifiable after having checked for an appropriate
......@@ -207,7 +218,7 @@ class IdentifiableAdapter(metaclass=ABCMeta):
if identifiable is None:
return None
return self.retrieve_identified_record(identifiable)
return self.retrieve_identified_record_for_identifiable(identifiable)
class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
......@@ -345,6 +356,17 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter):
def register_identifiable(self, name: str, definition: db.RecordType):
self._registered_identifiables[name] = definition
def get_file(self, record: db.File):
if record.path is None:
raise RuntimeError("Path must not be None for File retrieval.")
candidates = db.execute_query("FIND File which is stored at {}".format(
record.path))
if len(candidates) > 1:
raise RuntimeError("Identifiable was not defined unambigiously.")
if len(candidates) == 0:
return None
return candidates[0]
def get_registered_identifiable(self, record: db.Record):
"""
returns the registred identifiable for the given Record
......
......@@ -203,7 +203,7 @@ def test_crawler_update_list(crawler, ident):
assert len(id_r0.properties) == 2
idr_r0_test = ident.retrieve_identified_record(id_r0)
idr_r0 = ident.retrieve_identifiable(r_cur)
idr_r0 = ident.retrieve_identifiable_for_record(r_cur)
assert idr_r0 == idr_r0_test
# take the first measurement in the list of records:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment