Commit 19f2dc6f authored by Prosper De Laure's avatar Prosper De Laure
Browse files

First commit

parent e4bbb06c
<?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 ext\thirdPartyArchiving\bundle\medona\Batch;
/**
* Class for batch job to archive messages
*
*/
class archiveCertificate
{
protected $messageController;
protected $sdoFactory;
/**
* Construct the batch job instance
* @param \dependency\sdo\Factory $sdoFactory The dependency Sdo Factory
*/
public function __construct(\dependency\sdo\Factory $sdoFactory)
{
$this->messageController = \laabs::newController('medona/message');
$this->sdoFactory = $sdoFactory;
}
/**
* Receive the message
*
* @return medona/message $message
*/
public function archive()
{
$certificates = $this->sdoFactory->find('medona/message', 'archived = false');
foreach ($certificates as $certificate) {
$this->messageController->recordCertificate($certificate);
}
return true;
}
}
<?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 ext\thirdPartyArchiving\bundle\medona\Batch;
/**
* Class for batch job to process messages
*
*/
class processArchiveDelivery
{
// Controllers
protected $messageController;
protected $sdoFactory;
/**
* Construct the batch job instance
* @param \dependency\sdo\Factory $sdoFactory The dependency Sdo Factory
*/
public function __construct(\dependency\sdo\Factory $sdoFactory)
{
// Controlers
$this->messageController = \laabs::newController('medona/message');
$this->sdoFactory = $sdoFactory;
}
/**
* Process the message
*
* @return medona/message $message
*/
public function process()
{
$messages = $this->sdoFactory->find("medona/message", "status='accepted' AND type='ArchiveDeliveryRequest' AND active=true");
foreach ($messages as $message) {
$this->messageController->processArchiveDelivery((string) $message->messageId);
}
}
}
<?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 ext\thirdPartyArchiving\bundle\medona\Batch;
/**
* Class for batch job to process messages
*
*/
class processArchiveDestruction
{
// Controllers
protected $messageController;
protected $sdoFactory;
/**
* Construct the batch job instance
* @param \dependency\sdo\Factory $sdoFactory The dependency Sdo Factory
*/
public function __construct(\dependency\sdo\Factory $sdoFactory)
{
// Controlers
$this->messageController = \laabs::newController('medona/message');
$this->sdoFactory = $sdoFactory;
}
/**
* Process the message
*
* @return medona/message $message
*/
public function process()
{
$messages = $this->sdoFactory->find("medona/message", "type='ArchiveDestructionRequest' AND status='accepted' AND active='true'");
foreach ($messages as $message) {
$this->messageController->processArchiveDestruction($message);
}
}
}
<?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 ext\thirdPartyArchiving\bundle\medona\Batch;
/**
* Class for batch job to process messages
*
*/
class processArchiveTransfers
{
// Controllers
protected $messageController;
protected $sdoFactory;
/**
* Construct the batch job instance
* @param \dependency\sdo\Factory $sdoFactory The dependency Sdo Factory
*/
public function __construct(\dependency\sdo\Factory $sdoFactory)
{
// Controlers
$this->messageController = \laabs::newController('medona/message');
$this->sdoFactory = $sdoFactory;
}
/**
* Process the message
*
* @return medona/message $message
*/
public function process()
{
$messages = $this->sdoFactory->find("medona/message", "status='accepted' AND type='ArchiveTransfer' AND active=true");
foreach ($messages as $message) {
$this->messageController->processArchiveTransfer((string) $message->messageId);
}
}
}
<?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 ext\thirdPartyArchiving\bundle\medona\Batch;
/**
* Class for batch job to deposit messages
*
*/
class receiveArchiveTransfer
{
// Controllers
protected $messageController;
protected $zip;
// Loaded data
protected $messagefile;
protected $tmpdir;
protected $start;
/**
* Construct the batch job instance
* @param string $messagefile The message path, directory or xml file or zip file
* @param bool $compressed Indicates that the message is compressed
*/
public function __construct($messagefile, $compressed = false)
{
// Controlers
$this->messageController = \laabs::newController('medona/message');
if ($compressed) {
$this->zip = \laabs::newService('dependency/fileSystem/plugins/zip');
$tmpdir = sys_get_temp_dir().\laabs::uniqid();
$this->zip->extract($messagefile, $tmpdir);
$messagefile = glob($tmpdir.DIRECTORY_SEPARATOR.'*.xml')[0];
}
$this->messagefile = $messagefile;
$this->start = \laabs::newTimestamp();
}
/**
* Receive the message
*
* @return medona/message $message
*/
public function receive()
{
$message = $this->messageController->receiveArchiveTransfer($this->messagefile);
$this->messageController->validateArchiveTransfer($message);
}
}
<?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 ext\thirdPartyArchiving\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 ext\thirdPartyArchiving\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 ext\thirdPartyArchiving\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();