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

ENH: completed file retrieval implementation

parent 7d773b3e
No related branches found
No related tags found
1 merge request!53Release 0.1
......@@ -129,7 +129,10 @@ class IdentifiableAdapter(metaclass=ABCMeta):
pass
@abstractmethod
def get_file(self, record: db.File):
def get_file(self, identifiable: db.File):
"""
Retrieve the file object for a (File) identifiable.
"""
pass
......@@ -141,7 +144,9 @@ class IdentifiableAdapter(metaclass=ABCMeta):
with a specific path. In the future, this could be extended
to allow for names, parents and custom properties.
"""
pass
identifiable = db.File()
identifiable.path = record.path
return identifiable
......@@ -151,12 +156,8 @@ class IdentifiableAdapter(metaclass=ABCMeta):
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)
return self.get_identifiable_for_file(record)
registered_identifiable = self.get_registered_identifiable(record)
......@@ -231,6 +232,9 @@ class IdentifiableAdapter(metaclass=ABCMeta):
if identifiable is None:
return None
if identifiable.role == "File":
return self.get_file(identifiable)
return self.retrieve_identified_record_for_identifiable(identifiable)
......@@ -358,22 +362,21 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
class CaosDBIdentifiableAdapter(IdentifiableAdapter):
"""
Identifiable adapter which can be used for production.
TODO: store registred identifiables not locally
"""
# TODO: don't store registered identifiables locally
def __init__(self):
self._registered_identifiables = dict()
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:
def get_file(self, identifiable: db.File):
if identifiable.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))
identifiable.path))
if len(candidates) > 1:
raise RuntimeError("Identifiable was not defined unambigiously.")
if len(candidates) == 0:
......@@ -399,13 +402,9 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter):
"""
if record.id is None:
return record
# breakpoint()
# raise NotImplementedError()
return record.id
def retrieve_identified_record(self, identifiable: db.Record):
# if identifiable.parents[0].name == "Measurement":
# breakpoint()
query_string = self.create_query_for_identifiable(identifiable)
candidates = db.execute_query(query_string)
if len(candidates) > 1:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment