コード例 #1
0
 /**
  * Create a Dataverse study: create deposit package with journal-, article-, 
  * and suppfile-level metadata, then deposit in Dataverse to create study.
  * @param $article Article
  * @return DataverseStudy
  */
 function createStudy($article)
 {
     $package = $this->createMetadataPackage($article);
     $client = $this->_initSwordClient();
     $depositReceipt = $client->depositAtomEntry($this->getSetting($article->getJournalId(), 'dvUri'), $this->getSetting($article->getJournalId(), 'username'), $this->getSetting($article->getJournalId(), 'password'), '', $package->getAtomEntryFilePath());
     $study = null;
     if ($depositReceipt->sac_status == DATAVERSE_PLUGIN_HTTP_STATUS_CREATED) {
         $this->import('classes.DataverseStudy');
         $study = new DataverseStudy();
         $study->setSubmissionId($article->getId());
         $study->setEditUri($depositReceipt->sac_edit_iri);
         $study->setEditMediaUri($depositReceipt->sac_edit_media_iri);
         $study->setStatementUri($depositReceipt->sac_state_iri_atom);
         $study->setDataCitation($depositReceipt->sac_dcterms['bibliographicCitation'][0]);
         // Persistent URI may be present, as an altenate
         foreach ($depositReceipt->sac_links as $link) {
             if ($link->sac_linkrel == 'alternate') {
                 $study->setPersistentUri($link->sac_linkhref);
                 break;
             }
         }
         // Insert new Dataverse study for this submission
         $dataverseStudyDao =& DAORegistry::getDAO('DataverseStudyDAO');
         $dataverseStudyDao->insertStudy($study);
     }
     return $study;
 }
コード例 #2
0
 /**
  * Internal function to return DataverseStudy object from a row.
  * @param $row array
  * @return DataverseStudy
  */
 function &_returnStudyFromRow(&$row)
 {
     $dataversePlugin =& PluginRegistry::getPlugin('generic', $this->_parentPluginName);
     $dataversePlugin->import('classes.DataverseStudy');
     $study = new DataverseStudy();
     $study->setId($row['study_id']);
     $study->setSubmissionId($row['submission_id']);
     $study->setEditUri($row['edit_uri']);
     $study->setEditMediaUri($row['edit_media_uri']);
     $study->setStatementUri($row['statement_uri']);
     $study->setPersistentUri($row['persistent_uri']);
     $study->setDataCitation($row['data_citation']);
     return $study;
 }
