Skip to content
Snippets Groups Projects
Commit 726dc7a7 authored by Brittany Faciane's avatar Brittany Faciane
Browse files

Fix the core sampler access to project code linking table.

parent de160c0a
3 merge requests!1606catch 2.8.3 up with main,!1605Merge 2.8.2.3 work to main,!1589Fix the core sampler access to project code linking table.
Pipeline #14491 passed
......@@ -170,6 +170,15 @@ class CoreSampler:
self.visited.clear()
self.save(ancillary_rows)
# the science products table doesn't directly connect to the projects table via a key,
# so the sampler can't find them by default; grab the project code entries manually
products_projects = self.table("science_products_projects")
finder = ProductsProjectsFinder(self.connection)
project_codes = finder.find_project_codes_for_product(science_product_locators)
products_projects_rows = products_projects.fetch_from_many(
{"project_code": project_codes, "science_product_locator": science_product_locators})
self.save(products_projects_rows)
# finally, grab the files associated with the entries
filegroup_ids = [row["filegroup_id"] for row in science_product_rows] + \
[row["filegroup_id"] for row in ancillary_rows]
......@@ -207,10 +216,19 @@ class CoreSampler:
ancillary_product_locators = finder.find_ancillary_product_locators(product_group_id, science_product_locators)
requested_ancillary_rows = ancillary_products.fetch_from_many({"ancillary_product_locator": ancillary_product_locators})
# the science products table doesn't directly connect to the projects table via a key,
# so the sampler can't find them by default; grab the project code entries manually
products_projects = self.table("science_products_projects")
finder = ProductsProjectsFinder(self.connection)
project_codes = finder.find_project_codes_for_product(science_product_locators)
requested_project_product_rows = products_projects.fetch_from_many(
{"project_code": project_codes, "science_product_locator": science_product_locators})
# Create one dictionary pairing table names to row sets
rows_dict = self.create_row_dict(requested_product_group_rows, {})
rows_dict = self.create_row_dict(requested_product_rows, rows_dict)
rows_dict = self.create_row_dict(requested_ancillary_rows, rows_dict)
rows_dict = self.create_row_dict(requested_project_product_rows, rows_dict)
# the correct table deletion order is not the same as the reverse of the topographic map, set the order
deletion_order = ["ancillary_products", "science_products_projects", "science_products_product_groups",
......@@ -326,6 +344,24 @@ class CoreSampler:
rows.write_to(self.writer)
class ProductsProjectsFinder:
"""Looks up project codes for a list of spls"""
def __init__(self, connection: MDDBConnector):
self.connection = connection
def find_project_codes_for_product(self, spls: [str]) -> [str]:
cursor = self.connection.cursor()
sql = """
SELECT project_code FROM science_products_projects
WHERE science_product_locator IN %(spls)s
"""
cursor.execute(sql, {"spls": tuple(spls)})
data = cursor.fetchall()
# All spls will have the same project code, but return a list with a length matching the spls list
return [data[0]["project_code"]] * len(spls)
class ProductFinder:
"""Looks up science product locators for a product group id"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment