From 250f632521ebc8e9b8c302781a42737cf665b543 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 25 Nov 2025 13:31:49 +0200 Subject: [PATCH] orcid sources --- .../Transmogrify/config/schema/tables.json | 23 ++++ .../src/Lib/Traits/CacheTrait.php | 6 +- .../src/Lib/Traits/ManageDefaultsTrait.php | 112 ++++++++++++++++++ 3 files changed, 140 insertions(+), 1 deletion(-) diff --git a/app/plugins/Transmogrify/config/schema/tables.json b/app/plugins/Transmogrify/config/schema/tables.json index 26872e5ea..5dd73bda7 100644 --- a/app/plugins/Transmogrify/config/schema/tables.json +++ b/app/plugins/Transmogrify/config/schema/tables.json @@ -606,5 +606,28 @@ "reference_identifier": "reference_identifier", "org_identity_source_record_id": "ext_identity_source_record_id" } + }, + "orcid_sources": { + "source": "cm_orcid_sources", + "displayField": "id", + "booleans": [ + "scope_inherit" + ], + "cache": ["external_identity_source_id", "server_id"], + "fieldMap": { + "org_identity_source_id": "external_identity_source_id", + "default_affiliation_type_id": "&mapToDefaultAffiliationTypeId", + "address_type_id": "&mapToDefaultAddressTypeId", + "email_address_type_id": "&mapToDefaultEmailAddressTypeId", + "name_type_id": "&mapToDefaultNameTypeId", + "telephone_number_type_id": "&mapToDefaultTelephoneNumberTypeId" + }, + "addChangelog": true + }, + "orcid_tokens": { + "source": "cm_orcid_tokens", + "displayField": "id", + "cache": ["orcid_identifier", "orcid_source_id"], + "addChangelog": true } } diff --git a/app/plugins/Transmogrify/src/Lib/Traits/CacheTrait.php b/app/plugins/Transmogrify/src/Lib/Traits/CacheTrait.php index 9870abab7..bada6a214 100644 --- a/app/plugins/Transmogrify/src/Lib/Traits/CacheTrait.php +++ b/app/plugins/Transmogrify/src/Lib/Traits/CacheTrait.php @@ -129,6 +129,8 @@ protected function findCoId(array $row): int // Map External Identity -> Person -> CO isset($row['external_identity_id']) => $this->getCoIdFromExternalIdentityId((int)$row['external_identity_id']), + isset($row['external_identity_source_id']) => $this->getCoIdFromExternalIdentitySourceId((int)$row['external_identity_source_id']), + isset($row['group_id']) => $this->getCoIdFromGroupId((int)$row['group_id']), isset($row['match_server_id']) => $this->getCoIdFromMatchServer((int)$row['match_server_id']), @@ -136,10 +138,12 @@ protected function findCoId(array $row): int // Legacy/preRow: org_identity_id follows the same External Identity path isset($row['org_identity_id']) => $this->getCoIdFromExternalIdentityId((int)$row['org_identity_id']), + isset($row['org_identity_source_id']) => $this->getCoIdFromExternalIdentitySourceId((int)$row['org_identity_source_id']), + isset($row['co_person_id']) => $this->getCoIdFromPersonId((int)$row['co_person_id']), isset($row['co_group_id']) => $this->getCoIdFromGroupId((int)$row['co_group_id']), - + isset($row['co_person_role_id']) => $this->getCoIdFromPersonRoleId((int)$row['co_person_role_id']), default => null, diff --git a/app/plugins/Transmogrify/src/Lib/Traits/ManageDefaultsTrait.php b/app/plugins/Transmogrify/src/Lib/Traits/ManageDefaultsTrait.php index d1f4a8ec9..0682edc43 100644 --- a/app/plugins/Transmogrify/src/Lib/Traits/ManageDefaultsTrait.php +++ b/app/plugins/Transmogrify/src/Lib/Traits/ManageDefaultsTrait.php @@ -75,6 +75,118 @@ protected function createOwnersGroups(): void } } + /** + * Map to the default affiliation type ID ("member") for the row's CO. + * + * Used when a row does not carry an explicit affiliation value but we want to + * refer to the standard "member" affiliation type within the same CO. + * + * @param array $row Row data from which CO ID can be derived + * @return int|null + */ + protected function mapToDefaultAffiliationTypeId(array $row): ?int + { + // Let CacheTrait::findCoId decide how to resolve the CO ID + $coId = $this->findCoId($row); + + // Build a synthetic row with the default affiliation value + $defaultRow = [ + 'affiliation' => 'member', + ]; + + // Use the generic type mapper to get the extended type ID + return $this->mapType( + $defaultRow, + 'PersonRoles.affiliation_type', + $coId, + 'affiliation' + ); + } + + /** + * Default Address type ID (adjust value if a different default is desired). + * + * @param array $row + * @return int|null + */ + protected function mapToDefaultAddressTypeId(array $row): ?int + { + $coId = $this->findCoId($row); + + $defaultRow = [ + 'type' => 'office', + ]; + + return $this->mapType( + $defaultRow, + 'Addresses.type', + $coId + ); + } + + /** + * Default Email Address type ID. + * + * @param array $row + * @return int|null + */ + protected function mapToDefaultEmailAddressTypeId(array $row): ?int + { + $coId = $this->findCoId($row); + + $defaultRow = [ + 'type' => 'official', + ]; + + return $this->mapType( + $defaultRow, + 'EmailAddresses.type', + $coId + ); + } + + /** + * Default Name type ID. + * + * @param array $row + * @return int|null + */ + protected function mapToDefaultNameTypeId(array $row): ?int + { + $coId = $this->findCoId($row); + + $defaultRow = [ + 'type' => 'official', + ]; + + return $this->mapType( + $defaultRow, + 'Names.type', + $coId + ); + } + + /** + * Default Telephone Number type ID. + * + * @param array $row + * @return int|null + */ + protected function mapToDefaultTelephoneNumberTypeId(array $row): ?int + { + $coId = $this->findCoId($row); + + $defaultRow = [ + 'type' => 'office', + ]; + + return $this->mapType( + $defaultRow, + 'TelephoneNumbers.type', + $coId + ); + } + /** * Insert default CO Settings for COs that don't have settings. *