Ejemplo n.º 1
0
 /**
  * @covers CitationDAO
  */
 public function testCitationCrud()
 {
     $citationDao = DAORegistry::getDAO('CitationDAO');
     /* @var $citationDao CitationDAO */
     $nameSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema';
     $nameDescription = new MetadataDescription($nameSchemaName, ASSOC_TYPE_AUTHOR);
     $nameDescription->addStatement('given-names', $value = 'Peter');
     $nameDescription->addStatement('given-names', $value = 'B');
     $nameDescription->addStatement('surname', $value = 'Bork');
     $nameDescription->addStatement('prefix', $value = 'Mr.');
     $citationSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema';
     $citationDescription = new MetadataDescription($citationSchemaName, ASSOC_TYPE_CITATION);
     $citationDescription->addStatement('person-group[@person-group-type="author"]', $nameDescription);
     $citationDescription->addStatement('article-title', $value = 'PHPUnit in a nutshell', 'en_US');
     $citationDescription->addStatement('article-title', $value = 'PHPUnit in Kürze', 'de_DE');
     $citationDescription->addStatement('date', $value = '2009-08-17');
     $citationDescription->addStatement('size', $value = 320);
     $citationDescription->addStatement('uri', $value = 'http://phpunit.org/nutshell');
     // Add a simple source description.
     $sourceDescription = new MetadataDescription($citationSchemaName, ASSOC_TYPE_CITATION);
     $sourceDescription->setDisplayName('test');
     $sourceDescription->addStatement('article-title', $value = 'a simple source description', 'en_US');
     $sourceDescription->setSeq(0);
     $citation = new Citation('raw citation');
     $citation->setAssocType(ASSOC_TYPE_ARTICLE);
     $citation->setAssocId(999999);
     $citation->setSeq(50);
     $citation->addSourceDescription($sourceDescription);
     $citation->injectMetadata($citationDescription);
     // Create citation.
     $citationId = $citationDao->insertObject($citation);
     self::assertTrue(is_numeric($citationId));
     self::assertTrue($citationId > 0);
     // Retrieve citation.
     $citationById = $citationDao->getObjectById($citationId);
     // Fix state differences for comparison.
     $citation->removeSupportedMetadataAdapter($citationSchemaName);
     $citationById->removeSupportedMetadataAdapter($citationSchemaName);
     $citationById->_extractionAdaptersLoaded = true;
     $citationById->_injectionAdaptersLoaded = true;
     $sourceDescription->setAssocId($citationId);
     $sourceDescription->removeSupportedMetadataAdapter($citationSchemaName);
     $sourceDescriptions = $citationById->getSourceDescriptions();
     $sourceDescriptions['test']->getMetadataSchema();
     // this will instantiate the meta-data schema internally.
     self::assertEquals($citation, $citationById);
     $citationsByAssocIdDaoFactory = $citationDao->getObjectsByAssocId(ASSOC_TYPE_ARTICLE, 999999);
     $citationsByAssocId = $citationsByAssocIdDaoFactory->toArray();
     self::assertEquals(1, count($citationsByAssocId));
     // Fix state differences for comparison.
     $citationsByAssocId[0]->_extractionAdaptersLoaded = true;
     $citationsByAssocId[0]->_injectionAdaptersLoaded = true;
     $citationsByAssocId[0]->removeSupportedMetadataAdapter($citationSchemaName);
     $sourceDescriptionsByAssocId = $citationsByAssocId[0]->getSourceDescriptions();
     $sourceDescriptionsByAssocId['test']->getMetadataSchema();
     // this will instantiate the meta-data schema internally.
     self::assertEquals($citation, $citationsByAssocId[0]);
     // Update citation.
     $citationDescription->removeStatement('date');
     $citationDescription->addStatement('article-title', $value = 'PHPUnit rápido', 'pt_BR');
     // Update source descriptions.
     $sourceDescription->addStatement('article-title', $value = 'edited source description', 'en_US', true);
     $updatedCitation = new Citation('another raw citation');
     $updatedCitation->setId($citationId);
     $updatedCitation->setAssocType(ASSOC_TYPE_ARTICLE);
     $updatedCitation->setAssocId(999998);
     $updatedCitation->setSeq(50);
     $updatedCitation->addSourceDescription($sourceDescription);
     $updatedCitation->injectMetadata($citationDescription);
     $citationDao->updateObject($updatedCitation);
     $citationAfterUpdate = $citationDao->getObjectById($citationId);
     // Fix state differences for comparison.
     $updatedCitation->removeSupportedMetadataAdapter($citationSchemaName);
     $citationAfterUpdate->removeSupportedMetadataAdapter($citationSchemaName);
     $citationAfterUpdate->_extractionAdaptersLoaded = true;
     $citationAfterUpdate->_injectionAdaptersLoaded = true;
     $sourceDescriptionsAfterUpdate = $citationAfterUpdate->getSourceDescriptions();
     $sourceDescriptionsAfterUpdate['test']->getMetadataSchema();
     // this will instantiate the meta-data schema internally.
     $sourceDescription->removeSupportedMetadataAdapter($citationSchemaName);
     self::assertEquals($updatedCitation, $citationAfterUpdate);
     // Delete citation
     $citationDao->deleteObjectsByAssocId(ASSOC_TYPE_ARTICLE, 999998);
     self::assertNull($citationDao->getObjectById($citationId));
 }
Ejemplo n.º 2
0
 /**
  * Import citations from a raw citation list to the object
  * described by the given association type and id.
  * @param $request Request
  * @param $assocType int
  * @param $assocId int
  * @param $rawCitationList string
  * @return integer the number of spawned citation checking processes
  */
 function importCitations(&$request, $assocType, $assocId, $rawCitationList)
 {
     assert(is_numeric($assocType) && is_numeric($assocId));
     $assocType = (int) $assocType;
     $assocId = (int) $assocId;
     // Remove existing citations.
     $this->deleteObjectsByAssocId($assocType, $assocId);
     // Tokenize raw citations
     import('lib.pkp.classes.citation.CitationListTokenizerFilter');
     $citationTokenizer = new CitationListTokenizerFilter();
     $citationStrings = $citationTokenizer->execute($rawCitationList);
     // Instantiate and persist citations
     $citations = array();
     if (is_array($citationStrings)) {
         foreach ($citationStrings as $seq => $citationString) {
             $citation = new Citation($citationString);
             // Initialize the citation with the raw
             // citation string.
             $citation->setRawCitation($citationString);
             // Set the object association
             $citation->setAssocType($assocType);
             $citation->setAssocId($assocId);
             // Set the counter
             $citation->setSeq($seq + 1);
             $this->insertObject($citation);
             $citations[$citation->getId()] = $citation;
             unset($citation);
         }
     }
     // Check new citations in parallel.
     $noOfProcesses = (int) Config::getVar('general', 'citation_checking_max_processes');
     $processDao =& DAORegistry::getDAO('ProcessDAO');
     return $processDao->spawnProcesses($request, 'api.citation.CitationApiHandler', 'checkAllCitations', PROCESS_TYPE_CITATION_CHECKING, $noOfProcesses);
 }