コード例 #3
0
 /**
  * Create a Dataverse study: create and deposit Atom entry; package and deposit
  * files, if files submitted.
  * @param $article
  * @param $dvFiles array of files to deposit
  * @return DataverseStudy
  */
 function &createStudy(&$article, $dvFiles = array())
 {
     $journal =& Request::getJournal();
     // Go no further if plugin is not configured.
     if (!$this->getSetting($journal->getId(), 'dvUri')) {
         return false;
     }
     $packager = new DataversePackager();
     $suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
     // Add article metadata
     $packager->addMetadata('title', $article->getLocalizedTitle());
     $packager->addMetadata('description', $article->getLocalizedAbstract());
     foreach ($article->getAuthors() as $author) {
         $packager->addMetadata('creator', $author->getFullName(true));
     }
     // subject: academic disciplines
     $split = '/\\s*' . DATAVERSE_PLUGIN_SUBJECT_SEPARATOR . '\\s*/';
     foreach (preg_split($split, $article->getLocalizedDiscipline(), NULL, PREG_SPLIT_NO_EMPTY) as $subject) {
         $packager->addMetadata('subject', $subject);
     }
     // subject: subject classifications
     foreach (preg_split($split, $article->getLocalizedSubjectClass(), NULL, PREG_SPLIT_NO_EMPTY) as $subject) {
         $packager->addMetadata('subject', $subject);
     }
     // subject:	 keywords
     foreach (preg_split($split, $article->getLocalizedSubject(), NULL, PREG_SPLIT_NO_EMPTY) as $subject) {
         $packager->addMetadata('subject', $subject);
     }
     // geographic coverage
     foreach (preg_split($split, $article->getLocalizedCoverageGeo(), NULL, PREG_SPLIT_NO_EMPTY) as $coverage) {
         $packager->addMetadata('coverage', $coverage);
     }
     // publisher
     $packager->addMetadata('publisher', $journal->getSetting('publisherInstitution'));
     // rights
     $packager->addMetadata('rights', $journal->getLocalizedSetting('copyrightNotice'));
     // isReferencedBy
     $packager->addMetadata('isReferencedBy', $this->getCitation($article));
     // Include (some) suppfile metadata in study
     foreach ($dvFiles as $dvFile) {
         $suppFile =& $suppFileDao->getSuppFile($dvFile->getSuppFileId(), $article->getId());
         if (isset($suppFile)) {
             // subject
             foreach (preg_split($split, $suppFile->getSuppFileSubject(), NULL, PREG_SPLIT_NO_EMPTY) as $subject) {
                 $packager->addMetadata('subject', $subject);
             }
             // Type of file
             if ($suppFile->getType()) {
                 $packager->addMetadata('type', $suppFile->getType());
             }
             // Type of file, user-defined:
             if ($suppFile->getSuppFileTypeOther()) {
                 $packager->addMetadata('type', $suppFile->getSuppFileTypeOther());
             }
         }
     }
     // Write Atom entry file
     $packager->createAtomEntry();
     // Create the study in Dataverse
     $client = $this->_initSwordClient();
     $depositReceipt = $client->depositAtomEntry($this->getSetting($article->getJournalId(), 'dvUri'), $this->getSetting($article->getJournalId(), 'username'), $this->getSetting($article->getJournalId(), 'password'), '', $packager->getAtomEntryFilePath());
     // Exit & notify if study failed to be created
     if ($depositReceipt->sac_status != DATAVERSE_PLUGIN_HTTP_STATUS_CREATED) {
         return false;
     }
     // Insert new Dataverse study for this submission
     $dataverseStudyDao =& DAORegistry::getDAO('DataverseStudyDAO');
     $this->import('classes.DataverseStudy');
     $study = new DataverseStudy();
     $study->setSubmissionId($article->getId());
     $study->setEditUri($depositReceipt->sac_edit_iri);
     $study->setEditMediaUri($depositReceipt->sac_edit_media_iri);
     $study->setStatementUri($depositReceipt->sac_state_iri_atom);
     $study->setDataCitation($depositReceipt->sac_dcterms['bibliographicCitation'][0]);
     // Persistent URI may be present, as an altenate
     foreach ($depositReceipt->sac_links as $link) {
         if ($link->sac_linkrel == 'alternate') {
             $study->setPersistentUri($link->sac_linkhref);
             break;
         }
     }
     $dataverseStudyDao->insertStudy($study);
     // Fine. Now add the files, if any are present.
     for ($i = 0; $i < sizeof($dvFiles); $i++) {
         $dvFile =& $dvFiles[$i];
         $suppFile =& $suppFileDao->getSuppFile($dvFile->getSuppFileId(), $article->getId());
         $dvFileIndex[str_replace(' ', '_', $suppFile->getOriginalFileName())] =& $dvFile;
         $packager->addFile($suppFile);
     }
     // Create the deposit package & add package to Dataverse
     $packager->createPackage();
     $depositReceipt = $client->deposit($study->getEditMediaUri(), $this->getSetting($journal->getId(), 'username'), $this->getSetting($journal->getId(), 'password'), '', $packager->getPackageFilePath(), $packager->getPackaging(), $packager->getContentType(), false);
     // in progress? false
     if ($depositReceipt->sac_status != DATAVERSE_PLUGIN_HTTP_STATUS_CREATED) {
         return false;
     }
     // Get the study statement & update the local file list
     $studyStatement = $client->retrieveAtomStatement($study->getStatementUri(), $this->getSetting($journal->getId(), 'username'), $this->getSetting($journal->getId(), 'password'), '');
     if (!isset($studyStatement)) {
         return false;
     }
     // Update each Dataverse file with study id & content source URI
     $dvFileDao =& DAORegistry::getDAO('DataverseFileDAO');
     foreach ($studyStatement->sac_entries as $entry) {
         $dvUriFileName = substr($entry->sac_content_source, strrpos($entry->sac_content_source, '/') + 1);
         if (array_key_exists($dvUriFileName, $dvFileIndex)) {
             $dvFile =& $dvFileIndex[$dvUriFileName];
             $dvFile->setContentSourceUri($entry->sac_content_source);
             $dvFile->setStudyId($study->getId());
             $dvFileDao->updateDataverseFile($dvFile);
         }
     }
     // Done.
     return $study;
 }