Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions conf/recordmanager.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ strip_prefixes[] = 'http://id.loc.gov/vocabulary/relators/'
;secondary_author_relators = "D01,D02,E01,F01,F02"
;corporate_author_relators = ""

[LidoRecord]
; The following setting can be used to override the default types for thumbnail image indexing
;thumbnail_type_labels = "image_small,image_thumb,image_medium"

; The following section contains default mapping file definitions. Key is the field
; name and value is the mapping file name in mappings directory.
[Default Mappings]
Expand Down
54 changes: 52 additions & 2 deletions src/RecordManager/Base/Record/Lido.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
namespace RecordManager\Base\Record;

use RecordManager\Base\Database\DatabaseInterface as Database;
use RecordManager\Base\Utils\Logger;
use RecordManager\Base\Utils\MetadataUtils;

use function in_array;
use function is_string;
Expand Down Expand Up @@ -176,6 +178,44 @@ class Lido extends AbstractRecord
'is_hierarchy_title', 'hierarchy_parent_title', 'hierarchy_top_title', 'title_in_hierarchy',
];

/**
* LIDO thumbnail image types
*
* @see http://terminology.lido-schema.org/lido00451
* @var array
*/
protected array $thumbnailImageTypes = [
'preview image',
'image overview',
'image preview',
'image_medium',
'thumbnail',
'vorschau bild',
'bildvorschau',
'miniaturbild',
'vorschaubild',
];

/**
* Constructor
*
* @param array $config Main configuration
* @param array $dataSourceConfig Data source settings
* @param Logger $logger Logger
* @param MetadataUtils $metadataUtils Metadata utilities
*/
public function __construct(
array $config,
array $dataSourceConfig,
Logger $logger,
MetadataUtils $metadataUtils
) {
parent::__construct($config, $dataSourceConfig, $logger, $metadataUtils);
if ($thumbnailTypeLabels = $config['LidoRecord']['thumbnail_type_labels'] ?? '') {
$this->thumbnailImageTypes = explode(',', $thumbnailTypeLabels);
}
}

/**
* Set record data
*
Expand Down Expand Up @@ -1551,8 +1591,18 @@ protected function getGeographicFacets()
protected function getThumbnailUrl(): string
{
// thumbnail field is not multivalued, so just store take the first one:
$urls = $this->getUrls();
return $urls[0] ?? '';
foreach ($this->getResourceSetNodes() as $set) {
foreach ($this->xmlDoc->all($set, 'resourceRepresentation') as $node) {
$urlType = mb_strtolower($this->xmlDoc->attr($node, 'type'));
if (!in_array($urlType, $this->thumbnailImageTypes)) {
continue;
}
if ($url = $this->xmlDoc->firstValue($node, 'linkResource')) {
return $url;
}
}
}
return '';
}

/**
Expand Down
89 changes: 89 additions & 0 deletions tests/RecordManagerTest/Base/Record/LidoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,93 @@ public function testLidoRootElementHandling(string $input, string $expected): vo
$record = $this->createRecordFromString($prolog . $input, Lido::class);
$this->assertXmlStringEqualsXmlString($prolog . $expected, $record->toXML());
}

/**
* LIDO thumbnail data provider
*
* @return \Iterator
*/
public static function lidoThumbnailDataProvider(): \Iterator
{
yield 'Type Preview image' => [
'Preview image',
'http://url.it/1',
'http://url.it/1',
];
yield 'Type image overview' => [
'image overview',
'http://url.it/2',
'http://url.it/2',
];
yield 'Type Image preview' => [
'Image preview',
'http://url.it/3',
'http://url.it/3',
];
yield 'Type image_medium' => [
'image_medium',
'http://url.it/4',
'http://url.it/4',
];
yield 'Type thumbnail' => [
'thumbnail',
'http://url.it/5',
'http://url.it/5',
];
yield 'Type image_large' => [
'image_large',
'http://url.it/6',
'',
];
yield 'Type custom image_thumb' => [
'image_thumb',
'http://url.it/7',
'http://url.it/7',
[
'LidoRecord' => [
'thumbnail_type_labels' => 'image_thumb,image_very_small',
],
],
];
yield 'Type custom image_very_small' => [
'image_very_small',
'http://url.it/8',
'http://url.it/8',
[
'LidoRecord' => [
'thumbnail_type_labels' => 'image_thumb,image_very_small',
],
],
];
}

/**
* Test LIDO thumbnail indexing
*
* @param string $type ResourceRepresentation type
* @param string $url LinkResource url
* @param string $expected Expected result
* @param array $config Main config
*
* @return void
*/
#[\PHPUnit\Framework\Attributes\DataProvider('lidoThumbnailDataProvider')]
public function testLidoThumbnailIndexing(
string $type,
string $url,
string $expected,
array $config = []
) {
$fixture = $this->getFixture('record/lido4.xml');
$fixture = str_replace(['%%type%%', '%%url%%'], [$type, $url], $fixture);

$record = $this->createRecordFromString(
$fixture,
Lido::class,
config: $config
);

$data = $record->toSolrArray();
$this->assertEquals($expected, $data['thumbnail']);
}
}
98 changes: 98 additions & 0 deletions tests/fixtures/Base/record/lido4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0"?>
<lidoWrap schemaLocation="http://www.lido-schema.org http://www.lido-schema.org/schema/v1.0/lido-v1.0.xsd">
<lido>
<lidoRecID type="Test">12345</lidoRecID>
<descriptiveMetadata lang="en">
<objectClassificationWrap>
<objectWorkTypeWrap>
<objectWorkType>
<term>Kirja</term>
</objectWorkType>
</objectWorkTypeWrap>
</objectClassificationWrap>
<objectIdentificationWrap>
<titleWrap>
<titleSet>
<appellationValue>Kitchen tool</appellationValue>
<appellationValue>Scissors</appellationValue>
</titleSet>
<titleSet>
<appellationValue pref="alternate" lang="fi">Sakset</appellationValue>
<appellationValue pref="preferred" lang="fi">Keittiövälineet</appellationValue>
</titleSet>
</titleWrap>
<inscriptionsWrap/>
</objectIdentificationWrap>
</descriptiveMetadata>
<administrativeMetadata lang="en">
<rightsWorkWrap>
<rightsWorkSet>
<rightsHolder>
<legalBodyName>
<appellationValue>Maaseudun Sivistysliito</appellationValue>
</legalBodyName>
</rightsHolder>
</rightsWorkSet>
</rightsWorkWrap>
<recordWrap>
<recordID type="local">10754</recordID>
<recordType>
<term lang="en">Audiovisual</term>
</recordType>
</recordWrap>
<resourceWrap>
<resourceSet>
<resourceID type="url">urn:msl:10</resourceID>
<rightsResource>
<rightsType>
<conceptID type="Copyright">InC</conceptID>
<term lang="en">Copyright text for resource</term>
</rightsType>
<rightsHolder>
<legalBodyName>
<appellationValue/>
</legalBodyName>
</rightsHolder>
</rightsResource>
<resourceRepresentation type="preview_video">
<linkResource formatResource="text/html">http://link.to.a/video123</linkResource>
</resourceRepresentation>
</resourceSet>
<resourceSet>
<resourceID type="url">urn:msl:7</resourceID>
<rightsResource>
<rightsType>
<conceptID type="Copyright">InC</conceptID>
<term lang="en">Copyright text for resource</term>
</rightsType>
<rightsHolder>
<legalBodyName>
<appellationValue/>
</legalBodyName>
</rightsHolder>
</rightsResource>
<resourceRepresentation type="preview_audio">
<linkResource formatResource="wav">http://link.to.an/audio123</linkResource>
</resourceRepresentation>
</resourceSet>
<resourceSet>
<resourceID type="url">urn:msl:7</resourceID>
<rightsResource>
<rightsType>
<conceptID type="Copyright">InC</conceptID>
<term lang="en">Copyright text for resource</term>
</rightsType>
<rightsHolder>
<legalBodyName>
<appellationValue/>
</legalBodyName>
</rightsHolder>
</rightsResource>
<resourceRepresentation type="%%type%%">
<linkResource formatResource="jpg">%%url%%</linkResource>
</resourceRepresentation>
</resourceSet>
</resourceWrap>
</administrativeMetadata>
</lido>
</lidoWrap>
Loading