/** * @return Api_Models_Concept */ protected function _fetchConcept() { $id = $this->getRequest()->getParam('id'); if (null === $id) { throw new Zend_Controller_Exception('No id `' . $id . '` provided', 400); } /* * this is for clients that need special routes like "http://data.beeldenegluid.nl/gtaa/123456" * with this we can create a route in the config ini like this: * * resources.router.routes.route_id.type = "Zend_Controller_Router_Route_Regex" * resources.router.routes.route_id.route = "gtaa\/(\d+)" * resources.router.routes.route_id.defaults.module = "api" * resources.router.routes.route_id.defaults.controller = "concept" * resources.router.routes.route_id.defaults.action = "get" * resources.router.routes.route_id.defaults.id_prefix = "http://data.beeldengeluid.nl/gtaa/" * resources.router.routes.route_id.defaults.format = "html" * resources.router.routes.route_id.map.1 = "id" * resources.router.routes.route_id.reverse = "gtaa/%d" */ $id_prefix = $this->getRequest()->getParam('id_prefix'); if (null !== $id_prefix && !OpenSKOS_Solr::isValidUuid($id)) { $id_prefix = str_replace('%tenant%', $this->getRequest()->getParam('tenant'), $id_prefix); $id = $id_prefix . $id; } // Tries to find any not deleted concept. $concept = $this->model->getConcept($id); // If not deleted concept was not found - tries to find deleted one. if (null === $concept) { $concept = $this->model->getConcept($id, array(), true); } if (null === $concept) { throw new Zend_Controller_Exception('Concept `' . $id . '` not found', 404); } if ($concept->isDeleted()) { throw new Zend_Controller_Exception('Concept `' . $id . '` is deleted since ' . $concept['timestamp'], 410); } return $concept; }
public function checkParams($verb) { if (!isset($this->_verbs[$verb])) { unset($this->_params['verb']); throw new OaiPmh_Exception('Verb `' . $verb . '` is not a valid OAI-PMH verb', OaiPmh_Exception::badVerb); } //low level check for double parameters: $queryString = '&' . ltrim($_SERVER['QUERY_STRING'], '&'); parse_str($queryString, $queryStringAsArray); foreach ($queryStringAsArray as $qParameter => $value) { $c = 0; str_replace("&{$qParameter}=", '', $queryString, $c); if ($c > 1) { throw new OaiPmh_Exception('You can use parameter `' . $qParameter . '` only once', OaiPmh_Exception::badArgument); } } foreach ($this->getParams() as $key => $value) { if ($key == 'verb') { continue; } if (!in_array($key, $this->_verbs[$verb])) { unset($this->_params[$key]); throw new OaiPmh_Exception('Verb `' . $verb . '` may not contain parameter `' . $key . '`', OaiPmh_Exception::badArgument); } } if (null !== ($resumptionToken = $this->getParam('resumptionToken'))) { $params = unserialize(base64_decode($resumptionToken)); if (false === $params || !is_array($params)) { throw new OaiPmh_Exception('The given resumptionToken is not a valid one', OaiPmh_Exception::badResumptionToken); } if (!isset($params['verb'])) { throw new OaiPmh_Exception('The given resumptionToken is not a valid one (no verb)', OaiPmh_Exception::badResumptionToken); } if ($params['verb'] != $verb) { throw new OaiPmh_Exception('The given resumptionToken is not a valid one for verb `' . $verb . '`', OaiPmh_Exception::badResumptionToken); } //check for other parameters (which is illegal): if (count($queryStringAsArray) > 2) { throw new OaiPmh_Exception('Illegal use of the resumptionToken: too many arguments, only `verb` is allowed', OaiPmh_Exception::badArgument); } $this->setParams($params); return $this->checkparams($verb); } $from = null; $until = null; if (null !== ($request_from = $this->getParam('from'))) { try { $from = new Zend_Date($request_from, Zend_Date::ISO_8601); $this->setParam('from', $from); } catch (Zend_Date_Exception $e) { throw new OaiPmh_Exception('Date `from` is not a valid ISO8601 format', OaiPmh_Exception::badArgument); } } if (null !== ($request_until = $this->getParam('until'))) { try { $until = new Zend_Date($request_until, Zend_Date::ISO_8601); $this->setParam('until', $until); } catch (Zend_Date_Exception $e) { throw new OaiPmh_Exception('Date `until` is not a valid ISO8601 format', OaiPmh_Exception::badArgument); } } if (null !== $until && null !== $from) { if ($until->isEarlier($from)) { throw new OaiPmh_Exception('The `from` argument must be less than or equal to the `until` argument', OaiPmh_Exception::badArgument); } if (strlen($request_from) != strlen($request_until)) { throw new OaiPmh_Exception('The `from` and `until` argument must have the same granularity', OaiPmh_Exception::badArgument); } } if (null !== ($setspec = $this->getParam('set'))) { if (!preg_match('/([A-Za-z0-9\\-_\\.!~\\*\'\\(\\)])+(:[A-Za-z0-9\\-_\\.!~\\*\'\\(\\)]+)*/', $setspec)) { throw new OaiPmh_Exception('setSpec `' . $setspec . '` contains URI reserved characters', OaiPmh_Exception::badArgument); } if (null === ($this->_set = $this->getSet($setspec))) { throw new OaiPmh_Exception('setSpec `' . $setspec . '` is not a valid set for this repository', OaiPmh_Exception::badArgument); } } if (null !== ($metadataPrefix = $this->getParam('metadataPrefix'))) { if (!isset($this->_metadataFormats[$metadataPrefix])) { throw new OaiPmh_Exception('metadataPrefix `' . $metadataPrefix . '` is not a valid metadataPrefix for this repository', OaiPmh_Exception::badArgument); } } else { if ($verb == 'ListIdentifiers' || $verb == 'ListRecords' || $verb == 'GetRecord') { throw new OaiPmh_Exception('Missing required argument `metadataPrefix`', OaiPmh_Exception::badArgument); } } if ($verb == 'GetRecord') { if (null === ($identifier = $this->getParam('identifier'))) { throw new OaiPmh_Exception('Missing required argument `identifier`', OaiPmh_Exception::badArgument); } if (!OpenSKOS_Solr::isValidUuid($identifier)) { throw new OaiPmh_Exception('argument `identifier` is not a valid identifier (UUID:UUID)', OaiPmh_Exception::badArgument); } $this->setParam('identifier', $identifier); } if ($verb == 'ListMetadataFormats') { if (null !== ($identifier = $this->getParam('identifier'))) { if (!OpenSKOS_Solr::isValidUuid($identifier)) { throw new OaiPmh_Exception('argument `identifier` is not a valid identifier (UUID:UUID)', OaiPmh_Exception::badArgument); } $result = OpenSkos_Solr::getInstance()->search('uuid:' . $identifier, array('rows' => 1)); if ($result['response']['numFound'] === 0) { throw new OaiPmh_Exception('Concept `' . $identifier . '` does not exist in this repository', OaiPmh_Exception::idDoesNotExist); } } } $this->_view->parameters = $this->getParams(); }