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
/**
* Get transfer history
* @param string $reference
* @param string $archiver
* @param string $originator
* @param string $depositor
* @param string $archivalAgreement
* @param date $fromDate
* @param date $toDate
*
* @param string $reference Reference
* @param string $archiver Archiver
* @param string $originator Originator
* @param string $depositor Depositor
* @param string $archivalAgreement Archival agreement
* @param date $fromDate From date
* @param date $toDate To date
* @param string $status Status
*
* @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
* Deliver an archive
* @param mixed $archiveIds The identifier of archive or a list of identifiers
* @param string $identifier The medona message reference
* @param boolean $derogation Ask for an authorization
* @param string $comment The message comment
*
* @return array Array of message
*
* @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');
if (!$requesterOrg) {
......@@ -128,25 +131,28 @@ class ArchiveDeliveryRequest extends abstractMessage
$archivesByOriginator[$archive->originatorOrgRegNumber][] = $archive;
}
$counter = 0;
if (!$identifier) {
$identifier = "archiveDeliveryRequest_".date("Y-m-d-H-i-s");
}
$reference = $identifier;
foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) {
$messageIdentifier = $identifier ? $identifier."_".++$counter : "archiveDeliveryRequest_".\laabs::newId();
$i = 1;
$derogation = false;
foreach ($archives as $archive) {
if ($archive->accessRuleComDate) {
$communicationDelay = $archive->accessRuleComDate->diff(\laabs::newTimestamp());
if ($communicationDelay->invert != 0) {
$derogation = true;
$unique = array(
'type' => 'ArchiveDeliveryRequest',
'senderOrgRegNumber' => $requesterOrgRegNumber,
'reference' => $reference,
);
break;
}
}
while ($this->sdoFactory->exists("medona/message", $unique)) {
$i++;
$unique['reference'] = $reference = $identifier.'_'.$i;
}
$archiverOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$message = $this->send($messageIdentifier, $archives, $derogation, $comment, $requesterOrgRegNumber, $archiverOrgRegNumber);
$message = $this->send($reference, $archives, $derogation, $comment, $requesterOrgRegNumber, $archiverOrgRegNumber);
$messages[] = $message;
}
......@@ -326,7 +332,7 @@ class ArchiveDeliveryRequest extends abstractMessage
{
$this->changeStatus($messageId, "rejected");
$archiveDeliveryRequestReplyController = \laabs::newController('medona/ArchiveDeliveryRequestReply');
//$archiveDeliveryRequestReplyController = \laabs::newController('medona/ArchiveDeliveryRequestReply');
$message = $this->sdoFactory->read('medona/message', array('messageId' => $messageId));
......@@ -337,8 +343,6 @@ class ArchiveDeliveryRequest extends abstractMessage
$message,
true
);
return $archiveDeliveryRequestReplyController->send($messageId, "rejected", $comment);
}
/**
......@@ -353,7 +357,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)) {
......
<?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
*
* @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)) {
$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
}
$requesterOrgRegNumber = $requesterOrg->registrationNumber;
$i = 0;
if (!$identifier) {
$identifier = "archiveDestructionRequest_".date("Y-m-d-H-i-s");
}
$reference = $identifier;
foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) {
$i = 1;
$recipientOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$i++;
if (!$identifier) {
$identifier = "archiveDestructionRequest_".\laabs::newId();
} else {
$identifier .= "_".$i;
$unique = array(
'type' => 'ArchiveDestructionRequest',
'senderOrgRegNumber' => $requesterOrgRegNumber,
'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;
......
......@@ -48,19 +48,21 @@ class ArchiveDestructionRequest extends abstractMessage
/**
* Get transfer history
* @param string $reference
* @param string $archiver
* @param string $originator
* @param string $depositor
* @param string $archivalAgreement
* @param date $fromDate
* @param date $toDate
*
* @param string $reference Reference
* @param string $archiver Archiver
* @param string $originator Originator
* @param string $depositor Depositor
* @param string $archivalAgreement Archival agreement
* @param date $fromDate From date
* @param date $toDate To date
* @param string $status Status
*
* @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
$this->generate($message);
$this->save($message);
}
$this->create($message);
$operationResult = true;
} catch (\Exception $e) {
$message->status = "error";
$this->create($message);
$operationResult = false;
throw $e;
}
$event = $this->lifeCycleJournalController->logEvent(
'medona/sending',
'medona/message',
$message->messageId,
$message,
$operationResult
);
$this->create($message);
$senderOrg = \laabs::getToken('ORGANIZATION');
// Requested by archiver: send auth request to originator
......@@ -214,6 +223,14 @@ class ArchiveDestructionRequest extends abstractMessage
$message->status = "accepted";
$event = $this->lifeCycleJournalController->logEvent(
'medona/acceptance',
'medona/message',
$message->messageId,
$message,
true
);
$this->sdoFactory->update($message);
}
......@@ -300,8 +317,10 @@ class ArchiveDestructionRequest extends abstractMessage
$message->status = "processed";
$message->operationDate = \laabs::newDatetime(null, "UTC");
$operationResult = true;
$this->update($message);
} catch (\Exception $e) {
$operationResult = false;
throw $e;
}
......@@ -309,6 +328,14 @@ class ArchiveDestructionRequest extends abstractMessage
$this->sdoFactory->commit();
}
$this->lifeCycleJournalController->logEvent(
'medona/processing',
'medona/message',
$message->messageId,
$message,
$operationResult
);
$archiveDestructionNotificationController = \laabs::newController("medona/ArchiveDestructionNotification");
// TO DO : Write destruction failures in comments
......
......@@ -155,7 +155,7 @@ class ArchiveModification
{
$archives = array();
foreach ($archiveIds as $archiveId) {
$archive = $this->archiveController->getDescription($archiveId);
$archive = $this->archiveController->retrieve($archiveId);
$archives[] = $archive;
}
......@@ -169,17 +169,29 @@ class ArchiveModification
}
$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) {
$i = 1;
$senderOrg = $archives[0]->archiverOrgRegNumber;
$recipientOrg = $originatorOrgRegNumber;
if ($identifier) {
$unique = array(
'type' => 'ArchiveModificationNotification',
'senderOrgRegNumber' => $senderOrg,
'reference' => $reference,
);
while ($this->sdoFactory->exists("medona/message", $unique)) {
$i++;
$identifier .= "_".$i;
$message = $archiveModificationNotificationController->send((string) $identifier, $archives, $senderOrg, $recipientOrg, $comment);
} else {
$message = $archiveModificationNotificationController->send((string) \laabs::newId(), $archives, $senderOrg, $recipientOrg, $comment);
$unique['reference'] = $reference = $identifier.'_'.$i;
}
$message = $archiveModificationNotificationController->send($reference, $archives, $senderOrg, $recipientOrg, $comment);
}
}
}
......@@ -54,19 +54,21 @@ class ArchiveNotification extends abstractMessage
/**
* Get transfer history
* @param string $reference
* @param string $archiver
* @param string $originator
* @param string $depositor
* @param string $archivalAgreement
* @param date $fromDate
* @param date $toDate
*
* @param string $reference Reference
* @param string $archiver Archiver
* @param string $originator Originator
* @param string $depositor Depositor
* @param string $archivalAgreement Archival agreement
* @param date $fromDate From date
* @param date $toDate To date
* @param string $status Status
*
* @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
/**
* Get transfer history
* @param string $reference
* @param string $archiver
* @param string $originator
* @param string $depositor
* @param string $archivalAgreement
* @param date $fromDate
* @param date $toDate
*
* @param string $reference Reference
* @param string $archiver Archiver
* @param string $originator Originator
* @param string $depositor Depositor
* @param string $archivalAgreement Archival agreement
* @param date $fromDate From date
* @param date $toDate To date
* @param string $status Status
*
* @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
}
$result = array('success' => array(), 'error' => array());
$counter = 0;
$archiveRestitutionRequestController = \laabs::newController("medona/ArchiveRestitutionRequest");
foreach ($archivesIdsByOriginator as $originatorOrgRegNumber => $archiveIds) {
$communicable = $this->archiveController->accessVerification(($archiveIds[0]));
if (!$communicable) {
$result["error"] = array_merge($result["error"], $archiveIds);
continue;
if (!$identifier) {
$identifier = "archiveRestitutionRequest_".date("Y-m-d-H-i-s");
}
$reference = $identifier;
foreach ($archivesIdsByOriginator as $originatorOrgRegNumber => $archiveIds) {
$candidates = $this->archiveController->setForRestitution($archiveIds);
$result["success"] = array_merge($result["success"], $candidates["success"]);
$result["error"] = array_merge($result["error"], $candidates["error"]);
......@@ -278,11 +278,21 @@ class ArchiveRestitution extends abstractMessage
continue;
}
$messageIdentifier = $identifier ? $identifier."_".++$counter : "archiveRestitutionRequest_".\laabs::newId();
$i = 1;
$unique = array(
'type' => 'ArchiveRestitutionRequest',
'senderOrgRegNumber' => $senderOrgRegNumber,
'reference' => $reference,
);
while ($this->sdoFactory->exists("medona/message", $unique)) {
$i++;
$unique['reference'] = $reference = $identifier.'_'.$i;
}
$recipientOrgRegNumber = $archivesForRestitution[0]->archiverOrgRegNumber;
$archiveRestitutionRequestController->send($messageIdentifier, $archivesForRestitution, $comment, $senderOrgRegNumber, $recipientOrgRegNumber, $userName);
$archiveRestitutionRequestController->send($reference, $archivesForRestitution, $comment, $senderOrgRegNumber, $recipientOrgRegNumber, $userName);
}
return $result;
......
......@@ -207,7 +207,6 @@ class ArchiveRestitutionRequest extends abstractMessage
*/
public function sendFromRequestMessage($reference, $requestMessage)
{
$this->loadXmlFile($requestMessage);
$this->readOrgs($requestMessage);
$message = \laabs::newInstance('medona/message');
......
......@@ -35,86 +35,6 @@ class ArchiveTransfer extends abstractMessage
protected $jhove;
/**
* Get received archive tranfer message
*
* @return array Array of medona/message object
*/
public function listReception()
{
$registrationNumber = $this->getCurrentRegistrationNumber();
$queryParts = [];
$queryParts[] = "recipientOrgRegNumber=$registrationNumber";
$queryParts[] = "type='ArchiveTransfer'";
$queryParts[] = "active=true";
$queryParts[] = "isIncoming=true";
$queryParts[] = "status != 'processed' AND status != 'error' AND status != 'invalid' AND status !='draft' AND status !='template' AND status !='rejected' AND status !='acknowledge'" ;
return $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300);
}
/**
* Get sending archive tranfer message
*
* @return array Array of medona/message object
*/
public function listSending()
{
$registrationNumber = $this->getCurrentRegistrationNumber();
$accountToken = \laabs::getToken("AUTH");
$queryParts = [];
$queryParts[] = "(accountId= '$accountToken->accountId' OR senderOrgRegNumber=$registrationNumber)";
$queryParts[] = "type='ArchiveTransfer'";
$queryParts[] = "active=true";
$queryParts[] = "isIncoming=true";
$queryParts[] = "status=['sent', 'received','accepted']";
return $this->sdoFactory->find("medona/message", implode(' and ', $queryParts), null, false, false, 300);
}
/**
* Get transfer history
* @param string $reference
* @param string $archiver
* @param string $originator
* @param string $depositor
* @param string $archivalAgreement
* @param date $fromDate
* @param date $toDate
*
* @return array Array of medona/message object
*/
public function history($reference = null, $archiver = null, $originator = null, $depositor = null, $archivalAgreement = null, $fromDate = null, $toDate = null)
{
return $this->search("ArchiveTransfer", $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate, true);
}
/**
* Count archive tranfer message
*
* @return array Number of received and sent messages
*/