VuFind API Documentation

Server
in package

OAI Server class

This class provides OAI server functionality.

Tags
category

VuFind

author

Demian Katz demian.katz@villanova.edu

author

Ere Maijala ere.maijala@helsinki.fi

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link

Wiki

Table of Contents

$adminEmail  : string
Admin email used in "Identify" response
$baseHostURL  : string
Base URL of host containing VuFind.
$baseURL  : string
Repository base URL
$core  : string
What Solr core are we serving up?
$defaultQuery  : mixed
$deleteLifetime  : int
Limit on display of deleted records (in days); older deleted records will not be returned by the server. Set to null for no limit.
$earliestDatestamp  : string
Earliest datestamp used in "Identify" response
$idNamespace  : string
Namespace used for ID prefixing (if any)
$iso8601  : string
ISO-8601 date format
$metadataFormats  : array<string|int, mixed>
Supported metadata formats
$pageSize  : int
Records per page in lists
$params  : array<string|int, mixed>
Incoming request parameters
$recordFormatFilters  : array<string|int, mixed>
Filter queries specific to the requested record format
$recordFormatter  : mixed
$recordLinkerHelper  : RecordLinker
Record link helper (optional)
$recordLoader  : Loader
$repositoryName  : string
Repository name used in "Identify" response
$resultsManager  : PluginManager
$resumptionService  : OaiResumptionServiceInterface
$searchClassId  : string
Search object class to use
$setField  : string
Solr field for set membership
$setQueries  : array<string|int, mixed>
Set queries
$trackerService  : ChangeTrackerServiceInterface
$useCursorMark  : bool
Should we use cursorMarks for Solr retrieval? Normally this is the best option, but it is incompatible with some other Solr features and may need to be disabled in rare circumstances (e.g. when using field collapsing/ result grouping).
$vufindApiFields  : array<string|int, mixed>
Fields to return when the 'vufind' format is requested. Empty array means the format is disabled.
__construct()  : mixed
Constructor
getResponse()  : string
Respond to the OAI-PMH request.
init()  : void
Initialize settings
setRecordFormatter()  : void
Add a record formatter (optional -- allows the vufind record format to be returned).
setRecordLinkerHelper()  : void
Add a record linker helper (optional -- allows enhancement of some metadata with VuFind-specific links).
attachDeleted()  : void
Assign necessary interface variables to display a deleted record.
attachNonDeleted()  : bool
Attach a non-deleted record to an XML document.
attachRecordHeader()  : void
Attach a record header to an XML document.
createResponse()  : SimpleXMLElement
Create an OAI-PMH response (shared support method used by various response-specific methods).
dateTimeCreationSuccessful()  : bool
Check if a DateTime was successfully created without errors or warnings
getMetadataFormats()  : array<string|int, mixed>
Get metadata formats; initialize the list if necessary.
getRecord()  : string
Respond to a GetRecord request.
getUTCDateTime()  : string
Get the current UTC date/time in ISO 8601 format.
getVuFindMetadata()  : string
Support method for attachNonDeleted() to build the VuFind metadata for a record driver.
hasParam()  : bool
Was the specified parameter provided?
identify()  : string
Respond to an Identify request:
initializeMetadataFormats()  : void
Initialize data about metadata formats. (This is called on demand and is defined as a separate method to allow easy override by child classes).
initializeSettings()  : void
Load data from the OAI section of config.ini. (This is called by the constructor and is only a separate method to allow easy override by child classes).
isBadDate()  : bool
Validate the from and until parameters for the listRecords method.
listMetadataFormats()  : string
Respond to a ListMetadataFormats request.
listRecords()  : string
Respond to a ListIdentifiers or ListRecords request (the $verb parameter determines the exact format of the response).
listRecordsGetDeleted()  : array<string|int, ChangeTrackerEntityInterface>
Get an object containing the next page of deleted records from the specified date range.
listRecordsGetDeletedCount()  : int
Get a count of all deleted records in the specified date range.
listRecordsGetNonDeleted()  : Results
Get an array of information on non-deleted records in the specified range.
listRecordsGetParams()  : mixed
Get parameters for use in the listRecords method.
listRecordsValidateDates()  : bool
Validate the from and until parameters for the listRecords method.
listSets()  : string
Respond to a ListSets request.
loadRecord()  : mixed
Load a specific record from the index.
loadResumptionToken()  : array<string|int, mixed>
Load parameters associated with a resumption token.
normalizeDate()  : int
Normalize a date to a Unix timestamp.
prefixID()  : string
Prepend the OAI prefix to the provided ID number.
saveResumptionToken()  : void
Generate a resumption token to continue the current operation.
showError()  : string
Display an error response.
stripID()  : string
Strip the OAI prefix from the provided ID number.
supportsVuFindMetadata()  : bool
Does the current configuration support the VuFind metadata format (using the API's record formatter.
unexpectedError()  : void
Die with an unexpected error code (when something outside the scope of OAI-PMH fails).

Properties

$adminEmail

Admin email used in "Identify" response

protected string $adminEmail

$baseHostURL

Base URL of host containing VuFind.

protected string $baseHostURL

$baseURL

Repository base URL

protected string $baseURL

$core

What Solr core are we serving up?

protected string $core = 'biblio'

$defaultQuery

protected mixed $defaultQuery = ''

$deleteLifetime

Limit on display of deleted records (in days); older deleted records will not be returned by the server. Set to null for no limit.

protected int $deleteLifetime = null

$earliestDatestamp

Earliest datestamp used in "Identify" response

protected string $earliestDatestamp = '2000-01-01T00:00:00Z'

$idNamespace

Namespace used for ID prefixing (if any)

protected string $idNamespace = null

$iso8601

ISO-8601 date format

protected string $iso8601 = 'Y-m-d\\TH:i:s\\Z'

$metadataFormats

Supported metadata formats

protected array<string|int, mixed> $metadataFormats = []

$pageSize

Records per page in lists

protected int $pageSize = 100

$params

Incoming request parameters

protected array<string|int, mixed> $params

$recordFormatFilters

Filter queries specific to the requested record format

protected array<string|int, mixed> $recordFormatFilters = []

$recordFormatter

protected mixed $recordFormatter = null

$recordLinkerHelper

Record link helper (optional)

protected RecordLinker $recordLinkerHelper = null

$repositoryName

Repository name used in "Identify" response

protected string $repositoryName = 'VuFind'

$searchClassId

Search object class to use

protected string $searchClassId = 'Solr'

$setField

Solr field for set membership

protected string $setField = null

$setQueries

Set queries

protected array<string|int, mixed> $setQueries = []

$useCursorMark

Should we use cursorMarks for Solr retrieval? Normally this is the best option, but it is incompatible with some other Solr features and may need to be disabled in rare circumstances (e.g. when using field collapsing/ result grouping).

protected bool $useCursorMark = true

$vufindApiFields

Fields to return when the 'vufind' format is requested. Empty array means the format is disabled.

protected array<string|int, mixed> $vufindApiFields = []

Methods

__construct()

Constructor

public __construct(PluginManager $resultsManager, Loader $recordLoader, ChangeTrackerServiceInterface $trackerService, OaiResumptionServiceInterface $resumptionService) : mixed
Parameters
$resultsManager : PluginManager

Search manager for retrieving records

$recordLoader : Loader

Record loader

$trackerService : ChangeTrackerServiceInterface

ChangeTracker Service

$resumptionService : OaiResumptionServiceInterface

Database service for resumption tokens

Return values
mixed

getResponse()

Respond to the OAI-PMH request.

public getResponse() : string
Return values
string

init()

Initialize settings

public init(Config $config, string $baseURL, array<string|int, mixed> $params) : void
Parameters
$config : Config

VuFind configuration

$baseURL : string

The base URL for the OAI server

$params : array<string|int, mixed>

The incoming OAI-PMH parameters (i.e. $_GET)

Return values
void

setRecordFormatter()

Add a record formatter (optional -- allows the vufind record format to be returned).

public setRecordFormatter(RecordFormatter $formatter) : void
Parameters
$formatter : RecordFormatter

Record formatter

Return values
void

setRecordLinkerHelper()

Add a record linker helper (optional -- allows enhancement of some metadata with VuFind-specific links).

public setRecordLinkerHelper(RecordLinker $helper) : void
Parameters
$helper : RecordLinker

Helper to set

Return values
void

attachDeleted()

Assign necessary interface variables to display a deleted record.

protected attachDeleted(SimpleXMLElement $xml, ChangeTrackerEntityInterface $trackerEntity[, bool $headerOnly = false ]) : void
Parameters
$xml : SimpleXMLElement

XML to update

$trackerEntity : ChangeTrackerEntityInterface

ChangeTracker entity

$headerOnly : bool = false

Only attach the header?

Return values
void

attachNonDeleted()

Attach a non-deleted record to an XML document.

protected attachNonDeleted(SimpleXMLElement $container, object $record, string $format[, bool $headerOnly = false ][, string $set = '' ]) : bool
Parameters
$container : SimpleXMLElement

XML container for new record

$record : object

A record driver object

$format : string

Metadata format to obtain (false for none)

$headerOnly : bool = false

Only attach the header?

$set : string = ''

Currently active set

Return values
bool

attachRecordHeader()

Attach a record header to an XML document.

protected attachRecordHeader(SimpleXMLElement $xml, string $id, string $date[, array<string|int, mixed> $sets = [] ][, string $status = '' ]) : void
Parameters
$xml : SimpleXMLElement

XML to update

$id : string

Record id

$date : string

Record modification date

$sets : array<string|int, mixed> = []

Set(s) containing record

$status : string = ''

Record status code

Return values
void

createResponse()

Create an OAI-PMH response (shared support method used by various response-specific methods).

protected createResponse([bool $echoParams = true ]) : SimpleXMLElement
Parameters
$echoParams : bool = true

Include params in tag?

Return values
SimpleXMLElement

dateTimeCreationSuccessful()

Check if a DateTime was successfully created without errors or warnings

protected dateTimeCreationSuccessful(DateTime|false $dt) : bool
Parameters
$dt : DateTime|false

DateTime or false (return value of createFromFormat)

Return values
bool

getMetadataFormats()

Get metadata formats; initialize the list if necessary.

protected getMetadataFormats() : array<string|int, mixed>
Return values
array<string|int, mixed>

getRecord()

Respond to a GetRecord request.

protected getRecord() : string
Return values
string

getUTCDateTime()

Get the current UTC date/time in ISO 8601 format.

protected getUTCDateTime([string $time = 'now' ]) : string
Parameters
$time : string = 'now'

Time string to represent as UTC (default = 'now')

Return values
string

getVuFindMetadata()

Support method for attachNonDeleted() to build the VuFind metadata for a record driver.

protected getVuFindMetadata(object $record) : string
Parameters
$record : object

A record driver object

Return values
string

hasParam()

Was the specified parameter provided?

protected hasParam(string $param) : bool
Parameters
$param : string

Name of the parameter to check.

Return values
bool

True if parameter is set and non-empty.

identify()

Respond to an Identify request:

protected identify() : string
Return values
string

initializeMetadataFormats()

Initialize data about metadata formats. (This is called on demand and is defined as a separate method to allow easy override by child classes).

protected initializeMetadataFormats() : void
Return values
void

initializeSettings()

Load data from the OAI section of config.ini. (This is called by the constructor and is only a separate method to allow easy override by child classes).

protected initializeSettings(Config $config) : void
Parameters
$config : Config

VuFind configuration

Return values
void

isBadDate()

Validate the from and until parameters for the listRecords method.

protected isBadDate(int $from, int $until) : bool
Parameters
$from : int

String for start date.

$until : int

String for end date.

Return values
bool

True if invalid, false if not.

listMetadataFormats()

Respond to a ListMetadataFormats request.

protected listMetadataFormats() : string
Return values
string

listRecords()

Respond to a ListIdentifiers or ListRecords request (the $verb parameter determines the exact format of the response).

protected listRecords([string $verb = 'ListRecords' ]) : string
Parameters
$verb : string = 'ListRecords'

'ListIdentifiers' or 'ListRecords'

Return values
string

listRecordsGetDeleted()

Get an object containing the next page of deleted records from the specified date range.

protected listRecordsGetDeleted(int $from, int $until, int $currentCursor) : array<string|int, ChangeTrackerEntityInterface>
Parameters
$from : int

Start date.

$until : int

End date.

$currentCursor : int

Offset into result set

Return values
array<string|int, ChangeTrackerEntityInterface>

listRecordsGetDeletedCount()

Get a count of all deleted records in the specified date range.

protected listRecordsGetDeletedCount(int $from, int $until) : int
Parameters
$from : int

Start date.

$until : int

End date.

Return values
int

listRecordsGetNonDeleted()

Get an array of information on non-deleted records in the specified range.

protected listRecordsGetNonDeleted(int $from, int $until, mixed $offset, int $limit, string $format[, string $set = '' ]) : Results
Parameters
$from : int

Start date.

$until : int

End date.

$offset : mixed

Solr offset, or cursorMark for the position in the full result list (depending on settings).

$limit : int

Max number of full records to return.

$format : string

Requested record format

$set : string = ''

Set to limit to (empty string for none).

Return values
Results

Search result object.

listRecordsGetParams()

Get parameters for use in the listRecords method.

protected listRecordsGetParams() : mixed
Tags
throws
Exception
Return values
mixed

Array of parameters or false on error

listRecordsValidateDates()

Validate the from and until parameters for the listRecords method.

protected listRecordsValidateDates(int $from, int $until) : bool
Parameters
$from : int

Timestamp for start date.

$until : int

Timestamp for end date.

Return values
bool

True if valid, false if not.

listSets()

Respond to a ListSets request.

protected listSets() : string
Return values
string

loadRecord()

Load a specific record from the index.

protected loadRecord(string $id) : mixed
Parameters
$id : string

The record ID to load

Return values
mixed

The record array (if successful) or false

loadResumptionToken()

Load parameters associated with a resumption token.

protected loadResumptionToken(string $token) : array<string|int, mixed>
Parameters
$token : string

The resumption token to look up

Return values
array<string|int, mixed>

Parameters associated with token

normalizeDate()

Normalize a date to a Unix timestamp.

protected normalizeDate(string $date[, string $time = '00:00:00' ]) : int
Parameters
$date : string

Date (ISO-8601 or YYYY-MM-DD HH:MM:SS)

$time : string = '00:00:00'

Default time to use if $date has no time attached

Return values
int

Unix timestamp (or false if $date invalid)

prefixID()

Prepend the OAI prefix to the provided ID number.

protected prefixID(string $id) : string
Parameters
$id : string

The ID to update.

Return values
string

The prefixed ID.

saveResumptionToken()

Generate a resumption token to continue the current operation.

protected saveResumptionToken(SimpleXMLElement $xml, array<string|int, mixed> $params, int $currentCursor, int $listSize, string $cursorMark) : void
Parameters
$xml : SimpleXMLElement

XML document to update with token.

$params : array<string|int, mixed>

Current operational parameters.

$currentCursor : int

Current cursor position in search results.

$listSize : int

Total size of search results.

$cursorMark : string

cursorMark for the position in the full results list.

Return values
void

showError()

Display an error response.

protected showError(string $code, string $message) : string
Parameters
$code : string

The error code to display

$message : string

The error string to display

Return values
string

stripID()

Strip the OAI prefix from the provided ID number.

protected stripID(string $id) : string
Parameters
$id : string

The ID to strip.

Return values
string

The stripped ID (false if prefix invalid).

supportsVuFindMetadata()

Does the current configuration support the VuFind metadata format (using the API's record formatter.

protected supportsVuFindMetadata() : bool
Return values
bool

unexpectedError()

Die with an unexpected error code (when something outside the scope of OAI-PMH fails).

protected unexpectedError(string $msg) : void
Parameters
$msg : string

Error message

Tags
throws
Exception
Return values
void

Search results