diff --git a/src/MDNodaRepositoriesSet.php b/src/MDNodaRepositoriesSet.php index 8d1f81a..960ec1a 100644 --- a/src/MDNodaRepositoriesSet.php +++ b/src/MDNodaRepositoriesSet.php @@ -56,6 +56,7 @@ final class MDNodaRepositoriesSet extends MDValueSet { public const REPOSITORIES_TAG = [ 'aat', 'ackerbau', + 'avefi', 'allgemein', 'col', 'bne', diff --git a/src/enums/MDNodaRepository.php b/src/enums/MDNodaRepository.php index ebaf79f..d31c072 100644 --- a/src/enums/MDNodaRepository.php +++ b/src/enums/MDNodaRepository.php @@ -14,6 +14,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable { case allgemein; // General link to a good source case aat; case ackerbau; + case avefi; case bne; case bnf; case col; @@ -57,6 +58,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable { 'AAT-ID', 'aat' => self::aat, 'ackerbau' => self::ackerbau, + 'avefi' => self::avefi, 'bne' => self::bne, 'bnf' => self::bnf, 'col', @@ -156,6 +158,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable { self::allgemein => 'allgemein', // General link to a good source self::aat => 'aat', self::ackerbau => 'ackerbau', + self::avefi => 'avefi', self::bne => 'bne', self::bnf => 'bnf', self::col => 'col', @@ -199,6 +202,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable { self::allgemein => 'General', // General link to a good source self::aat => 'Art & Architecture Thesaurus (AAT)', self::ackerbau => 'Ackerbau-Thesaurus', + self::avefi => 'AVefi', self::bne => 'Biblioteca Nacional de España (BNE)', self::bnf => 'Bibliothèque nationale de France (BNF)', self::col => 'Catalogue of Life', @@ -242,6 +246,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable { self::allgemein => '', self::aat => 'https://vocab.getty.edu/page/aat/', self::ackerbau => 'https://term.museum-digital.de/ackerbau/tag/', + self::avefi => 'https://hdl.handle.net/', self::bne => 'http://datos.bne.es/persona/', self::bnf => "https://catalogue.bnf.fr/ark:/12148/cb", self::col => 'https://www.catalogueoflife.org/data/taxon/', @@ -304,6 +309,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable { self::allgemein => 'https://www.google.de/search?q=' . urlencode($searchTerm), self::aat => 'https://www.getty.edu/vow/AATServlet?english=N&find=' . urlencode($searchTerm) . '&page=1¬e=', self::ackerbau => 'https://term.museum-digital.de/redir.php?search=' . urlencode($searchTerm) . '&kind=tag|ackerbau', + self::avefi => 'https://www.av-efi.net/search?query=' . urlencode($searchTerm), self::bne => 'http://datos.bne.es/persona/' . urlencode($searchTerm), self::bnf => 'https://catalogue.bnf.fr/resultats-auteur.do?nomAuteur=' . urlencode($searchTerm) . '+&filtre=1&pageRech=rau', self::col => 'https://www.catalogueoflife.org/data/search?q=' . urlencode($searchTerm), @@ -422,6 +428,28 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable { } + /** + * Validates an AVefi ID. AVefi IDs are not numeric. + * + * @param string $id ID to validate. + * + * @return string|false + */ + private static function validateAvefiId(string $id):string|false { + + if (str_contains($id, 'https://www.av-efi.net/')) { + $id = str_replace('https://www.av-efi.net/res/', '', $id); + } + if (str_contains($id, 'https://hdl.handle.net/')) { + $id = str_replace('https://hdl.handle.net/', '', $id); + } + + if (substr_count($id, '/') !== 1) return false; + + return $id; + + } + /** * Validates a BNE ID, returning a string or false. The BNE is basically equalivalent to the * GND, just that the X character can be prepended to the number. @@ -778,6 +806,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable { 'https://vocab.getty.edu/page/aat/', ]), self::ackerbau => self::validateNumericId($id, ['https://term.museum-digital.de/ackerbau/tag/']), + self::avefi => self::validateAvefiId($id), self::bne => self::validateBneId($id, ['http://datos.bne.es/persona/', 'https://datos.bne.es/persona/']), self::bnf => self::validateBnfId($id), self::col => self::validateColId($id), diff --git a/tests/MDNodaRepositoryTest.php b/tests/MDNodaRepositoryTest.php index f17a586..ae608e8 100644 --- a/tests/MDNodaRepositoryTest.php +++ b/tests/MDNodaRepositoryTest.php @@ -48,6 +48,34 @@ final class MDNodaRepositoryTest extends TestCase { } + /** + * Data provider for validating AVefi IDs. + * + * @return Generator + */ + public static function avefiIdForValidationProvider():Generator { + + yield "Full URL, https" => ["21.11155/D80067AB-B4F5-4139-8D78-540D8BC001B8", "https://www.av-efi.net/res/21.11155/D80067AB-B4F5-4139-8D78-540D8BC001B8"]; + yield "ID" => ["21.11155/D80067AB-B4F5-4139-8D78-540D8BC001B8", "21.11155/D80067AB-B4F5-4139-8D78-540D8BC001B8"]; + yield "Broken input / XX503494safdsaf;3" => [false, "XX503494safdsaf;3"]; + + } + + /** + * Ensure validating references to the AVefi works. + * + * @param string|false $expected Expected output. + * @param string $inputString Input string. + * + * @return void + */ + #[DataProvider('avefiIdForValidationProvider')] + public function testAvefiIdValidation(string|false $expected, string $inputString):void { + + self::assertEquals($expected, MDNodaRepository::avefi->validateId($inputString)); + + } + /** * Data provider for validating BNE IDs. * @@ -62,17 +90,6 @@ final class MDNodaRepositoryTest extends TestCase { } - /** - * Data provider for validating BNE IDs. - * - * @return Generator - */ - public static function bnfIdForValidationProvider():Generator { - - yield "Broken input / duplicate https" => [false, "https://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cb104183522"]; - - } - /** * Ensure validating references to the BNE works. * @@ -88,6 +105,17 @@ final class MDNodaRepositoryTest extends TestCase { } + /** + * Data provider for validating BNE IDs. + * + * @return Generator + */ + public static function bnfIdForValidationProvider():Generator { + + yield "Broken input / duplicate https" => [false, "https://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cb104183522"]; + + } + /** * Data provider for validating GND IDs. *