Skip to content

Commit

Permalink
[WIP]fix(mtd): filter af list to be processed with id_instance
Browse files Browse the repository at this point in the history
In the retrieval of the list of acquisition frameworks to be processed, keep only those for which an ID_INSTANCE value is set and equals the ID_INSTANCE_FILTER config variable.
This ensures that an acquisition framework associated with no instance, or with an instance other than the present one, is not retrieved.

Note: it seems that this modification offers significant reductions in overall execution time, at least for user sync and, in particular, for a user with a lot of AF not associated to the configured instance.
  • Loading branch information
VincentCauchois committed Feb 5, 2025
1 parent 55db491 commit 3176d97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 0 additions & 2 deletions backend/geonature/core/gn_meta/mtd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@ def sync_af_and_ds_by_user(id_role, id_af=None):

# Get the list of acquisition frameworks for the user
# call INPN API for each AF to retrieve info
# TODO: check if there is any AF that is retrieved while not being associated to the current instance
# this may theoretically happen as AF from the XML file are not yet filtered with the instance ID
af_list = mtd_api.get_list_af_for_user()
else:
# TODO: Check the following TODO
Expand Down
22 changes: 16 additions & 6 deletions backend/geonature/core/gn_meta/mtd/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ def parse_acquisition_frameworks_xml(xml: str) -> list:
af_iter = root.iterfind(".//{http://inpn.mnhn.fr/mtd}CadreAcquisition")
af_list = []
for af in af_iter:
# TODO: IMPORTANT - filter the list of acquisition frameworks with `ID_INSTANCE_FILTER` as made for the datasets in `parse_jdd_xml`
# - Determine it is right to do so: is it possible that no ID_INSTANCE is set for an AF in the XML but still the AF is associated to the instance ?
af_list.append(parse_acquisition_framework(af))
current_af, id_instance = parse_acquisition_framework(af)
# Filter with id_instance
# TODO: Determine it is right to not retrieve an AF for which no ID_INSTANCE is set in the XML
id_instance_filter = current_app.config["MTD"]["ID_INSTANCE_FILTER"]
if id_instance_filter:
if id_instance and id_instance == str(id_instance_filter):
af_list.append(current_af)
else:
af_list.append(current_af)
return af_list


Expand All @@ -100,7 +106,8 @@ def parse_single_acquisition_framework_xml(xml):
"""
root = ET.fromstring(xml, parser=_xml_parser)
ca = root.find(".//" + namespace + "CadreAcquisition")
return parse_acquisition_framework(ca)
parsed_af, _ = parse_acquisition_framework(ca)
return parsed_af


def parse_acquisition_framework(ca):
Expand All @@ -121,11 +128,14 @@ def parse_acquisition_framework(ca):
ca_id_digitizer = None
attributs_additionnels_node = ca.find(namespace + "attributsAdditionnels")

# We extract the ID of the user to assign it the JDD as an id_digitizer
for attr in attributs_additionnels_node:
# We extract the ID of the user to assign it the JDD as an id_digitizer
if get_tag_content(attr, "nomAttribut") == "ID_CREATEUR":
ca_id_digitizer = get_tag_content(attr, "valeurAttribut")

if get_tag_content(attr, "nomAttribut") == "ID_INSTANCE":
id_instance = get_tag_content(attr, "valeurAttribut")

# We search for all the Contact nodes :
# - Main contact in acteurPrincipal node
# - Funder in acteurAutre node
Expand All @@ -149,7 +159,7 @@ def parse_acquisition_framework(ca):
"meta_update_date": ca_update_date,
"id_digitizer": ca_id_digitizer,
"actors": all_actors,
}
}, id_instance


def parse_jdd_xml(xml):
Expand Down

0 comments on commit 3176d97

Please sign in to comment.