Commit 59f31355 authored by Alexandre Morin's avatar Alexandre Morin
Browse files

Merge branch 'develop' into 'master'

Develop

See merge request !5
parents 6cc6b7cc 6de07c7a
<?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);
}
}
......@@ -105,11 +105,11 @@ class ArchiveDeliveryRequest extends abstractMessage
*/
public function requestDelivery($archiveIds, $identifier = null, $comment = null)
{
$senderOrg = \laabs::getToken('ORGANIZATION');
if (!$senderOrg) {
$requesterOrg = \laabs::getToken('ORGANIZATION');
if (!$requesterOrg) {
throw \laabs::newException('medona/invalidMessageException', "No current organization choosen");
}
$senderOrgRegNumber = $senderOrg->registrationNumber;
$requesterOrgRegNumber = $requesterOrg->registrationNumber;
if (!is_array($archiveIds)) {
$archiveIds = array($archiveIds);
......@@ -135,12 +135,7 @@ class ArchiveDeliveryRequest extends abstractMessage
$derogation = false;
foreach ($archives as $archive) {
if (!$archive->accessRuleComDate) {
$derogation = true;
break;
} else {
// Calc diff between communicability date and curent date
if ($archive->accessRuleComDate) {
$communicationDelay = $archive->accessRuleComDate->diff(\laabs::newTimestamp());
if ($communicationDelay->invert != 0) {
$derogation = true;
......@@ -150,8 +145,8 @@ class ArchiveDeliveryRequest extends abstractMessage
}
}
$recipientOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$message = $this->send($messageIdentifier, $archives, $derogation, $comment, $senderOrgRegNumber, $recipientOrgRegNumber);
$archiverOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$message = $this->send($messageIdentifier, $archives, $derogation, $comment, $requesterOrgRegNumber, $archiverOrgRegNumber);
$controlAutorityControler = \laabs::newController("medona/ControlAuthority");
if (count($controlAutorityControler->index()) > 0) {
......@@ -172,13 +167,13 @@ class ArchiveDeliveryRequest extends abstractMessage
* @param array $archives An array of archives
* @param boolean $derogation Ask for an authorization
* @param string $comment The request comment
* @param object $senderOrgRegNumber The requesting org
* @param string $recipientOrgRegNumber The recipient org registration number
* @param object $requesterOrgRegNumber The requesting org reg number
* @param string $archiverOrgRegNumber The archiver org registration number
* @param string $userName The requester user name
*
* @return The reply message generated
*/
public function send($reference, $archives, $derogation = false, $comment = false, $senderOrgRegNumber = false, $recipientOrgRegNumber = false, $userName = false)
public function send($reference, $archives, $derogation = false, $comment = false, $requesterOrgRegNumber = false, $archiverOrgRegNumber = false, $userName = false)
{
if (!is_array($archives)) {
$archives = array($archives);
......@@ -200,8 +195,8 @@ class ArchiveDeliveryRequest extends abstractMessage
$message->comment[] = $comment;
$message->senderOrgRegNumber = $senderOrgRegNumber;
$message->recipientOrgRegNumber = $recipientOrgRegNumber;
$message->senderOrgRegNumber = $requesterOrgRegNumber;
$message->recipientOrgRegNumber = $archiverOrgRegNumber;
// read org names, addresses, communications, contacts
$this->readOrgs($message);
......@@ -331,7 +326,7 @@ class ArchiveDeliveryRequest extends abstractMessage
true
);
return $archiveDeliveryRequestReplyController->send($messageId, "REJECT", $comment);
return $archiveDeliveryRequestReplyController->send($messageId, "rejected", $comment);
}
/**
......
......@@ -50,7 +50,7 @@ class ArchiveDestruction
{
$archiveList = $this->archiveController->dispose($archiveIds);
$archiveDestructionController = \laabs::newController("medona/ArchiveDestructionRequest");
$archiveDestructionRequestController = \laabs::newController("medona/ArchiveDestructionRequest");
$archivesByOriginator = array();
foreach ($archiveList['success'] as $archiveId) {
......@@ -61,18 +61,18 @@ class ArchiveDestruction
$archivesByOriginator[$archive->originatorOrgRegNumber][] = $archive;
}
$senderOrg = null;
if (!$senderOrg) {
$senderOrg = \laabs::getToken('ORGANIZATION');
if (!$senderOrg) {
$requesterOrg = null;
if (!$requesterOrg) {
$requesterOrg = \laabs::getToken('ORGANIZATION');
if (!$requesterOrg) {
throw \laabs::newException('medona/invalidMessageException', "No current organization choosen");
}
}
$senderOrg = $senderOrg->registrationNumber;
$requesterOrgRegNumber = $requesterOrg->registrationNumber;
$i = 0;
foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) {
$recipientOrg = $archives[0]->archiverOrgRegNumber;
$recipientOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$i++;
if (!$identifier) {
......@@ -81,7 +81,7 @@ class ArchiveDestruction
$identifier .= "_".$i;
}
$archiveDestructionController->send($identifier, $archives, $comment, $senderOrg, $recipientOrg);
$archiveDestructionRequestController->send($identifier, $archives, $comment, $requesterOrgRegNumber, $recipientOrgRegNumber, $originatorOrgRegNumber);
}
return $archiveList;
......
......@@ -87,15 +87,16 @@ class ArchiveDestructionRequest extends abstractMessage
/**
* Send a new a new delivery request
* @param string $reference The message identifier
* @param array $archives An array of archives
* @param string $comment The request comment
* @param string $senderOrg The requesting org
* @param string $recipientOrg The requesting org
* @param string $reference The message identifier
* @param array $archives An array of archives
* @param string $comment The request comment
* @param string $requesterOrgRegNumber The requesting org reg number
* @param string $archiverOrgRegNumber The recipient archiver org reg number
* @param string $originatorOrgRegNumber The originator org reg number
*
* @return The request message generated
*/
public function send($reference, $archives, $comment = null, $senderOrg = null, $recipientOrg = null)
public function send($reference, $archives, $comment = null, $requesterOrgRegNumber = null, $archiverOrgRegNumber = null, $originatorOrgRegNumber=null)
{
if (!is_array($archives)) {
$archives = array($archives);
......@@ -117,8 +118,8 @@ class ArchiveDestructionRequest extends abstractMessage
$message->comment[] = $comment;
$message->senderOrgRegNumber = $senderOrg;
$message->recipientOrgRegNumber = $recipientOrg;
$message->senderOrgRegNumber = $requesterOrgRegNumber;
$message->recipientOrgRegNumber = $archiverOrgRegNumber;
$this->readOrgs($message); // read org names, addresses, communications, contacts
try {
......@@ -157,24 +158,23 @@ class ArchiveDestructionRequest extends abstractMessage
throw $e;
}
if ($message->senderOrgRegNumber != $archives[0]->originatorOrgRegNumber) {
// Requested by archiver: send auth request to originator
$senderOrg = \laabs::getToken('ORGANIZATION');
// Requested by archiver: send auth request to originator
if ($senderOrg->registrationNumber == $message->recipientOrg) {
$authorizationOriginatingAgencyRequestController = \laabs::newController('medona/AuthorizationOriginatingAgencyRequest');
$authorizationOriginatingAgencyRequestController->send($message, $archives[0]->originatorOrgRegNumber);
$authorizationOriginatingAgencyRequestController->send($message, $originatorOrgRegNumber);
$message->status == "authorization_wait";
$message->status == "originator_authorization_wait";
} else {
// Requested by originator
$controlAuthorities = $this->orgController->getOrgsByRole('controlAuthority');
// Check if control authority is set on system
if (count($controlAuthorities)) {
$message->status == "authorization_wait";
reset($controlAuthorities);
$message->status == "control_authorization_wait";
$authorizationControlAuthorityRequestController = \laabs::newController('medona/AuthorizationControlAuthorityRequest');
$authorizationControlAuthorityRequestController->send($message);
$authorizationControlAuthorityRequestController->send($message, $originatorOrgRegNumber);
}
}
......
......@@ -38,11 +38,11 @@ class ArchiveNotification extends abstractMessage
$registrationNumber = $this->getCurrentRegistrationNumber();
$queryParts = [];
$queryParts[] = "recipientOrgRegNumber=$registrationNumber";
$queryParts[] = "(type='ArchiveModificationNotification' OR type='ArchiveDestructionNotification' OR type='ArchivalProfileModificationNotification')";
$queryParts[] = "recipientOrgRegNumber=$registrationNumber OR senderOrgRegNumber=$registrationNumber";
$queryParts[] = "type='ArchiveModificationNotification' OR type='ArchiveDestructionNotification' OR type='ArchivalProfileModificationNotification'";
$queryParts[] = "active=true";
return $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300);
return $this->sdoFactory->find('medona/message', '('.implode(') and (', $queryParts).')', null, false, false, 300);
}
/**
......@@ -57,7 +57,7 @@ class ArchiveNotification extends abstractMessage
$res = array();
$queryParts = array();
$queryParts[] = "(type='ArchiveModificationNotification' OR type='ArchiveDestructionNotification' OR type='ArchivalProfileModificationNotification')";
$queryParts[] = "recipientOrgRegNumber=$registrationNumber";
$queryParts[] = "recipientOrgRegNumber=$registrationNumber OR senderOrgRegNumber=$registrationNumber";
$queryParts[] = "active=true";
$res['received'] = $this->sdoFactory->count('medona/message', implode(' and ', $queryParts));
......
......@@ -76,13 +76,13 @@ class ArchiveRestitutionRequest extends abstractMessage
*/
public function listSending($sender = false, $recipient = false, $fromDate = false, $toDate = false, $reference = false)
{
$queryParts = $this->searchMessage($sender, $recipient, $fromDate, $toDate, $reference);
$registrationNumber = $this->getCurrentRegistrationNumber();
$queryParts[] = "type='ArchiveRestitutionRequest'";
$queryParts[] = "senderOrgRegNumber=$registrationNumber";
$queryParts[] = "active=true";
return $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300);
return $this->sdoFactory->find('medona/message', '('.implode(') and (', $queryParts).')', null, false, false, 300);
}
/**
......@@ -322,6 +322,30 @@ class ArchiveRestitutionRequest extends abstractMessage
return $replyMessage;
}
/**
* Process the messages
*
* @return medona/message $message
*/
public function processBatch()
{
$results = array();
$messages = $this->sdoFactory->find("medona/message", "status='accepted' AND type='ArchiveRestitutionRequest' AND active=true");
foreach ($messages as $message) {
$this->changeStatus($message->messageId, "processing");
$this->loadData($message);
try {
$results[(string) $message->messageId] = $this->process($message);
} catch (\Exception $e) {
$results[(string) $message->messageId] = $e;
}
}
return $results;
}
/**
* Validate message against schema and rules
* @param medona/message $message
......
......@@ -48,7 +48,7 @@ class ArchiveTransfer extends abstractMessage
$queryParts[] = "recipientOrgRegNumber=$registrationNumber";
$queryParts[] = "type='ArchiveTransfer'";
$queryParts[] = "active=true";
$queryParts[] = "status != 'processed' AND status != 'error' AND status != 'invalid' AND status !='draft'";
$queryParts[] = "status != 'processed' AND status != 'error' AND status != 'invalid' AND status !='draft' AND status !='template'" ;
return $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300);
}
......@@ -585,10 +585,10 @@ class ArchiveTransfer extends abstractMessage
$this->sendError("304", "Le service d'archives n'est pas conforme à celui indiqué dans l'accord de versement.");
}
if (empty($this->currentArchivalAgreement->originatorOrgIds)) {
$this->sendError("300", "Il n'y a pas de service producteur.");
} else {
if ($message->schema == 'medona') {
if ($message->schema == 'medona') {
if (empty($this->currentArchivalAgreement->originatorOrgIds)) {
$this->sendError("300", "Il n'y a pas de service producteur.");
} else {
$archivalAgreementOriginators = [];
foreach ((array) $this->currentArchivalAgreement->originatorOrgIds as $orgId) {
......@@ -999,14 +999,8 @@ class ArchiveTransfer extends abstractMessage
try {
if ($message->schema != 'medona') {
$archiveTransferController = \laabs::newController($message->schema.'/ArchiveTransfer');
$archives = $archiveTransferController->process($message);
list($archives, $archiveRelationships) = $archiveTransferController->process($message);
$archiveRelationships = [];
foreach ($archives as $archive) {
if ($archive->relationships) {
$archiveRelationships[] = $archive->relationships;
}
}
} else {