Verified Commit 268afd0b authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

merge

parent 24ef6f39
......@@ -341,7 +341,6 @@ 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->loadXmlFile($message);
$this->readOrgs($message);
if (!empty($message->data)) {
......
......@@ -207,7 +207,6 @@ class ArchiveRestitutionRequest extends abstractMessage
*/
public function sendFromRequestMessage($reference, $requestMessage)
{
$this->loadXmlFile($requestMessage);
$this->readOrgs($requestMessage);
$message = \laabs::newInstance('medona/message');
......
......@@ -161,6 +161,19 @@ class ArchiveTransfer extends abstractMessage
}
}
$contentType = $finfo->file($message->path);
if ($contentType == 'application/xml') {
$xml = new \DOMDocument();
$xml->load($message->path);
$messageNamespace = $xml->documentElement->namespaceURI;
if (!$messageSchema = \laabs::resolveXmlNamespace($messageNamespace)) {
throw \laabs::newException('medona/invalidMessageException', "Unknown message namespace'.$messageNamespace", 400);
}
$message->schema = $messageSchema;
} else {
$message->schema = 'recordsManagement';
}
try {
$archiveTransferController = \laabs::newController($message->schema. '/ArchiveTransfer');
$archiveTransferController->receive($message, $attachments);
......@@ -361,8 +374,6 @@ class ArchiveTransfer extends abstractMessage
$message = $this->sdoFactory->read('medona/message', $messageId);
$this->loadData($message);
$this->loadXmlFile($message);
if ($message->status == "error") {
$this->sendError('104', "The message is in error status");
$exception = \laabs::newException('medona/invalidMessageException', "Invalid message", 400);
......@@ -464,8 +475,6 @@ class ArchiveTransfer extends abstractMessage
$message = $this->sdoFactory->read('medona/message', $messageId);
$this->loadData($message);
$this->loadXmlFile($message);
try {
$this->validateMessageHeaders($message);
......@@ -704,7 +713,6 @@ class ArchiveTransfer extends abstractMessage
$message = $this->read($messageId);
$this->loadData($message);
$this->loadXmlFile($message);
} else {
$message = $messageId;
}
......
......@@ -48,30 +48,6 @@ abstract class abstractMessage extends message
$message->xPath->registerNamespace('digitalResource', 'maarch.org:laabs:digitalResource');
}
protected function sendMessage($message)
{
$messageObject = \laabs::newInstance('medona/'.$message->type);
$messageObject->id = (string) $message->messageId;
$messageObject->comment = $message->comment;
$messageObject->date = $message->date;
$messageObject->messageIdentifier = \laabs::newInstance('medona/Identifier', $message->reference);
return $messageObject;
}
protected function sendReplyCode($code)
{
$replyCode = \laabs::newInstance('medona/Code', $code);
$replyCode->name = $this->getReplyMessage($code);
return $replyCode;
}
protected function sendError($code, $message = false, $variable = null)
{
if ($message) {
......
......@@ -148,103 +148,13 @@ class message
*/
public function loadData($message, $filename = null)
{
$this->loadXmlFile($message);
$this->readOrgs($message);
if (!empty($message->data)) {
$message->object = json_decode($message->data);
if (isset($message->object->dataObjectPackage->descriptiveMetadata)
&& isset($message->object->dataObjectPackage->descriptiveMetadata->descriptiveMetadataClass)
&& $message->object->dataObjectPackage->descriptiveMetadataClass == 'medona/archivePackage'
&& is_object($message->object->dataObjectPackage->descriptiveMetadata->archive)) {
$message->object->dataObjectPackage->descriptiveMetadata->archive = get_object_vars($message->object->dataObjectPackage->descriptiveMetadata->archive);
}
}
}
/**
* Load file
* @param medona/message $message The medona message object
* @param string $filename The path to a message xml file
*
* @return object The Xml document
*/
public function loadXmlFile($message, $filename = null)
{
if (!$filename) {
$filename = $this->messageDirectory.DIRECTORY_SEPARATOR.(string) $message->messageId.DIRECTORY_SEPARATOR.(string) $message->messageId.'.xml';
}
if (is_file($filename)) {
$message->xml = \laabs::newService('dependency/xml/Document');
$message->xml->load($filename);
$message->xPath = new \DOMXPath($message->xml);
$message->xPath->registerNamespace('medona', 'org:afnor:medona:1.0');
if (!isset($message->schema)) {
$this->getMessageSchema($message);
}
$message->xml->uri = $filename;
}
}
/**
* Load string
* @param medona/message $message The medona message object
* @param string $contents The xml contents of a message xml file
*
* @return object The Xml document
*/
public function loadXml($message, $contents = null)
{
if (!$contents) {
$contents = file_get_contents($this->messageDirectory.DIRECTORY_SEPARATOR.(string) $message->messageId.DIRECTORY_SEPARATOR.(string) $message->messageId.'.xml');
}
$message->xml = \laabs::newService('dependency/xml/Document');
libxml_use_internal_errors(true);
$valid = $message->xml->loadXml($contents);
if ($valid == false) {
foreach (libxml_get_errors() as $error) {
$this->sendError('101', $error->message);
}
libxml_clear_errors();
libxml_use_internal_errors(false);
$this->lifeCycleJournalController->logEvent(
'medona/reception',
'medona/message',
$message->messageId,
$message,
false
);
$exception = \laabs::newException('medona/invalidMessageException', "Malformed XML", 400);
$exception->errors = $this->errors;
throw $exception;
} else {
libxml_use_internal_errors(false);
$message->xPath = new \DOMXPath($message->xml);
$message->xPath->registerNamespace('medona', 'org:afnor:medona:1.0');
if (!isset($message->schema)) {
$this->getMessageSchema($message);
}
$message->xml->uri = $this->messageDirectory.DIRECTORY_SEPARATOR.(string) $message->messageId.DIRECTORY_SEPARATOR.(string) $message->messageId.'.xml';
}
}
/**
* Get processed archive history message
* @param string $type
......
......@@ -125,8 +125,6 @@ abstract class abstractBusinessMessage extends abstractMessage
*/
public function viewDataObjectPackage($message)
{
$this->loadMessage($message);
$dataObjectPackageElement = $this->message->xPath->query("medona:DataObjectPackage")->item(0);
$xsltProcessor = new \XsltProcessor();
......
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