Example #1
0
 /**
  * Retrieve a batch of documents.
  *
  * @param array    $ids    Array of document identifiers
  * @param ParamBag $params Search backend parameters
  *
  * @return RecordCollectionInterface
  */
 public function retrieveBatch($ids, ParamBag $params = null)
 {
     $onCampus = null !== $params ? $params->get('onCampus') : [false];
     $onCampus = $onCampus ? $onCampus[0] : false;
     // Load 100 records at a time; this is a good number to avoid memory
     // problems while still covering a lot of ground.
     $pageSize = 100;
     // Retrieve records a page at a time:
     $results = false;
     while (count($ids) > 0) {
         $currentPage = array_splice($ids, 0, $pageSize, []);
         try {
             $response = $this->connector->getRecords($currentPage, $this->connector->getInstitutionCode(), $onCampus);
         } catch (\Exception $e) {
             throw new BackendException($e->getMessage(), $e->getCode(), $e);
         }
         $next = $this->createRecordCollection($response);
         if (!$results) {
             $results = $next;
         } else {
             foreach ($next->getRecords() as $record) {
                 $results->add($record);
             }
         }
     }
     $this->injectSourceIdentifier($results);
     return $results;
 }
Example #2
0
 /**
  * Retrieve a single document.
  *
  * @param string   $id     Document identifier
  * @param ParamBag $params Search backend parameters
  *
  * @return RecordCollectionInterface
  */
 public function retrieve($id, ParamBag $params = null)
 {
     try {
         $response = $this->connector->getRecord($id, $this->connector->getInstitutionCode());
     } catch (\Exception $e) {
         throw new BackendException($e->getMessage(), $e->getCode(), $e);
     }
     $collection = $this->createRecordCollection($response);
     $this->injectSourceIdentifier($collection);
     return $collection;
 }
Example #3
0
 /**
  * Retrieves a document specified by the ID.
  *
  * @param string $recordId  The document to retrieve from the Primo API
  * @param string $inst_code Institution code (optional)
  *
  * @throws \Exception
  * @return string    The requested resource
  */
 public function getRecord($recordId, $inst_code = null)
 {
     list(, $recordId) = explode('.', $recordId, 2);
     return parent::getRecord($recordId, $inst_code);
 }
 /**
  * Create the Primo Central connector.
  *
  * @return Connector
  */
 protected function createConnector()
 {
     // Get the PermissionHandler
     $permHandler = $this->getPermissionHandler();
     // Load credentials and port number:
     $id = isset($this->primoConfig->General->apiId) ? $this->primoConfig->General->apiId : null;
     $port = isset($this->primoConfig->General->port) ? $this->primoConfig->General->port : 1701;
     $instCode = isset($permHandler) ? $permHandler->getInstCode() : null;
     // Build HTTP client:
     $client = $this->serviceLocator->get('VuFind\\Http')->createClient();
     $timeout = isset($this->primoConfig->General->timeout) ? $this->primoConfig->General->timeout : 30;
     $client->setOptions(['timeout' => $timeout]);
     $connector = new Connector($id, $instCode, $client, $port);
     $connector->setLogger($this->logger);
     return $connector;
 }
 /**
  * Create the Primo Central connector.
  *
  * @return Connector
  */
 protected function createConnector()
 {
     // Get the PermissionHandler
     $permHandler = $this->getPermissionHandler();
     // Load url and credentials:
     if (!isset($this->primoConfig->General->url)) {
         throw new \Exception('Missing url in Primo.ini');
     }
     $instCode = isset($permHandler) ? $permHandler->getInstCode() : null;
     // Build HTTP client:
     $client = $this->serviceLocator->get('VuFind\\Http')->createClient();
     $timeout = isset($this->primoConfig->General->timeout) ? $this->primoConfig->General->timeout : 30;
     $client->setOptions(['timeout' => $timeout]);
     $connector = new Connector($this->primoConfig->General->url, $instCode, $client);
     $connector->setLogger($this->logger);
     return $connector;
 }
Example #6
0
 /**
  * Retrieves multiple documents specified by the ID.
  *
  * @param array  $recordIds The documents to retrieve from the Primo API
  * @param string $inst_code Institution code (optional)
  * @param bool   $onCampus  Whether the user is on campus
  *
  * @throws \Exception
  * @return string    The requested resource
  */
 public function getRecords($recordIds, $inst_code = null, $onCampus = false)
 {
     $recordIds = array_map(function ($recordId) {
         list(, $recordId) = explode('.', $recordId, 2);
         return $recordId;
     }, $recordIds);
     return parent::getRecords($recordIds, $inst_code, $onCampus);
 }