Skip to content

Commit

Permalink
Merge pull request #683 from NASA-IMPACT/682-automatically-update-pub…
Browse files Browse the repository at this point in the history
…lic-prod-query

682 automatically update public prod query
  • Loading branch information
CarsonDavis authored Apr 26, 2024
2 parents 6c04d9c + d4e2e93 commit 1b22c2a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sde_collections/models/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ class Meta:
verbose_name = "Collection"
verbose_name_plural = "Collections"

def add_to_public_query(self):
"""Add the collection to the public query."""
if self.workflow_status != WorkflowStatusChoices.READY_FOR_PUBLIC_PROD:
raise ValueError(f"{self.config_folder} is not ready for public prod, you can't add it to the public query")

gh = GitHubHandler()
query_path = "webservices/query-smd-primary.xml"
scraper_content = gh._get_file_contents(query_path)
scraper_editor = XmlEditor(scraper_content.decoded_content.decode("utf-8"))

collections = scraper_editor.get_tag_value("CollectionSelection", strict=True)
collections = collections.split(";")
collections.append(f"/SDE/{self.config_folder}/")
collections = list(set(collections))
collections.sort()
collections = ";".join(collections)

scraper_editor.update_or_add_element_value("CollectionSelection", collections)
scraper_content = scraper_editor.update_config_xml()
gh.create_or_update_file(query_path, scraper_content)

@property
def _scraper_config_path(self) -> str:
return f"sources/scrapers/{self.config_folder}/default.xml"
Expand Down Expand Up @@ -473,3 +494,5 @@ def create_configs_on_status_change(sender, instance, created, **kwargs):
elif instance.workflow_status == WorkflowStatusChoices.READY_FOR_ENGINEERING:
instance.create_scraper_config(overwrite=False)
instance.create_indexer_config(overwrite=False)
elif instance.workflow_status == WorkflowStatusChoices.READY_FOR_PUBLIC_PROD:
instance.add_to_public_query()

0 comments on commit 1b22c2a

Please sign in to comment.