Skip to content

Commit

Permalink
[WIP](mtd): several modifications for mtd module
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentCauchois committed Oct 29, 2024
1 parent 08617c1 commit 970e13b
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 33 deletions.
17 changes: 15 additions & 2 deletions backend/geonature/core/gn_meta/mtd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
class MTDInstanceApi:
af_path = "/mtd/cadre/export/xml/GetRecordsByInstanceId?id={ID_INSTANCE}"
ds_path = "/mtd/cadre/jdd/export/xml/GetRecordsByInstanceId?id={ID_INSTANCE}"
# TODO: check if there are endpoints to retrieve metadata for a given user and instance, and not only a given user and whatever instance
ds_user_path = "/mtd/cadre/jdd/export/xml/GetRecordsByUserId?id={ID_ROLE}"
af_user_path = "/mtd/cadre/export/xml/GetRecordsByUserId?id={ID_ROLE}"
single_af_path = "/mtd/cadre/export/xml/GetRecordById?id={ID_AF}" # NOTE: `ID_AF` is actually an UUID and not an ID from the point of view of geonature database.
Expand All @@ -60,6 +61,9 @@ def _get_xml(self, path):
def _get_af_xml(self):
return self._get_xml(self.af_path)

# TODO: make the functions `get_af_list` and `get_ds_list` homogeneous
# - Use functions `parse_acquisition_framworks_xml`, and `parse_datasets_xml`, OR `parse_acquisition_framework`, and `parse_dataset`

def get_af_list(self) -> list:
xml = self._get_af_xml()
_xml_parser = etree.XMLParser(ns_clean=True, recover=True, encoding="utf-8")
Expand Down Expand Up @@ -206,6 +210,9 @@ def process_af_and_ds(af_list, ds_list, id_role=None):
add_unexisting_digitizer(af["id_digitizer"] if not id_role else id_role)
user_add_total_time += time.time() - start_add_user_time
af = sync_af(af)
# TODO: choose whether or not to commit retrieval of the AF before association of actors
# and possibly retrieve an AF without any actor associated to it
db.session.commit()
# If the AF has not been retrieved, associated actors cannot be retrieved either
# and thus we continue to the next AF
if not af:
Expand All @@ -215,6 +222,7 @@ def process_af_and_ds(af_list, ds_list, id_role=None):
CorAcquisitionFrameworkActor,
"id_acquisition_framework",
af.id_acquisition_framework,
af.unique_acquisition_framework_id,
)
# TODO: remove actors removed from MTD
db.session.commit()
Expand All @@ -231,7 +239,13 @@ def process_af_and_ds(af_list, ds_list, id_role=None):
user_add_total_time += time.time() - start_add_user_time
ds = sync_ds(ds, list_cd_nomenclature)
if ds is not None:
associate_actors(actors, CorDatasetActor, "id_dataset", ds.id_dataset)
associate_actors(
actors,
CorDatasetActor,
"id_dataset",
ds.id_dataset,
ds.unique_dataset_id,
)

user_add_total_time = round(user_add_total_time, 2)
db.session.commit()
Expand Down Expand Up @@ -264,7 +278,6 @@ def sync_af_and_ds_by_user(id_role, id_af=None):
id_af : str, optional
The ID of an AF (Acquisition Framework).
"""

logger.info("MTD - SYNC USER : START")

# Create an instance of MTDInstanceApi
Expand Down
Loading

0 comments on commit 970e13b

Please sign in to comment.