Skip to content

Commit 2e157f0

Browse files
committed
#338 Functions for finding (duplicate) DOIs
1 parent 5b55129 commit 2e157f0

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

library/Opus/Doi/DoiManager.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
use Opus\Common\Log;
4343
use Opus\Common\Log\LogService;
4444
use Opus\Common\Model\NotFoundException;
45+
use Opus\Db\DocumentIdentifiers;
46+
use Opus\Db\TableGateway;
4547
use Opus\Document;
4648
use Opus\DocumentFinder;
4749
use Opus\Doi\Generator\DoiGeneratorException;
@@ -851,4 +853,41 @@ public function storeRegistrationXml($doc, $xml)
851853

852854
file_put_contents($filePath, $xml);
853855
}
856+
857+
/**
858+
* @return string[]
859+
*/
860+
public function getAllDoiValues()
861+
{
862+
$table = TableGateway::getInstance(DocumentIdentifiers::class);
863+
864+
$database = $table->getAdapter();
865+
866+
$select = $table->select()
867+
->from('document_identifiers', 'value')
868+
->distinct(true)
869+
->where('type = ?', 'doi');
870+
871+
return $database->fetchCol($select);
872+
}
873+
874+
/**
875+
* Returns DOIs that are linked to multiple documents.
876+
*
877+
* @return string[]
878+
*/
879+
public function getDuplicateDoiValues()
880+
{
881+
$table = TableGateway::getInstance(DocumentIdentifiers::class);
882+
883+
$database = $table->getAdapter();
884+
885+
$select = $table->select()
886+
->from('document_identifiers', 'value')
887+
->group('value')
888+
->having('count(value) > 1')
889+
->where('type = ?', 'doi');
890+
891+
return $database->fetchCol($select);
892+
}
854893
}

tests/Opus/Doi/DoiManagerTest.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,4 +908,98 @@ public function testGetLandingPageUrlOfDocForId()
908908
$manager->getLandingPageUrlOfDoc($docId)
909909
);
910910
}
911+
912+
public function testGetAllDoiValues()
913+
{
914+
$doiValues = [
915+
'10.0000/1111',
916+
'10.0000/2222',
917+
'10.0000/3333',
918+
];
919+
920+
foreach ($doiValues as $doi) {
921+
$doc = Document::new();
922+
$identifier = $doc->addIdentifier();
923+
$identifier->setType('doi');
924+
$identifier->setValue($doi);
925+
$doc->store();
926+
}
927+
928+
// other identifier type than DOI
929+
$identifier = $doc->addIdentifier();
930+
$identifier->setType('isbn');
931+
$identifier->setValue('isbn-value');
932+
933+
// duplicate DOI identifier
934+
$identifier = $doc->addIdentifier();
935+
$identifier->setType('doi');
936+
$identifier->setValue('10.0000/3333');
937+
938+
$doc->store();
939+
940+
$manager = new DoiManager();
941+
942+
$values = $manager->getAllDoiValues();
943+
944+
$this->assertCount(3, $values);
945+
$this->assertEquals($doiValues, $values);
946+
}
947+
948+
public function testGetAllDoiValuesNonFound()
949+
{
950+
$manager = new DoiManager();
951+
952+
$values = $manager->getAllDoiValues();
953+
954+
$this->assertIsArray($values);
955+
$this->assertEmpty($values);
956+
}
957+
958+
public function testGetDuplicateDoiValues()
959+
{
960+
$doi1 = '10.1000/1111';
961+
$doi2 = '10.1000/2222';
962+
963+
$doc = Document::new();
964+
$doi = $doc->addIdentifier();
965+
$doi->setType('doi');
966+
$doi->setValue($doi1);
967+
$doc->store();
968+
969+
$doc = Document::new();
970+
$doi = $doc->addIdentifier();
971+
$doi->setType('doi');
972+
$doi->setValue($doi1);
973+
$doc->store();
974+
975+
$doc = Document::new();
976+
$doi = $doc->addIdentifier();
977+
$doi->setType('doi');
978+
$doi->setValue($doi2);
979+
$doc->store();
980+
981+
// other identifier type than DOI
982+
$doc = Document::new();
983+
$identifier = $doc->addIdentifier();
984+
$identifier->setType('isbn');
985+
$identifier->setValue('isbn-value');
986+
$doc->store();
987+
988+
$manager = new DoiManager();
989+
990+
$values = $manager->getDuplicateDoiValues();
991+
992+
$this->assertCount(1, $values);
993+
$this->assertEquals($doi1, $values[0]);
994+
}
995+
996+
public function testGetDuplicateDoiValuesNonFound()
997+
{
998+
$manager = new DoiManager();
999+
1000+
$values = $manager->getDuplicateDoiValues();
1001+
1002+
$this->assertIsArray($values);
1003+
$this->assertEmpty($values);
1004+
}
9111005
}

0 commit comments

Comments
 (0)