Exemplo n.º 1
0
 /**
  * redirects OPUS 3.x file names to the corresponding OPUS 4.0 file names
  * in addition it returns HTTP code 301 (moved permanently)
  */
 public function opus3fileAction()
 {
     $docid = $this->getRequest()->getParam('opus3id');
     $filename = $this->getRequest()->getParam('filename');
     if (empty($docid) || empty($filename)) {
         return $this->_redirectToAndExit('index', array('failure' => 'missing argument'), 'index', 'home');
     }
     $f = new Opus_DocumentFinder();
     $ids = $f->setIdentifierTypeValue('opus3-id', $docid)->ids();
     if (count($ids) < 1) {
         return $this->_redirectToAndExit('index', array('failure' => 'given opus3id is unknown'), 'index', 'home');
     }
     if (count($ids) > 1) {
         return $this->_redirectToAndExit('index', array('failure' => 'given opus3id is not unique'), 'index', 'home');
     }
     return $this->_redirect($this->getRequest()->getBaseUrl() . '/files/' . $ids[0] . '/' . $filename, array('prependBase' => false, 'code' => 301));
 }
Exemplo n.º 2
0
 protected function _preStore()
 {
     $type = $this->getType();
     $value = $this->getValue();
     if (isset($type) and isset($value) and $type === 'urn') {
         $finder = new Opus_DocumentFinder();
         $docIds = $finder->setIdentifierTypeValue('urn', $value)->ids();
         $errorMsg = "urn collision (documents " . implode(",", $docIds) . ")";
         if ($this->isNewRecord() and count($docIds) > 0) {
             throw new Opus_Identifier_UrnAlreadyExistsException($errorMsg);
         }
         if (count($docIds) > 1) {
             throw new Opus_Identifier_UrnAlreadyExistsException($errorMsg);
         }
         if (count($docIds) == 1 and !in_array($this->getParentId(), $docIds)) {
             throw new Opus_Identifier_UrnAlreadyExistsException($errorMsg);
         }
     }
     return parent::_preStore();
 }
Exemplo n.º 3
0
 /**
  * prevent URN collisions: check that given URN is unique (in our database)
  */
 private function _validateURN()
 {
     if (!array_key_exists('IdentifierUrn', $this->extendedData)) {
         return true;
     }
     $urn = $this->extendedData['IdentifierUrn'];
     $value = $urn['value'];
     if (trim($value) == '') {
         return true;
     }
     // check URN $urn for collision
     $finder = new Opus_DocumentFinder();
     $finder->setIdentifierTypeValue('urn', $value);
     if ($finder->count() == 0) {
         return true;
     }
     $element = $this->form->getElement('IdentifierUrn');
     if (!is_null($element)) {
         $element->clearErrorMessages();
         $element->addError($this->translate('publish_error_urn_collision'));
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * Retrieve a document id by an oai identifier.
  *
  * @param string $oaiIdentifier
  * @result int
  */
 private function getDocumentIdByIdentifier($oaiIdentifier)
 {
     $identifierParts = explode(":", $oaiIdentifier);
     $docId = null;
     switch ($identifierParts[0]) {
         case 'urn':
             $finder = new Opus_DocumentFinder();
             $finder->setIdentifierTypeValue('urn', $oaiIdentifier);
             $finder->setServerStateInList($this->_deliveringDocumentStates);
             $docIds = $finder->ids();
             $docId = $docIds[0];
             break;
         case 'oai':
             if (isset($identifierParts[2])) {
                 $docId = $identifierParts[2];
             }
             break;
         default:
             throw new Oai_Model_Exception('The prefix of the identifier argument is unknown.', Oai_Model_Error::BADARGUMENT);
             break;
     }
     if (empty($docId) or !preg_match('/^\\d+$/', $docId)) {
         throw new Oai_Model_Exception('The value of the identifier argument is unknown or illegal in this repository.', Oai_Model_Error::IDDOESNOTEXIST);
     }
     return $docId;
 }
Exemplo n.º 5
0
 /**
  * Retrieve an array of all document_id titles associated with the given
  * (identifier, value)
  *
  * @param string $value value of the identifer that should be queried in DB
  * @param string [$type] optional string describing the type of identifier (default is urn)
  * @return array array with all ids of the entries.
  *
  * @deprecated
  */
 public static function getDocumentByIdentifier($value, $type = 'urn')
 {
     $finder = new Opus_DocumentFinder();
     $finder->setIdentifierTypeValue($type, $value);
     return $finder->ids();
 }