Verified Commit 4f1aa612 authored by Cyril Vazquez's avatar Cyril Vazquez Committed by Alexandre Morin
Browse files

Merge from TPA, added files

parent 0b7009af
<?php
/*
* Copyright (C) 2015 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 bundle\medona\Controller;
/**
* Trait for acknowledgement
*
* @package Medona
* @author Alexis Ragot <alexis.ragot@maarch.org>
*/
class Acknowledgement
extends abstractMessage
{
/**
* Send an aknowledgement
* @param string $receivedMessage The received message
*
* @return The ack generated
*/
public function send($receivedMessage)
{
if (is_scalar($receivedMessage)) {
$messageId = $receivedMessage;
$receivedMessage = $this->sdoFactory->read('medona/message', $messageId);
}
$message = \laabs::newInstance('medona/message');
$message->messageId = \laabs::newId();
$message->type = "Acknowledgement";
$message->schema = $receivedMessage->schema;
$message->status = "sent";
$message->date = \laabs::newDatetime(null, "UTC");
$message->reference = $receivedMessage->reference.'_Ack';
$message->requestReference = $receivedMessage->reference;
$message->senderOrgRegNumber = $receivedMessage->recipientOrgRegNumber;
$message->recipientOrgRegNumber = $receivedMessage->senderOrgRegNumber;
try {
$this->readOrgs($message); // read org names, addresses, communications, contacts
} catch (\Exception $e) {
$recipientOrg = \laabs::getToken("ORGANIZATION");
$message->recipientOrgRegNumber = $recipientOrg->registrationNumber;
$message->recipientOrg = $recipientOrg;
$message->senderOrgRegNumber = $recipientOrg->registrationNumber;
$message->senderOrg = $recipientOrg;
}
try {
if ($message->schema != 'medona') {
$archiveTransferReplyController = \laabs::newController($message->schema.'/Acknowledgement');
$archiveTransferReplyController->send($message);
} else {
/*$archiveTransferReply = $this->sendMessage($message);
$message->object = $archiveTransferReply;
$archiveTransferReply->replyCode = $this->sendReplyCode($message->replyCode);
if (isset($message->requestReference)) {
$archiveTransferReply->messageRequestIdentifier = \laabs::newInstance('medona/Identifier', $message->requestReference);
}
if (isset($message->operationDate)) {
$archiveTransferReply->grantDate = (string) $message->operationDate;
}
$archiveTransferReply->archivalAgency = $this->sendOrganization($message->senderOrg);
$archiveTransferReply->transferringAgency = $this->sendOrganization($message->recipientOrg);
// Generate XML
$this->generate($message);
$this->save($message);*/
}
$operationResult = true;
} catch (\Exception $e) {
$message->status = "error";
$operationResult = false;
throw $e;
}
$event = $this->lifeCycleJournalController->logEvent(
'medona/sending',
'medona/message',
$message->messageId,
$message,
$operationResult
);
$this->create($message);
return $message;
}
}
<?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 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
<?php
/*
* Copyright (C) 2015 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 bundle\medona\Controller;
/**
* Archival profile modification notification
* @author Cyril Vazquez <cyril.vazquez@maarch.org>
*/
class ArchivalProfileModificationNotification extends ArchiveNotification
{
/**
* Send a new transfer reply
* @param string $reference The notification message identifier
* @param array $profile The profile
*
* @return The message generated
*/
public function send($reference, $profile)
{
$archivalAgreements = $this->archivalAgreementController->getByProfileReference((string) $profile->archivalProfileId);
$recipients = array();
foreach ($archivalAgreements as $archivalAgreement) {
foreach ($archivalAgreement->originatorOrgIds as $originatorOrgId) {
$recipient = $this->orgController->read($originatorOrgId);
$recipients[] = $recipient;
}
}
$messages = array();
if (!\laabs::hasBundle("seda")) {
$this->retentionRuleController = \laabs::newController('recordsManagement/retentionRule');
$retentionRule = $this->retentionRuleController->read($profile->retentionRuleCode);
$profile->retentionRuleDuration = $retentionRule->duration;
$profile->retentionRuleFinalDisposition = $retentionRule->finalDisposition;
$this->accessRuleController = \laabs::newController('recordsManagement/accessRule');
$accessRule = $this->accessRuleController->edit($profile->accessRuleCode);
$profile->accessRuleDuration = $accessRule->duration;
}
foreach ($recipients as $recipient) {
$message = \laabs::newInstance('medona/message');
$message->messageId = \laabs::newId();
$message->type = "ArchivalProfileModificationNotification";
$message->schema = "medona";
$message->status = "sent";
$message->date = \laabs::newDatetime(null, "UTC");
$message->receptionDate = $message->date;
$message->reference = $reference."_".$recipient->registrationNumber;
$senderOrg = $this->orgController->getOrgsByRole('archiver')[0];
$message->senderOrgRegNumber = $senderOrg->registrationNumber;
$message->senderOrgName = $senderOrg->orgName;
$message->recipientOrgRegNumber = $recipient->registrationNumber;
$message->recipientOrgName = $recipient->orgName;
$message->profile = $profile;
try {
$this->generate($message);
$this->save($message);
$operationResult = true;
} catch (\Exception $e) {
$message->status = "error";
$operationResult = false;
}
$this->lifeCycleJournalController->logEvent(
'medona/sending',
'medona/message',
$message->messageId,
$message,
$operationResult
);
$this->create($message);
$messages[] = $message;
}
return $messages;
}
}
<?php
/*
* Copyright (C) 2015 Maarch
*
* This file is part of bundle recordsManagement.
*
* Bundle recordsManagement 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 recordsManagement 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 recordsManagement. If not, see <http://www.gnu.org/licenses/>.
*/
namespace bundle\medona\Controller;
/**
* Archives modification
*/
class ArchiveConversion
{
protected $sdoFactory;
/**
* Constructor
* @param \dependency\sdo\Factory $sdoFactory The sdo factory
*/
public function __construct(\dependency\sdo\Factory $sdoFactory)
{
$this->sdoFactory = $sdoFactory;
}
/**
* Flag for converison
* @param array $documentIds Array of document identifier
*
* @return bool
*/
public function conversion($documentIds)
{
$archiveConversionRequestController = \laabs::newController("medona/ArchiveConversionRequest");
$organizationController = \laabs::newController('organization/organization');
$archiveIds = array();
$documentsByOriginator = array();
foreach ($documentIds as $documentId) {
$archiveDocumentDigitalResource = $this->sdoFactory->find('recordsManagement/archiveDocumentDigitalResource', "docId='".(string) $documentId."'")[0];
$archiveIds[] = $archiveDocumentDigitalResource->archiveId;
if (!isset($documentsByOriginator[$archiveDocumentDigitalResource->originatorOrgRegNumber])) {
$documentsByOriginator[$archiveDocumentDigitalResource->originatorOrgRegNumber] = array();
}
$documentsByOriginator[$archiveDocumentDigitalResource->originatorOrgRegNumber][] = $archiveDocumentDigitalResource;
}
$senderOrg = \laabs::getToken('ORGANIZATION');
if (!$senderOrg) {
throw \laabs::newException('medona/invalidMessageException', "No current organization choosen");
}
foreach ($documentsByOriginator as $originatorOrgRegNumber => $documents) {
$recipientOrg = $organizationController->getOrgByRegNumber($originatorOrgRegNumber);
$archiveConversionRequestController->send((string) \laabs::newId(), $senderOrg, $recipientOrg, $documents);
}
return $documentIds;
}
}
<?php
/*
* Copyright (C) 2015 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 bundle\medona\Controller;
/**
* Conversion request message
*
* @author Alexis RAGOT <alexis.ragot@maarch.org>
*/
class ArchiveConversionRequest extends abstractMessage
{
/**
* Send a new a new delivery request
* @param string $reference The message identifier
* @param object $senderOrg The requesting org
* @param object $recipientOrg The originating org
* @param array $documents An array of document objects
*
* @return The request message generated
*/
public function send($reference, $senderOrg, $recipientOrg, $documents)
{
if (!is_array($documents)) {
$documents = array($documents);
}
$message = \laabs::newInstance('medona/message');
$message->messageId = \laabs::newId();
$message->schema = "medona";
$message->type = "ArchiveConversionRequest";
$message->status = 'processWait';
$message->date = \laabs::newDatetime(null, "UTC");
$message->receptionDate = $message->date;
$message->reference = $reference;
$message->senderOrgRegNumber = $senderOrg->registrationNumber;
$message->recipientOrgRegNumber = $recipientOrg->registrationNumber;
// read org names, addresses, communications, contacts
$this->readOrgs($message);
foreach ($documents as $document) {
$unitIdentifier = \laabs::newInstance("medona/unitIdentifier");
$unitIdentifier->messageId = $message->messageId;
$unitIdentifier->objectClass = "documentManagement/document";
$unitIdentifier->objectId = (string) $document->docId;
$message->unitIdentifier[] = $unitIdentifier;
}
$archiveConversionRequest = $this->sendMessage($message);
$message->object = $archiveConversionRequest;
$archiveConversionRequest->requester = $this->sendOrganization($message->senderOrg);
$archiveConversionRequest->archivalAgency = $this->sendOrganization($message->recipientOrg);
$message->object->unitIdentifier = $message->unitIdentifier;
$this->create($message);
return $message;
}
/**
* Process all archive destructions
*
* @return the result of process
*/
public function processAll()
{
$index = $this->sdoFactory->index('medona/message', array('messageId'), "type = 'ArchiveConversionRequest' AND status = 'processWait'");
$result = array();
foreach ($index as $messageId) {
try {
$results[(string) $message->messageId] = $this->process($messageId);
} catch (\Exception $e) {
$results[(string) $message->messageId] = $e;
}
}
return $result;
}
/**
* Process archive destruction
* @param medona/message $messageId
*
* @return the result of process
*/
public function process($messageId)
{
if (is_scalar($messageId)) {
$message = $this->read($messageId);
} else {
$message = $messageId;
}
$convertedDocumentIds = array();
$transactionControl = !$this->sdoFactory->inTransaction();
if ($transactionControl) {
$this->sdoFactory->beginTransaction();
}
foreach ($message->unitIdentifier as $unitIdentifier) {
$docId = (string) $unitIdentifier->objectId;
try {
$convertedDocument = $this->archiveController->convert($docId, $messageId);
$convertedDocumentIds[$docId] = (string) $convertedDocument->docId;
} catch (\Exception $e) {
throw new \bundle\medona\Exception\invalidConversionException("Error of conversion process");
}
}
$message->status = "processed";
$message->operationDate = \laabs::newDatetime(null, "UTC");
$this->update($message);
if ($transactionControl) {
$this->sdoFactory->commit();
}
return $convertedDocumentIds;
}
/**
* Get conversion request message
*
* @return array Array of medona/message object
*/
public function listConversionRequest()
{
$queryParts = array();
$queryParts[] = "type='ArchiveConversionRequest'";
return $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300);
}
}
<?php
/*
* Copyright (C) 2015 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 bundle\medona\Controller;
/**
* Archive delivery request
*
* @author Alexis Ragot <alexis.ragot@maarch.org>
*/
class ArchiveDeliveryRequest extends abstractMessage
{
/**
* Get received archive delivery message
*
* @return array Array of medona/message object
*/
public function listReception()
{
$currentOrg = \laabs::getToken('ORGANIZATION');
if (!$currentOrg) {
$this->view->addContentFile("recordsManagement/welcome/noWorkingOrg.html");
return $this->view->saveHtml();
}
$queryParts = array();
$registrationNumber = $this->getCurrentRegistrationNumber();
$queryParts[] = "recipientOrgRegNumber=$registrationNumber";
$queryParts[] = "type='ArchiveDeliveryRequest'";
$queryParts[] = "status = 'sent'";
$queryParts[] = "active=true";
return $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300);
}
/**
* Get transfer history
*
* @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, $status = null)
{
return $this->search("ArchiveDelivery", $reference, $archiver, $originator, $depositor, $archivalAgreement, $fromDate, $toDate, $status);
}
/**
* Count archive delivery message
*
* @return array Number of received and sent messages
*/
public function count()
{