From fa79ed211f38d6fe1af78dbee7bd337058919e99 Mon Sep 17 00:00:00 2001 From: EEA Jenkins Date: Fri, 20 Dec 2024 13:29:23 +0200 Subject: [PATCH 1/7] Updated version to 6.5 --- Products/Reportek/version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Products/Reportek/version.txt b/Products/Reportek/version.txt index 89c24c50..7822c1ab 100644 --- a/Products/Reportek/version.txt +++ b/Products/Reportek/version.txt @@ -1 +1 @@ -6.5-dev0 +6.5 From 851fa507fd9a376374e7e50f307b184d0968d4a9 Mon Sep 17 00:00:00 2001 From: EEA Jenkins Date: Fri, 20 Dec 2024 13:29:25 +0200 Subject: [PATCH 2/7] Updated changelog - needs review --- docs/HISTORY.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index 6a86413a..12faed3a 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -1,6 +1,10 @@ Changelog ========= +6.5 - (2024-12-20) +--------------------------- +* Change: Merge development [olimpiurob] + 6.5-dev0 - (unreleased) --------------------------- From b8f83dbd46af5ad06ffcd0721450c818ad50558a Mon Sep 17 00:00:00 2001 From: EEA Jenkins Date: Fri, 20 Dec 2024 13:29:26 +0200 Subject: [PATCH 3/7] Updated changelog - removed develop information --- docs/HISTORY.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index 12faed3a..a6e67c68 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -5,8 +5,10 @@ Changelog --------------------------- * Change: Merge development [olimpiurob] -6.5-dev0 - (unreleased) +6.5 - (2024-12-20) --------------------------- +* Change: Merge development + [olimpiurob] 6.4 - (2024-11-28) --------------------------- From 60774acf7fcc36caa833511514a01d6c6d0d13f0 Mon Sep 17 00:00:00 2001 From: EEA Jenkins <2368628+eea-jenkins@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:32:13 +0200 Subject: [PATCH 4/7] Back to devel --- Products/Reportek/version.txt | 2 +- docs/HISTORY.txt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Products/Reportek/version.txt b/Products/Reportek/version.txt index 7822c1ab..09e196f6 100644 --- a/Products/Reportek/version.txt +++ b/Products/Reportek/version.txt @@ -1 +1 @@ -6.5 +6.6-dev0 diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index a6e67c68..edf8f967 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -1,6 +1,9 @@ Changelog ========= +6.6-dev0 - (unreleased) +--------------------------- + 6.5 - (2024-12-20) --------------------------- * Change: Merge development [olimpiurob] From ea83ce13cdd1b31e39602faabbc6504185f7b96c Mon Sep 17 00:00:00 2001 From: Olimpiu Rob Date: Mon, 23 Dec 2024 12:09:29 +0200 Subject: [PATCH 5/7] feat: refactored update_company_collection method - refs #281710 --- Products/Reportek/ReportekEngine.py | 228 +++++++++++----------------- 1 file changed, 86 insertions(+), 142 deletions(-) diff --git a/Products/Reportek/ReportekEngine.py b/Products/Reportek/ReportekEngine.py index ae6d2ca9..117dfa07 100644 --- a/Products/Reportek/ReportekEngine.py +++ b/Products/Reportek/ReportekEngine.py @@ -712,36 +712,16 @@ def get_df_domain(self, dfs, df_type=None): return None - def create_fgas_collections( - self, ctx, country_uri, company_id, name, old_company_id=None + def create_ecr_collections( + self, ctx, country_uri, company_id, name, domain, old_company_id=None ): - # Hardcoded obligations should be fixed and retrieved automatically - parent_coll_df = self.get_active_df("FGAS") - eq_imports_df = ["http://rod.eionet.europa.eu/obligations/765"] - bulk_imports_df = ["http://rod.eionet.europa.eu/obligations/764"] + parent_coll_df = self.get_active_df(domain) main_env_id = old_company_id if old_company_id else company_id ctx.manage_addCollection( dataflow_uris=parent_coll_df, country=country_uri, id=main_env_id, title=name, - allow_collections=1, - allow_envelopes=1, - descr="", - locality="", - partofyear="", - year="", - endyear="", - old_company_id=old_company_id, - ) - coll = getattr(ctx, main_env_id) - coll.company_id = company_id - ei_id = "".join([RepUtils.generate_id("col"), "ei"]) - coll.manage_addCollection( - dataflow_uris=eq_imports_df, - country=country_uri, - id=ei_id, - title="Upload of verification documents (equipment importers)", allow_collections=0, allow_envelopes=1, descr="", @@ -751,140 +731,104 @@ def create_fgas_collections( endyear="", old_company_id=old_company_id, ) - bi_id = "".join([RepUtils.generate_id("col"), "bi"]) - coll.manage_addCollection( - dataflow_uris=bulk_imports_df, - country=country_uri, - id=bi_id, - title="""Upload of verification documents""" - """ (HFC producers and bulk importers)""", - allow_collections=0, - allow_envelopes=1, - descr="", - locality="", - partofyear="", - year="", - endyear="", - old_company_id=old_company_id, - ) - ei = getattr(coll, ei_id) - ei.company_id = company_id - ei.reindexObject() - bi = getattr(coll, bi_id) - bi.company_id = company_id - bi.reindexObject() - coll.allow_collections = 0 - coll.reindexObject() def update_company_collection( - self, company_id, domain, country, name, old_collection_id=None + self, domain, country, company_id, name, old_collection_id=None ): - """Update information on an existing old-type collection - (say, 'fgas30001') mainly setting it's `company_id` - (the id internal to Fgas Portal for instance) - If no `old_collection_id` is provided then a new collection will be - created with id=company_id=provided `company_id`. - If `old_collection_id` is provided, the the collection must exist - in the expected path deducted from the - domain/country/old_collection_id. It's company_id will be updated. - If `old_collection_id` does not exist at the expected location - nothing will happen.""" - - # Disable CSRF protection - if "IDisableCSRFProtection" in dir(plone.protect.interfaces): + """Update or create a company collection. + + Args: + domain (str): The domain name + country (str): Country code + company_id (str): Company identifier + name (str): Company name + old_collection_id (str, optional): Previous collection ID + + Returns: + str: JSON response with status and message + """ + # Disable CSRF protection if available + if hasattr(plone.protect.interfaces, "IDisableCSRFProtection"): alsoProvides( self.REQUEST, plone.protect.interfaces.IDisableCSRFProtection ) - if REPORTEK_DEPLOYMENT == DEPLOYMENT_BDR: - self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") - resp = {"status": "fail", "message": ""} + if REPORTEK_DEPLOYMENT != DEPLOYMENT_BDR: + return - coll_path = self.FGASRegistryAPI.buildCollectionPath( - domain, country, company_id, old_collection_id - ) + response = self.REQUEST.RESPONSE + response.setHeader("Content-Type", "application/json") - if not coll_path: - msg = ( - """Cannot form path to collection, with details domain: """ - """ %s, country: %s, company_id: %s, old_collection_id: """ - """ %s.""" - % (domain, country, company_id, old_collection_id) - ) - logger.warning(msg) - # return failure (404) to the service calling us - self.REQUEST.RESPONSE.setStatus(404) - resp["message"] = msg - return json.dumps(resp) + def create_error_response(message, status_code=404): + response.setStatus(status_code) + return json.dumps({"status": "fail", "message": message}) + + def create_success_response(message): + return json.dumps({"status": "success", "message": message}) + + # Get collection path + coll_path = self.FGASRegistryAPI.buildCollectionPath( + domain, country, company_id, old_collection_id + ) + if not coll_path: + error_msg = ( + "Cannot form path to collection with details: " + "domain: {0}, country: {1}, " + "company_id: {2}, old_collection_id: {3}" + ).format(domain, country, company_id, old_collection_id) + logger.warning(error_msg) + return create_error_response(error_msg) + + # Parse path + try: path_parts = coll_path.split("/") obligation_id = path_parts[0] country_id = path_parts[1] - coll_id = path_parts[2] + country_folder_path = "{0}/{1}".format(obligation_id, country_id) + country_folder = self.restrictedTraverse(country_folder_path) + except (IndexError, KeyError) as e: + error_msg = ( + "Cannot update collection {0}. " + "Invalid path structure: {1}".format(coll_path, str(e)) + ) + logger.warning(error_msg) + return create_error_response(error_msg) + + # Determine collection ID + collection_id = old_collection_id or company_id + collection = getattr(country_folder, collection_id, None) + + # Create collection if it doesn't exist + if not collection: try: - country_folder_path = "/".join([obligation_id, country_id]) - country_folder = self.restrictedTraverse(country_folder_path) - except KeyError: - msg = ( - """Cannot update collection %s. Path to collection """ - """does not exist""" % coll_path + country_uri = getattr(country_folder, "country", "") + self.create_ecr_collections( + country_folder, + country_uri, + company_id, + name, + domain, + old_company_id=old_collection_id, ) - logger.warning(msg) - # return 404 - self.REQUEST.RESPONSE.setStatus(404) - resp["message"] = msg - return json.dumps(resp) - - coll_id = company_id - if old_collection_id: - coll_id = old_collection_id - - coll = getattr(country_folder, coll_id, None) - if not coll: - try: - country_uri = getattr(country_folder, "country", "") - if domain == "FGAS": - self.create_fgas_collections( - country_folder, - country_uri, - company_id, - name, - old_company_id=old_collection_id, - ) - else: - country_folder.manage_addCollection( - dataflow_uris=[self.get_active_df(domain)], - country=country_uri, - id=company_id, - title=name, - allow_collections=0, - allow_envelopes=1, - descr="", - locality="", - partofyear="", - year="", - endyear="", - old_company_id=old_collection_id, - ) - coll = getattr(country_folder, coll_id) - except Exception as e: - msg = "Cannot create collection %s. " % coll_path - logger.warning(msg + str(e)) - # return failure (404) to the service calling us - self.REQUEST.RESPONSE.setStatus(404) - resp["message"] = msg - return json.dumps(resp) - coll.company_id = company_id - if old_collection_id: - coll.old_company_id = old_collection_id - coll.reindexObject() - resp["status"] = "success" - resp["message"] = ( - "Collection %s updated/created succesfully" % coll_path - ) - return json.dumps(resp) - else: - pass + collection = getattr(country_folder, collection_id) + except Exception as e: + error_msg = "Cannot create collection {0}: {1}".format( + coll_path, str(e) + ) + logger.warning(error_msg) + return create_error_response(error_msg) + + # Update collection properties + collection.company_id = company_id + if old_collection_id: + collection.old_company_id = old_collection_id + collection.reindexObject() + + success_msg = "Collection {0} updated/created successfully".format( + coll_path + ) + return create_success_response(success_msg) if REPORTEK_DEPLOYMENT == DEPLOYMENT_BDR: security.declareProtected("Audit Envelopes", "globalworklist") From e47a63de83efb3b06d28adacb4238902d6bd80fd Mon Sep 17 00:00:00 2001 From: Olimpiu Rob Date: Mon, 23 Dec 2024 12:24:11 +0200 Subject: [PATCH 6/7] bumped version --- Products/Reportek/version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Products/Reportek/version.txt b/Products/Reportek/version.txt index 09e196f6..9fa141a7 100644 --- a/Products/Reportek/version.txt +++ b/Products/Reportek/version.txt @@ -1 +1 @@ -6.6-dev0 +6.7-dev0 From 0bf2bc7461ed0d151a2bea58c30d9f191d7bd8b0 Mon Sep 17 00:00:00 2001 From: EEA Jenkins Date: Mon, 23 Dec 2024 12:43:20 +0200 Subject: [PATCH 7/7] Updated changelog - removed develop information --- docs/HISTORY.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index edf8f967..eaf842a4 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -1,8 +1,10 @@ Changelog ========= -6.6-dev0 - (unreleased) +6.6 - (2024-12-23) --------------------------- +* Change: Develop + [olimpiurob] 6.5 - (2024-12-20) ---------------------------