Verified Commit 472f6857 authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

Apply transformation on archives with description model other than seda for dissemination to seda2

parent bec9dfbe
......@@ -909,7 +909,7 @@ abstract class abstractMessage
return $signature;
}
public function sendArchiveContent($descriptionValue, $archiveId)
public function sendArchiveContent($descriptionObject)
{
$content = \laabs::newInstance("seda2/Content");
......@@ -984,21 +984,19 @@ abstract class abstractMessage
"signature"
];
$content->systemId = [(string) $archiveId];
if (isset($descriptionValue->systemId)) {
$content->systemId = array_merge($content->systemId, $descriptionValue->systemId);
if (isset($descriptionObject->systemId)) {
$content->systemId = array_merge($content->systemId, $descriptionObject->systemId);
}
foreach ($attributes as $attribute) {
if (isset($descriptionValue->$attribute) && !is_null($descriptionValue->$attribute)) {
if ((is_string($descriptionValue->$attribute) && trim($descriptionValue->$attribute) != '')
|| is_array($descriptionValue->$attribute)
|| is_object($descriptionValue->$attribute)) {
if ($descriptionValue->$attribute instanceof \DateTime) {
$content->$attribute = $this->sendDate($descriptionValue->$attribute);
if (isset($descriptionObject->$attribute) && !is_null($descriptionObject->$attribute)) {
if ((is_string($descriptionObject->$attribute) && trim($descriptionObject->$attribute) != '')
|| is_array($descriptionObject->$attribute)
|| is_object($descriptionObject->$attribute)) {
if ($descriptionObject->$attribute instanceof \DateTime) {
$content->$attribute = $this->sendDate($descriptionObject->$attribute);
} else {
$content->$attribute = $descriptionValue->$attribute;
$content->$attribute = $descriptionObject->$attribute;
}
if ($attribute == "descriptionLevel") {
$content->$attribute = ucfirst($content->$attribute);
......@@ -1019,40 +1017,40 @@ abstract class abstractMessage
}
foreach ($agentTypes as $agentType) {
if (isset($descriptionValue->$agentType)) {
$content->$agentType = $this->sendMultipleOfInstance($descriptionValue->$agentType, "AgentAbstract", ["name" => "Place", "instance" => "BirthOrDeathPlace"]);
if (isset($descriptionObject->$agentType)) {
$content->$agentType = $this->sendMultipleOfInstance($descriptionObject->$agentType, "AgentAbstract", ["name" => "Place", "instance" => "BirthOrDeathPlace"]);
}
}
if (isset($descriptionValue->gps)) {
$content->gps = $this->sendOneOfInstance($descriptionValue->gps, "Gps");
if (isset($descriptionObject->gps)) {
$content->gps = $this->sendOneOfInstance($descriptionObject->gps, "Gps");
}
if (isset($descriptionValue->coverage)) {
$content->coverage = $this->sendOneOfInstance($descriptionValue->coverage, "Coverage");
if (isset($descriptionObject->coverage)) {
$content->coverage = $this->sendOneOfInstance($descriptionObject->coverage, "Coverage");
}
if (isset($descriptionValue->custodialHistory)) {
$content->custodialHistory = $this->sendCustodialHistory($descriptionValue->custodialHistory);
if (isset($descriptionObject->custodialHistory)) {
$content->custodialHistory = $this->sendCustodialHistory($descriptionObject->custodialHistory);
}
if (is_null($content->custodialHistory)) {
unset($content->custodialHistory);
}
if (isset($descriptionValue->signature)) {
$content->signature = $this->sendSignature($descriptionValue->signature);
if (isset($descriptionObject->signature)) {
$content->signature = $this->sendSignature($descriptionObject->signature);
}
if (isset($descriptionValue->submissionAgency)) {
$content->submissionAgency = $this->sendOrganization($descriptionValue->submissionAgency);
if (isset($descriptionObject->submissionAgency)) {
$content->submissionAgency = $this->sendOrganization($descriptionObject->submissionAgency);
}
if (isset($descriptionValue->originatingAgency)) {
$content->originatingAgency = $this->sendOrganization($descriptionValue->originatingAgency);
if (isset($descriptionObject->originatingAgency)) {
$content->originatingAgency = $this->sendOrganization($descriptionObject->originatingAgency);
}
if (isset($descriptionValue->keyword)) {
if (isset($descriptionObject->keyword)) {
$content->keyword = [];
foreach ($descriptionValue->keyword as $keyword) {
foreach ($descriptionObject->keyword as $keyword) {
$content->keyword[] = $this->sendKeyword($keyword);
}
}
......@@ -1089,14 +1087,15 @@ abstract class abstractMessage
$archive->id = (string) $rmArchive->archiveId;
$archive->management = $this->sendManagement($rmArchive);
if ($rmArchive->descriptionClass == "archivesPubliques/content") {
if ($rmArchive->descriptionClass == "archivesPubliques/content") { // SEDA 1
$contents = $this->contentController->read($rmArchive->archiveId);
if (isset($contents) && !empty($contents)) {
foreach ($contents as $key => $content) {
$content->archivalAgencyArchiveUnitIdentifier = $rmArchive->archiverArchiveId;
$content->originatingAgencyArchiveUnitIdentifier = $rmArchive->originatorArchiveId;
$content->transferringAgencyArchiveUnitIdentifier = $rmArchive->depositorArchiveId;
$archive->content = $this->sendArchiveContent($content, $rmArchive->archiveId);
$archive->content = $this->sendArchiveContent($content);
$content->systemId = [(string) $rmArchive->archiveId];
if (!is_null($content->resId)) {
$archive->content = $this->convertToSeda2($archive->content);
}
......@@ -1109,8 +1108,14 @@ abstract class abstractMessage
}
$archive->content = $content;
}
} elseif (isset($rmArchive->description)) {
$archive->content = $this->sendArchiveContent($rmArchive->description->getValue(), $rmArchive->archiveId);
} elseif ($rmArchive->descriptionClass == "seda2") { // SEDA 2 or other description schemes
$archive->content = $this->sendArchiveContent($rmArchive->description->getValue());
$archive->content->systemId = [(string) $rmArchive->archiveId];
} elseif (isset($rmArchive->description)) { // Other description profiles
$archive->content = $this->transformDescription($rmArchive);
var_dump($archive->content);
exit;
}
$archive->dataObjectReference = $this->sendDataObjectReference($identifier);
......@@ -1157,6 +1162,45 @@ abstract class abstractMessage
return $content;
}
protected function transformDescription($rmArchive)
{
$mapping = $this->getTranformationRules($rmArchive->archivalProfileReference, 'seda2', 'outputs');
if ($mapping) {
$content = $this->applyTransformationRules($rmArchive, $mapping);
} else {
$content = (object) [];
}
$content->systemId = [(string) $rmArchive->archiveId];
return $content;
}
protected function applyTransformationRules($archiveDescription, $rules)
{
$transformationProcessor = \laabs::newService('dependency/Transformation/Processor', $rules);
return $transformationProcessor->transform($archiveDescription);
}
protected function getTranformationRules($archivalProfileReference, $namespace, $mode) {
if (empty($archivalProfileReference)) {
return;
}
$mappingFile = $this->profilesDirectory.DIRECTORY_SEPARATOR.$archivalProfileReference.'.json';
if (!is_file($mappingFile)) {
return;
}
$mapping = json_decode(file_get_contents($mappingFile));
if (!isset($mapping->{$mode}->{$namespace})) {
return;
}
return $mapping->{$mode}->{$namespace};
}
protected function sendKeyword($apKeyword)
{
$keyword = \laabs::newInstance('seda2/Keyword');
......
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