Skip to content

Commit

Permalink
Support specificUse in DataReference
Browse files Browse the repository at this point in the history
  • Loading branch information
LinaKind committed Jan 15, 2025
1 parent f480068 commit 1947bcf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/Model/Reference/DataReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class DataReference implements Reference, HasDoi
private $source;
private $dataId;
private $assigningAuthority;
private $specificUse;
private $doi;
private $uri;

Expand All @@ -43,6 +44,7 @@ public function __construct(
string $source,
string $dataId = null,
Place $assigningAuthority = null,
string $specificUse = null,
string $doi = null,
string $uri = null
) {
Expand All @@ -59,6 +61,7 @@ public function __construct(
$this->source = $source;
$this->dataId = $dataId;
$this->assigningAuthority = $assigningAuthority;
$this->specificUse = $specificUse;
$this->doi = $doi;
$this->uri = $uri;
}
Expand Down Expand Up @@ -143,6 +146,14 @@ public function getAssigningAuthority()
return $this->assigningAuthority;
}

/**
* @return string|null
*/
public function getSpecificUse()
{
return $this->specificUse;
}

/**
* @return string|null
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Serializer/Reference/DataReferenceNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function denormalize($data, $class, $format = null, array $context = [])
$data['dataId'] ?? null,
empty($data['assigningAuthority']) ? null : $this->denormalizer->denormalize($data['assigningAuthority'],
Place::class, $format, $context),
$data['specificUse'] ?? null,
$data['doi'] ?? null,
$data['uri'] ?? null
);
Expand Down Expand Up @@ -111,6 +112,10 @@ public function normalize($object, $format = null, array $context = []) : array
$context);
}

if ($object->getSpecificUse()) {
$data['specificUse'] = $object->getSpecificUse();
}

if ($object->getDoi()) {
$data['doi'] = $object->getDoi();
}
Expand Down
4 changes: 2 additions & 2 deletions test/Model/Reference/DataReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function it_may_have_a_doi()
{
$with = new DataReference('id', new Date(2000), null,
[new PersonAuthor(new PersonDetails('preferred name', 'index name'))], false, [], false, [], false, 'title',
'source', null, null, '10.1000/182');
'source', null, null, null, '10.1000/182');
$withOut = new DataReference('id', new Date(2000), null,
[new PersonAuthor(new PersonDetails('preferred name', 'index name'))], false, [], false, [], false, 'title',
'source');
Expand All @@ -241,7 +241,7 @@ public function it_may_have_a_uri()
{
$with = new DataReference('id', new Date(2000), null,
[new PersonAuthor(new PersonDetails('preferred name', 'index name'))], false, [], false, [], false, 'title',
'source', null, null, null, 'http://www.example.com/');
'source', null, null, null, null, 'http://www.example.com/');
$withOut = new DataReference('id', new Date(2000), null,
[new PersonAuthor(new PersonDetails('preferred name', 'index name'))], false, [], false, [], false, 'title',
'source');
Expand Down
9 changes: 6 additions & 3 deletions test/Serializer/Reference/DataReferenceNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function normalizeProvider() : array
[new PersonAuthor(new PersonDetails('curator preferred name', 'curator index name'))], true,
'title',
'source', 'id', new Place(['assigning authority']),
// 'analyzed',
'analyzed',
'10.1000/182',
'http://www.example.com/'),
[
Expand Down Expand Up @@ -132,7 +132,7 @@ public function normalizeProvider() : array
'assigning authority',
],
],
// 'specificUse' => 'analyzed',
'specificUse' => 'analyzed',
'doi' => '10.1000/182',
'uri' => 'http://www.example.com/',
],
Expand Down Expand Up @@ -244,6 +244,7 @@ public function denormalizeProvider() : array
'assigning authority',
],
],
'specificUse' => 'analyzed',
'doi' => '10.1000/182',
'uri' => 'http://www.example.com/',
],
Expand All @@ -252,7 +253,9 @@ public function denormalizeProvider() : array
[new PersonAuthor(new PersonDetails('compiler preferred name', 'compiler index name'))], true,
[new PersonAuthor(new PersonDetails('curator preferred name', 'curator index name'))], true,
'title',
'source', 'id', new Place(['assigning authority']), '10.1000/182',
'source', 'id', new Place(['assigning authority']),
'analyzed',
'10.1000/182',
'http://www.example.com/'),
],
'minimum' => [
Expand Down

0 comments on commit 1947bcf

Please sign in to comment.