Verified Commit 59060842 authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

Add transformation engine WIP

parent 19052a6b
Pipeline #14813 failed with stages
in 33 seconds
...@@ -1015,6 +1015,15 @@ class ArchiveTransfer extends abstractMessage ...@@ -1015,6 +1015,15 @@ class ArchiveTransfer extends abstractMessage
$archive->originatorOwnerOrgId = $originatorOrg->ownerOrgId; $archive->originatorOwnerOrgId = $originatorOrg->ownerOrgId;
$mapping = $this->getInputTranformationRules($archive, $namespace);
if ($mapping) {
$this->applyTransformationRules($archive->descriptionObject, $mapping, $archive);
}
var_dump($mapping);
var_dump($archive);
exit;
if (!empty($archive->archiveUnitProfile)) { if (!empty($archive->archiveUnitProfile)) {
$this->archiveController->completeArchivalProfileCodes($archive); $this->archiveController->completeArchivalProfileCodes($archive);
} }
...@@ -1097,6 +1106,54 @@ class ArchiveTransfer extends abstractMessage ...@@ -1097,6 +1106,54 @@ class ArchiveTransfer extends abstractMessage
return (string) $replyMessage->messageId; return (string) $replyMessage->messageId;
} }
protected function getInputTranformationRules($archive, $namespace) {
if (empty($archive->archivalProfileReference)) {
return;
}
$mappingFile = $this->profilesDirectory.DIRECTORY_SEPARATOR.$archive->archivalProfileReference.'.json';
if (!is_file($mappingFile)) {
return;
}
$mapping = json_decode(file_get_contents($mappingFile));
if (!isset($mapping->inputs->{$namespace})) {
return;
}
return $mapping->inputs->{$namespace};
}
protected function applyTransformationRules($source, $rules, $target = null)
{
$jsonPath = \laabs::newService('dependency/json/Jsonpath', $source);
if (!$target) {
$target = (object) [];
}
foreach ($rules as $name => $rule) {
if (is_object($rule)) {
$target->{$name} = $this->applyTransformationRules($source, $rule);
} elseif (is_array($rule)) {
$results = [];
foreach ($rule as $subrule) {
$subpath = '$.'.$subrule;
$results = array_merge($results, $jsonPath->query($subpath));
}
$target->{$name} = array_values($results);
} else {
$path = '$.'.$rule;
$results = $jsonPath->query($path);
if (count($results)) {
$target->{$name} = reset($results);
}
}
}
return $target;
}
protected function generateId($archive) protected function generateId($archive)
{ {
if (!isset(\laabs::configuration('recordsManagement')['archiveIdGenerator']) || empty(\laabs::configuration('recordsManagement')['archiveIdGenerator'])) { if (!isset(\laabs::configuration('recordsManagement')['archiveIdGenerator']) || empty(\laabs::configuration('recordsManagement')['archiveIdGenerator'])) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment