Skip to content

Commit

Permalink
maint: 2025 R1 update (#630)
Browse files Browse the repository at this point in the history
Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
Andy-Grigg and pyansys-ci-bot authored Oct 16, 2024
1 parent c1c84b3 commit b6cfc99
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
16 changes: 11 additions & 5 deletions cicd/get_cleaned_db_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@
# Generally static unless the BoM Analytics Servers logic has changed, or these attributes have been added to the layout
# Both of these scenarios are unlikely
# dict[Table name: list[Attribute name]]
extra_attributes = {"Coatings": ["Coating Code"], "Legislations and Lists": ["Legislation ID", "Short title"]}
extra_attributes = {
"Coatings": ["Coating Code"],
"Legislations and Lists": ["Legislation ID", "Short title"],
}

# Will generally be different for each release, and may be empty.
# dict[Table name: dict[Current attribute name: New attribute name]]
renamed_attributes = {"Products and parts": {"General comments": "Comments"}}
renamed_attributes = {
# "Table name": {
# "Old attribute name": "New attribute name",
# }
}

info = {}
logger.info(f"Reading records and attributes from database '{DB_KEY}'")
Expand Down Expand Up @@ -109,7 +115,7 @@
for extra_attribute_name in relevant_attribute_names:
attribute_info = attribute_name_map[extra_attribute_name]
added_items.append(
models.GrantaServerApiSchemaLayoutsLayoutAttributeItem(
models.GsaLayoutAttributeItem(
attribute_type=attribute_info.type,
underlying_entity_guid=attribute_info.guid,
name=attribute_info.name,
Expand All @@ -121,7 +127,7 @@
)
)
layout_info.append(
models.GrantaServerApiSchemaLayoutsFullLayoutSection(
models.GsaFullLayoutSection(
name="Extra Attributes",
section_items=added_items,
display_names={},
Expand Down
4 changes: 2 additions & 2 deletions cicd/modify_custom_rs_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
database_client = api.SchemaDatabasesApi(api_client)

logger.info("Renaming Database")
database_info: models.GrantaServerApiSchemaDatabase = database_client.get_database(database_key=CUSTOM_DB_KEY)
database_info: models.GsaDatabase = database_client.get_database(database_key=CUSTOM_DB_KEY)
guid = database_info.guid
new_name = "Restricted Substances Custom Tables"
rename_request = models.GrantaServerApiSchemaUpdateDatabase(name=new_name)
rename_request = models.GsaUpdateDatabase(name=new_name)

database_client.update_database(database_key=CUSTOM_DB_KEY, body=rename_request)

Expand Down
26 changes: 14 additions & 12 deletions cicd/prepare_rs_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_table_name_guid_map(self, db_key: str) -> Mapping[str, str]:
def update_table_name(self, db_key: str, table_guid: str, new_table_name: str) -> None:
tables_api = api.SchemaTablesApi(self._client)
self.logger.info(f"Updating Table - {db_key}:{table_guid} with name '{new_table_name}'")
patch_request = models.GrantaServerApiSchemaTablesUpdateTable(name=new_table_name)
patch_request = models.GsaUpdateTable(name=new_table_name)
tables_api.update_table(database_key=db_key, table_guid=table_guid, body=patch_request)


Expand Down Expand Up @@ -86,15 +86,15 @@ def delete_layout(self, layout_guid: str) -> None:

def create_layout(self, layout_name: str) -> str:
logger.info(f"Creating new layout '{layout_name}'")
layout_request = models.GrantaServerApiSchemaLayoutsCreateLayout(name=layout_name)
layout_request = models.GsaCreateLayout(name=layout_name)
layout_response = self._layouts_api.create_layout(
database_key=self._db_key, table_guid=self._table_guid, body=layout_request
)
return layout_response.guid

def create_layout_section(self, layout_guid: str, section_name: str) -> str:
logger.info(f"Creating new layout section '{section_name}' in layout '{layout_guid}'")
section_request = models.GrantaServerApiSchemaLayoutsCreateLayoutSection(name=section_name)
section_request = models.GsaCreateLayoutSection(name=section_name)
section_response = self._layout_sections_api.create_section( # noqa: E501
database_key=self._db_key, table_guid=self._table_guid, layout_guid=layout_guid, body=section_request
)
Expand All @@ -105,6 +105,8 @@ def add_layout_section_item(self, layout_guid: str, layout_section_guid: str, it
f"Adding new item '{item_information['name']}' to layout section '{layout_section_guid}' in layout '{layout_guid}'" # noqa: E501
)
new_section_item = self._process_layout_item(item_information)
if new_section_item is None:
return
self._layout_sections_api.create_layout_item( # noqa: E501
database_key=self._db_key,
table_guid=self._table_guid,
Expand All @@ -113,25 +115,25 @@ def add_layout_section_item(self, layout_guid: str, layout_section_guid: str, it
body=new_section_item,
)

def _process_layout_item(self, item_information: Mapping) -> models.GrantaServerApiSchemaLayoutsNewLayoutItem:
def _process_layout_item(self, item_information: Mapping) -> models.GsaNewLayoutItem | None:
if item_information["item_type"] == "attribute":
return self._process_attribute(item_information)
elif item_information["item_type"] == "link":
if item_information["link_type"] == "associationChain":
return self._process_association_chain(item_information)
elif item_information["link_type"] == "crossDatabaseLink":
return None
raise NotImplementedError("Other layout items are not supported yet...")

def _process_association_chain(self, layout_item):
item_name = layout_item["name"]
logger.info(f"--Association Chain - '{item_name}'")
links = self._process_association_chain_link(layout_item)
return models.GrantaServerApiSchemaLayoutsNewLayoutAssociationChainItem(
association_chain_name=item_name, association_chain_links=links
)
return models.GsaNewLayoutAssociationChainItem(association_chain_name=item_name, association_chain_links=links)

def _process_association_chain_link(self, chain_link):
links = [
models.GrantaServerApiSchemaLayoutsNewLayoutAssociationChainLink(
models.GsaNewLayoutAssociationChainLink(
forwards=chain_link["forwards"],
tabular_attribute_guid=chain_link["underlying_entity_guid"],
source_database_version_guid=chain_link["target_database"],
Expand All @@ -148,12 +150,12 @@ def _process_attribute(self, layout_item: Mapping):
meta_names = [i["name"] for i in layout_item["meta_attributes"]]
attribute_guid = self._attribute_name_map[attribute_name]

new_section_item = models.GrantaServerApiSchemaLayoutsNewLayoutAttributeItem(attribute_guid=attribute_guid)
new_section_item = models.GsaNewLayoutAttributeItem(attribute_guid=attribute_guid)
if layout_item["tabular_columns"] is not None:
detailed_attribute_info = self._attributes_api.get_attribute(
database_key=self._db_key, table_guid=self._table_guid, attribute_guid=attribute_guid
)
assert isinstance(detailed_attribute_info, models.GrantaServerApiSchemaAttributesTabularAttribute)
assert isinstance(detailed_attribute_info, models.GsaTabularAttribute)
column_map = {column.name: column for column in detailed_attribute_info.tabular_columns}
columns = []
for column_item in layout_item["tabular_columns"]:
Expand All @@ -169,7 +171,7 @@ def _process_attribute(self, layout_item: Mapping):
for meta_name in meta_names:
logger.info(f"----{meta_name}")
meta_item = meta_map[meta_name]
metas.append(models.GrantaServerApiSchemaLayoutsNewLayoutAttributeItem(attribute_guid=meta_item))
metas.append(models.GsaNewLayoutAttributeItem(attribute_guid=meta_item))
new_section_item.meta_attributes = metas
return new_section_item

Expand All @@ -190,7 +192,7 @@ def delete_subset(self, db_key: str, table_guid: str, subset_guid: str):
def create_subset(self, db_key: str, table_guid: str, subset_name: str) -> str:
subsets_api = api.SchemaSubsetsApi(self._client)
self.logger.info(f"Creating new subset '{subset_name}'")
subset_request = models.GrantaServerApiSchemaSubsetsCreateSubset(name=subset_name)
subset_request = models.GsaCreateSubset(name=subset_name)
subset_response = subsets_api.create_subset(database_key=db_key, table_guid=table_guid, body=subset_request)
return subset_response.guid

Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/630.documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
maint: 2025 R1 update

0 comments on commit b6cfc99

Please sign in to comment.