diff --git a/backend/geonature/core/gn_meta/mtd/__init__.py b/backend/geonature/core/gn_meta/mtd/__init__.py index 63ca691d60..7279f2ffa7 100644 --- a/backend/geonature/core/gn_meta/mtd/__init__.py +++ b/backend/geonature/core/gn_meta/mtd/__init__.py @@ -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 diff --git a/backend/geonature/core/gn_meta/mtd/xml_parser.py b/backend/geonature/core/gn_meta/mtd/xml_parser.py index 5f246b9033..4ffc443fc7 100644 --- a/backend/geonature/core/gn_meta/mtd/xml_parser.py +++ b/backend/geonature/core/gn_meta/mtd/xml_parser.py @@ -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 @@ -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): @@ -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 @@ -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):