Skip to content

Commit

Permalink
Resource: checking object values - extend the test and add log messag…
Browse files Browse the repository at this point in the history
…e about updating an object value
  • Loading branch information
zozlak committed Dec 9, 2024
1 parent fe66c3d commit 3338c9d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
4 changes: 3 additions & 1 deletion config-sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ doorkeeper:
rolePublic: public
roleAcademic: academic
checkRanges:
https://vocabs.acdh.oeaw.ac.at/schema#Agent: [viaf, orcid, gnd, wikidata, arche-localhost, acdhi, arche, pmb]
https://vocabs.acdh.oeaw.ac.at/schema#Agent: [viaf, orcid, gnd, wikidata, arche-localhost, acdhi, arche, pmb, ror]
https://vocabs.acdh.oeaw.ac.at/schema#Place: [wikidata, arche-localhost, acdhi, arche, pmb, geonames]
https://vocabs.acdh.oeaw.ac.at/schema#AgentOrPlace: [viaf, orcid, gnd, wikidata, arche-localhost, acdhi, arche, pmb, geonames, ror]
# Should Doorkeeper::checkUnknownProperties() be run? We need to be able to turn it off for the ontology import.
checkUnknownProperties: true
# Should Doorkeeper::checkAutoCreatedResources() be run? We need to be able to turn it off for the ontology import.
Expand Down
4 changes: 2 additions & 2 deletions src/acdhOeaw/arche/doorkeeper/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,7 @@ private function maintainPropertyRangeLiteral(
}
}

private function verifyPropertyRangeUri(
string $rangeUri, string $prop): void {
private function verifyPropertyRangeUri(string $rangeUri, string $prop): void {
static $rangeDefs = null;
if ($rangeDefs === null) {
$rangeDefs = RC::$config->doorkeeper->checkRanges;
Expand Down Expand Up @@ -842,6 +841,7 @@ private function verifyPropertyRangeUri(
$objNorm = $norm->normalize((string) $obj);
if ($objNorm !== (string) $obj) {
$objNorm = DF::namedNode($objNorm);
$this->log?->debug("\t\tupdating object value $obj with $objNorm");
$this->meta->forEach(fn($q) => $q->withObject($objNorm), new PT($prop, $obj));
}
} catch (UriNormalizerException $ex) {
Expand Down
30 changes: 23 additions & 7 deletions tests/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use quickRdf\DatasetNode;
use termTemplates\PredicateTemplate as PT;
use termTemplates\NamedNodeTemplate as NNT;
use acdhOeaw\UriNormalizer;
use acdhOeaw\arche\lib\RepoResource;
use acdhOeaw\arche\lib\BinaryPayload;
use acdhOeaw\arche\lib\exception\NotFound;
Expand Down Expand Up @@ -993,20 +994,35 @@ public function testTechnicalProperty(): void {
}

public function testNormalizeObjectValue(): void {
$prop = 'https://vocabs.acdh.oeaw.ac.at/schema#hasActor';
$value = 'https://orcid.org/0000-0001-5853-2534/';
$class = DF::namedNode('https://vocabs.acdh.oeaw.ac.at/schema#Collection');
$meta = self::createMetadata([$prop => $value], $class);
$norm = new UriNormalizer();

$prop1 = 'https://vocabs.acdh.oeaw.ac.at/schema#hasActor';
$value1 = 'https://orcid.org/0000-0001-5853-2534/';
$prop2 = 'https://vocabs.acdh.oeaw.ac.at/schema#hasSpatialCoverage';
$value2 = 'http://www.wikidata.org/wiki/Q932005';
$vals = [
$prop1 => $value1,
$prop2 => $value2,
];
$class = DF::namedNode('https://vocabs.acdh.oeaw.ac.at/schema#Collection');
$meta = self::createMetadata($vals, $class);
self::$repo->begin();
$res = self::$repo->createResource($meta);
$ref = self::$repo->getResourceById(substr($value, 0, -1)); // normalized form
$res = self::$repo->createResource($meta);
$ref1 = self::$repo->getResourceById($norm->normalize($value1));
$ref2 = self::$repo->getResourceById($norm->normalize($value2));
try {
self::$repo->getResourceById($value);
self::$repo->getResourceById($value1);
$this->assertTrue(false);
} catch (NotFound $ex) {
$this->assertTrue(true);
}
self::$repo->rollback();
try {
self::$repo->getResourceById($value2);
$this->assertTrue(false);
} catch (NotFound $ex) {
$this->assertTrue(true);
}
}

public function testOpenAireOaipmhSet(): void {
Expand Down

0 comments on commit 3338c9d

Please sign in to comment.