Commit 47f30be4 authored by Alexandre Morin's avatar Alexandre Morin
Browse files

Merge branch 'release/2.3' into 'master'

Release/2.3

See merge request maarch/thirdPartyArchiving!45
parents f510acbf 88d7d203
<?php
/*
* Copyright (C) 2018 Maarch
*
* This file is part of bundle medona.
*
* Bundle medona is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Bundle medona is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with bundle medona. If not, see <http://www.gnu.org/licenses/>.
*/
namespace ext\thirdPartyArchiving\bundle\medona\Controller;
/**
* Acknowledgement interface
*
* @package Medona
* @author Alexis Ragot <alexis.ragot@maarch.org>
*/
interface AcknowledgementInterface
{
/**
* Send an aknowledgement
* @param mixed $receivedMessage The received message or it's identifier
*
* @return object The acknowledgement
*/
public function send($receivedMessage);
}
\ No newline at end of file
...@@ -55,19 +55,21 @@ class ArchiveDeliveryRequest extends abstractMessage ...@@ -55,19 +55,21 @@ class ArchiveDeliveryRequest extends abstractMessage
/** /**
* Get transfer history * Get transfer history
* @param string $reference *
* @param string $archiver * @param string $reference Reference
* @param string $originator * @param string $archiver Archiver
* @param string $depositor * @param string $originator Originator
* @param string $archivalAgreement * @param string $depositor Depositor
* @param date $fromDate * @param string $archivalAgreement Archival agreement
* @param date $toDate * @param date $fromDate From date
* @param date $toDate To date
* @param string $status Status
* *
* @return array Array of medona/message object * @return array Array of medona/message object
*/ */
public function history($reference = null, $archiver = null, $originator = null, $depositor = null, $archivalAgreement = null, $fromDate = null, $toDate = null) public function history($reference = null, $archiver = null, $originator = null, $depositor = null, $archivalAgreement = null, $fromDate = null, $toDate = null, $status = null)
{ {
return $this->search("ArchiveDelivery", $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate); return $this->search("ArchiveDelivery", $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate, $status);
} }
/** /**
...@@ -97,13 +99,14 @@ class ArchiveDeliveryRequest extends abstractMessage ...@@ -97,13 +99,14 @@ class ArchiveDeliveryRequest extends abstractMessage
* Deliver an archive * Deliver an archive
* @param mixed $archiveIds The identifier of archive or a list of identifiers * @param mixed $archiveIds The identifier of archive or a list of identifiers
* @param string $identifier The medona message reference * @param string $identifier The medona message reference
* @param boolean $derogation Ask for an authorization
* @param string $comment The message comment * @param string $comment The message comment
* *
* @return array Array of message * @return array Array of message
* *
* @throws \bundle\recordsManagement\Exception\notCommunicableException * @throws \bundle\recordsManagement\Exception\notCommunicableException
*/ */
public function requestDelivery($archiveIds, $identifier = null, $comment = null) public function requestDelivery($archiveIds, $identifier = null, $derogation = false, $comment = null)
{ {
$requesterOrg = \laabs::getToken('ORGANIZATION'); $requesterOrg = \laabs::getToken('ORGANIZATION');
if (!$requesterOrg) { if (!$requesterOrg) {
...@@ -128,25 +131,28 @@ class ArchiveDeliveryRequest extends abstractMessage ...@@ -128,25 +131,28 @@ class ArchiveDeliveryRequest extends abstractMessage
$archivesByOriginator[$archive->originatorOrgRegNumber][] = $archive; $archivesByOriginator[$archive->originatorOrgRegNumber][] = $archive;
} }
$counter = 0; if (!$identifier) {
$identifier = "archiveDeliveryRequest_".date("Y-m-d-H-i-s");
}
$reference = $identifier;
foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) { foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) {
$messageIdentifier = $identifier ? $identifier."_".++$counter : "archiveDeliveryRequest_".\laabs::newId(); $i = 1;
$derogation = false; $unique = array(
foreach ($archives as $archive) { 'type' => 'ArchiveDeliveryRequest',
if ($archive->accessRuleComDate) { 'senderOrgRegNumber' => $requesterOrgRegNumber,
$communicationDelay = $archive->accessRuleComDate->diff(\laabs::newTimestamp()); 'reference' => $reference,
if ($communicationDelay->invert != 0) { );
$derogation = true;
break; while ($this->sdoFactory->exists("medona/message", $unique)) {
} $i++;
} $unique['reference'] = $reference = $identifier.'_'.$i;
} }
$archiverOrgRegNumber = $archives[0]->archiverOrgRegNumber; $archiverOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$message = $this->send($messageIdentifier, $archives, $derogation, $comment, $requesterOrgRegNumber, $archiverOrgRegNumber);
$message = $this->send($reference, $archives, $derogation, $comment, $requesterOrgRegNumber, $archiverOrgRegNumber);
$messages[] = $message; $messages[] = $message;
} }
...@@ -326,7 +332,7 @@ class ArchiveDeliveryRequest extends abstractMessage ...@@ -326,7 +332,7 @@ class ArchiveDeliveryRequest extends abstractMessage
{ {
$this->changeStatus($messageId, "rejected"); $this->changeStatus($messageId, "rejected");
$archiveDeliveryRequestReplyController = \laabs::newController('medona/ArchiveDeliveryRequestReply'); //$archiveDeliveryRequestReplyController = \laabs::newController('medona/ArchiveDeliveryRequestReply');
$message = $this->sdoFactory->read('medona/message', array('messageId' => $messageId)); $message = $this->sdoFactory->read('medona/message', array('messageId' => $messageId));
...@@ -337,8 +343,6 @@ class ArchiveDeliveryRequest extends abstractMessage ...@@ -337,8 +343,6 @@ class ArchiveDeliveryRequest extends abstractMessage
$message, $message,
true true
); );
return $archiveDeliveryRequestReplyController->send($messageId, "rejected", $comment);
} }
/** /**
...@@ -353,7 +357,6 @@ class ArchiveDeliveryRequest extends abstractMessage ...@@ -353,7 +357,6 @@ class ArchiveDeliveryRequest extends abstractMessage
$messages = $this->sdoFactory->find("medona/message", "status='accepted' AND type='ArchiveDeliveryRequest' AND active=true"); $messages = $this->sdoFactory->find("medona/message", "status='accepted' AND type='ArchiveDeliveryRequest' AND active=true");
foreach ($messages as $message) { foreach ($messages as $message) {
$this->changeStatus($message->messageId, "processing"); $this->changeStatus($message->messageId, "processing");
$this->loadXmlFile($message);
$this->readOrgs($message); $this->readOrgs($message);
if (!empty($message->data)) { if (!empty($message->data)) {
......
<?php
/*
* Copyright (C) 2018 Maarch
*
* This file is part of bundle medona.
*
* Bundle medona is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Bundle medona is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with bundle medona. If not, see <http://www.gnu.org/licenses/>.
*/
namespace ext\thirdPartyArchiving\bundle\medona\Controller;
/**
* Archive delivery request interface
*
* @package Medona
* @author Alexis Ragot <alexis.ragot@maarch.org>
*/
interface ArchiveDeliveryRequestInterface
{
/**
* Send an archive delivery request
* @param Object $message The message
*/
public function send($message);
}
...@@ -80,7 +80,7 @@ class ArchiveDeliveryRequestReply extends abstractMessage ...@@ -80,7 +80,7 @@ class ArchiveDeliveryRequestReply extends abstractMessage
* *
* @return The reply message generated * @return The reply message generated
*/ */
public function send($requestMessage, $archives, $replyCode = "000", $comment = null) public function send($requestMessage, $archives = null, $replyCode = "000", $comment = null)
{ {
if (is_scalar($requestMessage)) { if (is_scalar($requestMessage)) {
$messageId = $requestMessage; $messageId = $requestMessage;
......
<?php
/*
* Copyright (C) 2018 Maarch
*
* This file is part of bundle medona.
*
* Bundle medona is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Bundle medona is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with bundle medona. If not, see <http://www.gnu.org/licenses/>.
*/
namespace ext\thirdPartyArchiving\bundle\medona\Controller;
/**
* Archive delivery request reply interface
*
* @package Medona
* @author Alexis Ragot <alexis.ragot@maarch.org>
*/
interface ArchiveDeliveryRequestReplyInterface
{
/**
* Send message with all contents embedded
* @param object $message The message
*/
public function send($message);
}
...@@ -70,18 +70,27 @@ class ArchiveDestruction ...@@ -70,18 +70,27 @@ class ArchiveDestruction
} }
$requesterOrgRegNumber = $requesterOrg->registrationNumber; $requesterOrgRegNumber = $requesterOrg->registrationNumber;
$i = 0; if (!$identifier) {
$identifier = "archiveDestructionRequest_".date("Y-m-d-H-i-s");
}
$reference = $identifier;
foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) { foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) {
$i = 1;
$recipientOrgRegNumber = $archives[0]->archiverOrgRegNumber; $recipientOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$i++;
if (!$identifier) { $unique = array(
$identifier = "archiveDestructionRequest_".\laabs::newId(); 'type' => 'ArchiveDestructionRequest',
} else { 'senderOrgRegNumber' => $requesterOrgRegNumber,
$identifier .= "_".$i; 'reference' => $reference,
);
while ($this->sdoFactory->exists("medona/message", $unique)) {
$i++;
$unique['reference'] = $reference = $identifier.'_'.$i;
} }
$archiveDestructionRequestController->send($identifier, $archives, $comment, $requesterOrgRegNumber, $recipientOrgRegNumber, $originatorOrgRegNumber); $archiveDestructionRequestController->send($reference, $archives, $comment, $requesterOrgRegNumber, $recipientOrgRegNumber, $originatorOrgRegNumber);
} }
return $archiveList; return $archiveList;
......
...@@ -48,19 +48,21 @@ class ArchiveDestructionRequest extends abstractMessage ...@@ -48,19 +48,21 @@ class ArchiveDestructionRequest extends abstractMessage
/** /**
* Get transfer history * Get transfer history
* @param string $reference *
* @param string $archiver * @param string $reference Reference
* @param string $originator * @param string $archiver Archiver
* @param string $depositor * @param string $originator Originator
* @param string $archivalAgreement * @param string $depositor Depositor
* @param date $fromDate * @param string $archivalAgreement Archival agreement
* @param date $toDate * @param date $fromDate From date
* @param date $toDate To date
* @param string $status Status
* *
* @return array Array of medona/message object * @return array Array of medona/message object
*/ */
public function history($reference = null, $archiver = null, $originator = null, $depositor = null, $archivalAgreement = null, $fromDate = null, $toDate = null) public function history($reference = null, $archiver = null, $originator = null, $depositor = null, $archivalAgreement = null, $fromDate = null, $toDate = null, $status = null)
{ {
return $this->search("ArchiveDestruction", $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate); return $this->search("ArchiveDestruction", $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate, $status);
} }
/** /**
...@@ -148,16 +150,23 @@ class ArchiveDestructionRequest extends abstractMessage ...@@ -148,16 +150,23 @@ class ArchiveDestructionRequest extends abstractMessage
$this->generate($message); $this->generate($message);
$this->save($message); $this->save($message);
} }
$operationResult = true;
$this->create($message);
} catch (\Exception $e) { } catch (\Exception $e) {
$message->status = "error"; $message->status = "error";
$operationResult = false;
$this->create($message);
throw $e; throw $e;
} }
$event = $this->lifeCycleJournalController->logEvent(
'medona/sending',
'medona/message',
$message->messageId,
$message,
$operationResult
);
$this->create($message);
$senderOrg = \laabs::getToken('ORGANIZATION'); $senderOrg = \laabs::getToken('ORGANIZATION');
// Requested by archiver: send auth request to originator // Requested by archiver: send auth request to originator
...@@ -214,6 +223,14 @@ class ArchiveDestructionRequest extends abstractMessage ...@@ -214,6 +223,14 @@ class ArchiveDestructionRequest extends abstractMessage
$message->status = "accepted"; $message->status = "accepted";
$event = $this->lifeCycleJournalController->logEvent(
'medona/acceptance',
'medona/message',
$message->messageId,
$message,
true
);
$this->sdoFactory->update($message); $this->sdoFactory->update($message);
} }
...@@ -300,8 +317,10 @@ class ArchiveDestructionRequest extends abstractMessage ...@@ -300,8 +317,10 @@ class ArchiveDestructionRequest extends abstractMessage
$message->status = "processed"; $message->status = "processed";
$message->operationDate = \laabs::newDatetime(null, "UTC"); $message->operationDate = \laabs::newDatetime(null, "UTC");
$operationResult = true;
$this->update($message); $this->update($message);
} catch (\Exception $e) { } catch (\Exception $e) {
$operationResult = false;
throw $e; throw $e;
} }
...@@ -309,6 +328,14 @@ class ArchiveDestructionRequest extends abstractMessage ...@@ -309,6 +328,14 @@ class ArchiveDestructionRequest extends abstractMessage
$this->sdoFactory->commit(); $this->sdoFactory->commit();
} }
$this->lifeCycleJournalController->logEvent(
'medona/processing',
'medona/message',
$message->messageId,
$message,
$operationResult
);
$archiveDestructionNotificationController = \laabs::newController("medona/ArchiveDestructionNotification"); $archiveDestructionNotificationController = \laabs::newController("medona/ArchiveDestructionNotification");
// TO DO : Write destruction failures in comments // TO DO : Write destruction failures in comments
......
...@@ -155,7 +155,7 @@ class ArchiveModification ...@@ -155,7 +155,7 @@ class ArchiveModification
{ {
$archives = array(); $archives = array();
foreach ($archiveIds as $archiveId) { foreach ($archiveIds as $archiveId) {
$archive = $this->archiveController->getDescription($archiveId); $archive = $this->archiveController->retrieve($archiveId);
$archives[] = $archive; $archives[] = $archive;
} }
...@@ -169,17 +169,29 @@ class ArchiveModification ...@@ -169,17 +169,29 @@ class ArchiveModification
} }
$archiveModificationNotificationController = \laabs::newController("medona/ArchiveModificationNotification"); $archiveModificationNotificationController = \laabs::newController("medona/ArchiveModificationNotification");
$i = 0;
if (!$identifier) {
$identifier = "archiveModificationNotification_".date("Y-m-d-H-i-s");
}
$reference = $identifier;
foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) { foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) {
$i = 1;
$senderOrg = $archives[0]->archiverOrgRegNumber; $senderOrg = $archives[0]->archiverOrgRegNumber;
$recipientOrg = $originatorOrgRegNumber; $recipientOrg = $originatorOrgRegNumber;
if ($identifier) {
$unique = array(
'type' => 'ArchiveModificationNotification',
'senderOrgRegNumber' => $senderOrg,
'reference' => $reference,
);
while ($this->sdoFactory->exists("medona/message", $unique)) {
$i++; $i++;
$identifier .= "_".$i; $unique['reference'] = $reference = $identifier.'_'.$i;
$message = $archiveModificationNotificationController->send((string) $identifier, $archives, $senderOrg, $recipientOrg, $comment);
} else {
$message = $archiveModificationNotificationController->send((string) \laabs::newId(), $archives, $senderOrg, $recipientOrg, $comment);
} }
$message = $archiveModificationNotificationController->send($reference, $archives, $senderOrg, $recipientOrg, $comment);
} }
} }
} }
...@@ -54,19 +54,21 @@ class ArchiveNotification extends abstractMessage ...@@ -54,19 +54,21 @@ class ArchiveNotification extends abstractMessage
/** /**
* Get transfer history * Get transfer history
* @param string $reference *
* @param string $archiver * @param string $reference Reference
* @param string $originator * @param string $archiver Archiver
* @param string $depositor * @param string $originator Originator
* @param string $archivalAgreement * @param string $depositor Depositor
* @param date $fromDate * @param string $archivalAgreement Archival agreement
* @param date $toDate * @param date $fromDate From date
* @param date $toDate To date
* @param string $status Status
* *
* @return array Array of medona/message object * @return array Array of medona/message object
*/ */
public function history($reference = null, $archiver = null, $originator = null, $depositor = null, $archivalAgreement = null, $fromDate = null, $toDate = null) public function history($reference = null, $archiver = null, $originator = null, $depositor = null, $archivalAgreement = null, $fromDate = null, $toDate = null, $status = null)
{ {
return $this->search("ArchiveNotification", $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate, false); return $this->search("ArchiveNotification", $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate, $status, false);
} }
/** /**
......
...@@ -67,19 +67,21 @@ class ArchiveRestitution extends abstractMessage ...@@ -67,19 +67,21 @@ class ArchiveRestitution extends abstractMessage
/** /**
* Get transfer history * Get transfer history
* @param string $reference *
* @param string $archiver * @param string $reference Reference
* @param string $originator * @param string $archiver Archiver
* @param string $depositor * @param string $originator Originator
* @param string $archivalAgreement * @param string $depositor Depositor
* @param date $fromDate * @param string $archivalAgreement Archival agreement
* @param date $toDate * @param date $fromDate From date
* @param date $toDate To date
* @param string $status Status
* *
* @return array Array of medona/message object * @return array Array of medona/message object
*/ */
public function history($reference = null, $archiver = null, $originator = null, $depositor = null, $archivalAgreement = null, $fromDate = null, $toDate = null) public function history($reference = null, $archiver = null, $originator = null, $depositor = null, $archivalAgreement = null, $fromDate = null, $toDate = null, $status = null)
{ {
return $this->search("ArchiveRestitution", $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate); return $this->search("ArchiveRestitution", $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate, $status);
} }
/** /**
...@@ -251,17 +253,15 @@ class ArchiveRestitution extends abstractMessage ...@@ -251,17 +253,15 @@ class ArchiveRestitution extends abstractMessage
} }
$result = array('success' => array(), 'error' => array()); $result = array('success' => array(), 'error' => array());
$counter = 0;
$archiveRestitutionRequestController = \laabs::newController("medona/ArchiveRestitutionRequest"); $archiveRestitutionRequestController = \laabs::newController("medona/ArchiveRestitutionRequest");
foreach ($archivesIdsByOriginator as $originatorOrgRegNumber => $archiveIds) { if (!$identifier) {
$communicable =