From 611d90ea3751883ccf5ae88331721bff19819db2 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Wed, 26 Nov 2025 12:31:44 +0200 Subject: [PATCH] EnvSources transmogrification. Improve MVA mappers. --- .../Transmogrify/config/schema/tables.json | 30 ++++++++++++++ .../src/Lib/Traits/CacheTrait.php | 12 ++++++ .../src/Lib/Traits/TypeMapperTrait.php | 39 +++++++++++++++++-- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/app/plugins/Transmogrify/config/schema/tables.json b/app/plugins/Transmogrify/config/schema/tables.json index 5dd73bda..24675ab6 100644 --- a/app/plugins/Transmogrify/config/schema/tables.json +++ b/app/plugins/Transmogrify/config/schema/tables.json @@ -629,5 +629,35 @@ "displayField": "id", "cache": ["orcid_identifier", "orcid_source_id"], "addChangelog": true + }, + "env_sources": { + "source": "cm_env_sources", + "displayField": "id", + "addChangelog": true, + "fieldMap": { + "org_identity_source_id": "external_identity_source_id", + "duplicate_mode": null, + "redirect_on_duplicate": "redirect_on_duplicate", + "sp_type": "sp_mode", + "default_affiliation_type_id": "&mapAffiliationType", + "default_affiliation": null, + "address_type_id": "&mapToDefaultAddressTypeId", + "email_address_type_id": "&mapToDefaultEmailAddressTypeId", + "name_type_id": "&mapToDefaultNameTypeId", + "telephone_number_type_id": "&mapToDefaultTelephoneNumberTypeId", + "env_o": "env_organization", + "env_ou": "env_department", + "env_identifier_eppn_login": null, + "env_identifier_eptid_login": null, + "env_identifier_epuid_login": null, + "env_identifier_oidcsub_login": null, + "env_identifier_orcid": null, + "env_identifier_orcid_login": null, + "env_identifier_samlpairwiseid_login": null, + "env_identifier_samlsubjectid_login": null, + "env_identifier_sorid": "env_identifier_sourcekey", + "env_identifier_sorid_login": null, + "env_identifier_network_login": null + } } } diff --git a/app/plugins/Transmogrify/src/Lib/Traits/CacheTrait.php b/app/plugins/Transmogrify/src/Lib/Traits/CacheTrait.php index bada6a21..c5571db5 100644 --- a/app/plugins/Transmogrify/src/Lib/Traits/CacheTrait.php +++ b/app/plugins/Transmogrify/src/Lib/Traits/CacheTrait.php @@ -212,6 +212,18 @@ private function getCoIdFromExternalIdentityId(int $externalIdentityId): ?int return $personId !== null ? $this->getCoIdFromPersonId($personId) : null; } + /** + * Resolve a CO ID starting from an External Identity Source (or legacy OrgIdentitySource) ID via cache. + * + * @param int $externalIdentitySourceId + * @return int|null + */ + private function getCoIdFromExternalIdentitySourceId(int $externalIdentitySourceId): ?int + { + $coId = $this->cache['external_identity_sources']['id'][$externalIdentitySourceId]['co_id'] ?? null; + return $coId !== null ? (int)$coId : null; + } + /** * Resolve a CO ID from a Match Server ID via cache. * diff --git a/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php b/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php index cfd6512e..d398cffd 100644 --- a/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php +++ b/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php @@ -31,10 +31,11 @@ use App\Lib\Enum\PetitionStatusEnum; use Cake\ORM\TableRegistry; +use Cake\Utility\Inflector; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Transmogrify\Lib\Util\RawSqlQueries; -use Cake\Utility\Inflector; +use \App\Lib\Enum\MatchStrategyEnum; /** * Encapsulates all type mapping logic and helpers (map_type + specific wrappers). @@ -175,14 +176,22 @@ protected function mapAddressType(array $row): ?int */ protected function mapAffiliationType(array $row, ?int $coId = null): ?int { + $type = 'affiliation'; + if (isset($row['default_affiliation'])) { + $type = 'default_affiliation'; + } else if (isset($row['sync_affiliation'])) { + $type = 'sync_affiliation'; + } + return $this->mapType( $row, 'PersonRoles.affiliation_type', $coId ?? $this->findCoId($row), - 'affiliation' + $type ); } + /** * Map v4 External Identity Source plugin name to v5 plugin model path. * @@ -254,7 +263,17 @@ protected function mapExternalIdentitySourcePlugin(array $row): ?string */ protected function mapEmailType(array $row): ?int { - return $this->mapType($row, 'EmailAddresses.type', $this->findCoId($row)); + $type = 'type'; + if (isset($row['match_type']) && $row['match_strategy'] === MatchStrategyEnum::EmailAddress) { + $type = 'match_type'; + } + + return $this->mapType( + $row, + 'EmailAddresses.type', + $this->findCoId($row), + $type + ); } /** @@ -332,7 +351,19 @@ protected function mapHistoricPetitionViewerId(array $row): ?int */ protected function mapIdentifierType(array $row): ?int { - return $this->mapType($row, 'Identifiers.type', $this->findCoId($row)); + $type = 'type'; + if (isset($row['sync_identifier_type'])) { + $type = 'sync_identifier_type'; + } else if (isset($row['match_type']) && $row['match_strategy'] === MatchStrategyEnum::Identifier) { + $type = 'match_type'; + } + + return $this->mapType( + $row, + 'Identifiers.type', + $this->findCoId($row), + $type + ); }