| 47 | self._process_mapping(database, mapping) |
| 48 | |
| 49 | def _process_mapping(self, database: str, mapping: dict): |
| 50 | ont_type = mapping["ontologyType"] |
| 51 | table = mapping["sourceTable"] |
| 52 | identifier = mapping.get("identifier") |
| 53 | filter_spec = mapping.get("filter") |
| 54 | enum_mappings = mapping.get("enumMappings", {}) |
| 55 | |
| 56 | direct_columns = {} |
| 57 | fk_refs = {} |
| 58 | joins = {} |
| 59 | |
| 60 | for prop, value in mapping.get("columnMappings", {}).items(): |
| 61 | if isinstance(value, str): |
| 62 | direct_columns[prop] = value |
| 63 | self.property_registry.setdefault(prop, []).append( |
| 64 | (database, table, value) |
| 65 | ) |
| 66 | elif isinstance(value, dict): |
| 67 | if "references" in value: |
| 68 | fk_refs[prop] = value |
| 69 | elif "join" in value: |
| 70 | joins[prop] = value["join"] |
| 71 | |
| 72 | entry = { |
| 73 | "database": database, |
| 74 | "table": table, |
| 75 | "identifier": identifier, |
| 76 | "filter": filter_spec, |
| 77 | "columns": direct_columns, |
| 78 | "fk_refs": fk_refs, |
| 79 | "joins": joins, |
| 80 | "enums": enum_mappings, |
| 81 | } |
| 82 | self.type_registry.setdefault(ont_type, []).append(entry) |
| 83 | |
| 84 | def get_canonical_mapping(self, ont_type: str) -> Optional[dict]: |
| 85 | """Get the canonical (preferred) mapping for an ontology type.""" |