Verified Commit 393f596a authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

Complete delivery without derogation

To do : complete data contract for descriptiveMetadata/archiveUnit
parent 8ed924fe
......@@ -327,7 +327,7 @@ class ArchiveDeliveryRequest extends abstractMessage
$messages = $this->sdoFactory->find("medona/message", "status='accepted' AND type='ArchiveDeliveryRequest' AND active=true");
foreach ($messages as $message) {
$this->changeStatus($message->messageId, "processing");
//$this->changeStatus($message->messageId, "processing");
$this->readOrgs($message);
if (!empty($message->data)) {
......@@ -361,11 +361,11 @@ class ArchiveDeliveryRequest extends abstractMessage
$message->unitIdentifier = $this->sdoFactory->readChildren("medona/unitIdentifier", $message);
}
$this->changeStatus($message->messageId, "processing");
//$this->changeStatus($message->messageId, "processing");
$archives = array();
foreach ((array) $message->unitIdentifier as $unitIdentifier) {
$archives[] = $this->archiveController->communicate($unitIdentifier->objectId);
$archives[] = $this->archiveController->communicate((string) $unitIdentifier->objectId);
}
$logMessage = ["message" => "%s archives are communicated", "variables"=> count($archives)];
......
......@@ -127,19 +127,9 @@ class ArchiveDeliveryRequestReply extends abstractMessage
try {
mkdir($this->messageDirectory.DIRECTORY_SEPARATOR.(string) $message->messageId, 0777, true);
if ($message->schema != 'medona') {
$archiveDeliveryRequestReplyController = \laabs::newController($message->schema.'/ArchiveDeliveryRequestReply');
$archiveDeliveryRequestReplyController->send($message);
} else {
$archiveDeliveryRequestReply = $this->sendMessage($message);
$message->object = $archiveDeliveryRequestReply;
$archiveDeliveryRequestReply->requester = $this->sendOrganization($message->senderOrg);
$archiveDeliveryRequestReply->archivalAgency = $this->sendOrganization($message->recipientOrg);
$this->generate($message);
$this->save($message);
}
$archiveDeliveryRequestReplyController = \laabs::newController($message->schema.'/ArchiveDeliveryRequestReply');
$archiveDeliveryRequestReplyController->send($message);
$operationResult = true;
} catch (\Exception $e) {
$message->status = "invalid";
......
......@@ -49,6 +49,77 @@ abstract class AbstractDissemination
$this->lifeCycleController = \laabs::newController("lifeCycle/journal");
}
public function validateSchema($message)
{
// todo : validation json schema
}
protected function sendArchive($archive, $dataObjectPackage, $withData=false)
{
$archiveUnit = \laabs::newMessage('recordsManagement/ArchiveUnit');
$archiveUnit->managementMetadata = \laabs::newMessage('recordsManagement/ManagementMetadata');
$archiveUnit->dataObjects = [];
$archiveUnit->archiveUnit = [];
foreach ($archive->digitalResources as $digitalResource) {
$binaryDataObject = \laabs::newInstance('medona/BinaryDataObject');
$archiveUnit->dataObjects[] = (string) $digitalResource->resId;
$dataObjectPackage->binaryDataObject[(string) $digitalResource->resId] = $binaryDataObject;
$binaryDataObject->id = $digitalResource->resId;
$binaryDataObject->attachment = \laabs::newInstance('medona/BinaryObject');
if ($digitalResource->fileName) {
$filename = $digitalResource->fileName;
} else {
$filename = $digitalResource->resId;
if (isset($digitalResource->fileExtension)) {
$filename .= ".".$digitalResource->fileExtension;
}
}
$illegal = array_merge(array_map('chr', range(0, 31)), array("<", ">", ":", '"', "|", "?", "*", ".."));
$filename = str_replace($illegal, "_", $filename);
$binaryDataObject->attachment->filename = $filename;
$binaryDataObject->format = $digitalResource->puid;
$binaryDataObject->messageDigest = \laabs::newInstance('medona/MessageDigest', $digitalResource->hash, $digitalResource->hashAlgorithm);
$binaryDataObject->size = $digitalResource->size;
}
$archiveUnit->archiveName = $archive->archiveName;
$archiveUnit->originatorArchiveId = $archive->originatorArchiveId;
$archiveUnit->archiverArchiveId = $archive->archiverArchiveId;
$archiveUnit->depositorArchiveId = $archive->depositorArchiveId;
$archiveUnit->originatingSystemId = $archive->archiveId;
$archiveUnit->originatorId = $archive->originatorOrgRegNumber;
$archiveUnit->archiveType = $archive->fileplanLevel;
$archiveUnit->descriptionObject = $archive->descriptionObject;
$archiveUnit->originatingDate = $archive->originatingDate;
$archiveUnit->managementMetadata->archivalProfile = $archive->archivalProfileReference;
$archiveUnit->managementMetadata->serviceLevel = $archive->serviceLevelReference;
if (isset($archive->retentionRuleCode)) {
$appraisalRule = \laabs::newMessage('recordsManagement/AppraisalRule');
$archiveUnit->managementMetadata->appraisalRule = $appraisalRule;
$appraisalRule->code = $archive->finalDisposition;
$appraisalRule->duration = $archive->retentionDuration;
$appraisalRule->startDate = $archive->retentionStartDate;
}
if (!empty($archive->childrenArchives)) {
foreach ($archive->childrenArchives as $childArchive) {
$archiveUnit->archiveUnit[] = $this->sendArchive($childArchive);
}
}
return $archiveUnit;
}
protected function sendJson($message, $withData)
{
$message->json = json_encode($message->object);
......@@ -66,15 +137,10 @@ abstract class AbstractDissemination
}
}
$message->path = $this->messageDirectory.DIRECTORY_SEPARATOR.$message->messageId.DIRECTORY_SEPARATOR.$message->messageId.'.xml';
$message->path = $this->messageDirectory.DIRECTORY_SEPARATOR.$message->messageId.DIRECTORY_SEPARATOR.$message->messageId.'.json';
file_put_contents($message->path, $message->json);
}
public function validateSchema($message)
{
// todo : validation json schema
}
protected function sendArchiveData($rmArchive, $message)
{
$outdir = $this->messageDirectory.DIRECTORY_SEPARATOR.$message->messageId;
......@@ -92,6 +158,8 @@ abstract class AbstractDissemination
$filename .= ".".$digitalResource->fileExtension;
}
}
$illegal = array_merge(array_map('chr', range(0, 31)), array("<", ">", ":", '"', "|", "?", "*", ".."));
$filename = str_replace($illegal, "_", $filename);
file_put_contents($outdir.DIRECTORY_SEPARATOR.$filename, $contents);
$this->sendRelatedResource($digitalResource, $outdir);
......@@ -123,7 +191,7 @@ abstract class AbstractDissemination
{
$replyCode = \laabs::newInstance('medona/Code', $code);
$replyCode->name = $this->getReplyMessage($code);
$replyCode->name = '';//$this->getReplyMessage($code);
return $replyCode;
}
......
......@@ -50,18 +50,13 @@ class ArchiveDeliveryRequestReply extends AbstractDissemination implements \ext\
$archiveDeliveryRequestReply->archivalAgency = $this->sendOrganization($message->senderOrg);
$archiveDeliveryRequestReply->requester = $this->sendOrganization($message->recipientOrg);
foreach ($message->archive as $archive) {
$unitIdentifier = \laabs::newInstance('medona/Identifier');
$unitIdentifier->value = $archive->archiveId;
$unitIdentifier->schemeName = 'ArchivalAgencyArchiveIdentifier';
$archive->lifeCycleEvent = $this->lifeCyclejournalController->getEvents((string) $archive->archiveId, $archive->depositDate);
$archive = $this->sendArchive($archive, $withAttachment = true);
$archiveDeliveryRequestReply->dataObjectPackage = \laabs::newInstance('medona/DataObjectPackage');
$archiveDeliveryRequestReply->dataObjectPackage->descriptiveMetadata = [];
$archiveDeliveryRequestReply->archive[] = $archive;
$archiveDeliveryRequestReply->unitIdentifier[] = $unitIdentifier;
foreach ($message->archive as $archive) {
$archiveDeliveryRequestReply->dataObjectPackage->descriptiveMetadata[] = $this->sendArchive($archive, $archiveDeliveryRequestReply->dataObjectPackage, $parent = false, $withAttachment = true);
}
//$this->sendXml($message, $withData = true);
$this->sendJson($message, $withData = true);
}
}
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