Commit 3fba839b authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

Merge branch 'feat/15005_automatic_formated_id' into 'develop'

Feat/15005 automatic formated

See merge request !589
parents 7bfef368 f8f6641f
Pipeline #9836 failed with stages
in 51 seconds
......@@ -60,6 +60,28 @@ refDirectory = "%laabsDirectory%/data/maarchRM/ref"
; 3 = both
archivalProfileType = 2
; Automatic generation of archiverArchiveId on deposit
; format : The format with constant and variable values (see doc for available variables and parameters).
; Variable parameters are following a %1$s syntax identic than one use for php sprintf function
; % is mandatory, it tell system it's a variable
; number. Argument repetition. 1 MUST be delegated to separator
; $ mandatory
; s see sprintf documentation
;
; isAutomaticallyForced : false : a value will be generated and set only if no value is provided on the submission
; true : a value will be generated and replace any incoming value on the submission
; sequenceSeparator : string : a string representing the delimiter between sequences. This separator MUST not be used inside format
;
archiveIdGenerator = "{
'service' : 'recordsManagement/Generator/Sequence',
'archiverArchiveIdRules' : {
'isAutomaticallyForced' : true,
'isInheritedFromParent' : true,
'format' : 'FR094080%1$s%2$d%1$sAE%3$s',
'sequenceSeparator' : '_'
}
}"
; Default Retention Rule if any retention rule is set up ("dispose" or "preserve")
actionWithoutRetentionRule = "dispose"
......
......@@ -4,3 +4,5 @@ UPDATE "lifeCycle"."eventFormat" SET format = 'type senderOrgRegNumber senderOrg
INSERT INTO "lifeCycle"."eventFormat" (type, format, message, notification) VALUES ('digitalResource/integrityCheck', 'repositoryReference addressesToCheck checkedAddresses failed', 'Contrôle d''intégrité des ressources présentes dans %6$s', false);
ALTER TABLE "organization"."organization" ADD COLUMN "history" text;
CREATE SEQUENCE IF NOT EXISTS "recordsManagement"."archiverArchiveIdSequence";
......@@ -965,6 +965,9 @@ class ArchiveTransfer extends abstractMessage
$this->archiveController->manageFileplanPosition($archive);
$this->archiveController->convertArchive($archive);
$this->generateId($archive);
$this->archiveController->deposit($archive, $storagePath);
$unitIdentifier = \laabs::newInstance("medona/unitIdentifier");
......@@ -983,6 +986,7 @@ class ArchiveTransfer extends abstractMessage
}
}
$message->status = "processed";
$this->update($message);
} catch (\Exception $e) {
......@@ -1024,6 +1028,17 @@ class ArchiveTransfer extends abstractMessage
return (string) $replyMessage->messageId;
}
protected function generateId($archive)
{
$generator = \laabs::configuration('recordsManagement')['archiveIdGenerator'];
if (empty($generator)) {
return;
}
$generatorService = \laabs::newService($generator['service']);
$generatorService->generate($archive);
}
/**
* Get received archive tranfer message
*
......
......@@ -456,6 +456,12 @@ trait archiveEntryTrait
$this->manageFileplanPosition($archive);
$generator = \laabs::configuration('recordsManagement')['archiveIdGenerator'];
if (!empty($generator)) {
$generatorService = \laabs::newService($generator['service']);
$generatorService->generate($archive);
}
if (empty($archive->descriptionClass) && isset($this->currentArchivalProfile->descriptionClass)) {
$archive->descriptionClass = $this->currentArchivalProfile->descriptionClass;
}
......
<?php
/*
* Copyright (C) 2020 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\recordsManagement\Controller;
interface archiverArchiveIdGeneratorInterface
{
/**
* Receive an archive
*
* @param recordsManagement/archive $archive The archive to receive
*/
public function generate($archive);
}
<?php
/*
* Copyright (C) 2020 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\recordsManagement\Generator;
class Sequence implements \bundle\recordsManagement\Controller\archiverArchiveIdGeneratorInterface
{
/**
* Sdo Factory for management of archive persistance
* @var dependency/sdo/Factory
*/
protected $sdoFactory;
public function __construct(\dependency\sdo\Factory $sdoFactory)
{
$this->sdoFactory = $sdoFactory;
}
/**
* Generate archiverArchiveId
*
* @param recordsManagement/archive $archive
*
* @return recordsManagement/archive $archive
*/
public function generate($archive)
{
$sequenceConfiguration = \laabs::configuration('recordsManagement')['archiveIdGenerator']['archiverArchiveIdRules'];
if (is_null($sequenceConfiguration) || empty($sequenceConfiguration)) {
return;
}
if (!empty($archive->archiverArchiveId) && !$sequenceConfiguration['isAutomaticallyForced']) {
return;
}
if (isset($archive->parentArchiveId) && !empty($archive->parentArchiveId) && $sequenceConfiguration['isInheritedFromParent']) {
$parentArchive = $this->sdoFactory->read('recordsManagement/archive', $archive->parentArchiveId);
$parentArchiveId = (string) $parentArchive->archiveId;
$directChildrenCount = $this->sdoFactory->count('recordsManagement/archive', "parentArchiveId='$parentArchiveId'");
$archive->archiverArchiveId = $parentArchive->archiverArchiveId . $sequenceConfiguration['sequenceSeparator'] . str_pad($directChildrenCount + 1, 7, 0, STR_PAD_LEFT);
} else {
$sequenceId = $this->getNewSequenceId();
$year = date("Y");
$archive->archiverArchiveId = sprintf($sequenceConfiguration['format'], $sequenceConfiguration['sequenceSeparator'], $year, str_pad($sequenceId, 7, 0, STR_PAD_LEFT));
}
}
protected function getNewSequenceId()
{
$sequenceId = null;
$query = <<<EOT
SELECT NEXTVAL('"recordsManagement"."archiverArchiveIdSequence"');
EOT;
$stmt = $this->sdoFactory->das->pdo->prepare($query);
$stmt->execute();
while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$sequenceId = $result['nextval'];
}
return $sequenceId;
}
}
......@@ -347,3 +347,5 @@ CREATE INDEX "recordsManagement_archive_originatorArchiveId_idx" ON "recordsMana
CREATE INDEX "recordsManagement_archiveRelationship_archiveId_idx" ON "recordsManagement"."archiveRelationship" USING btree ("archiveId");
CREATE INDEX "recordsManagement_archiveRelationship_relatedArchiveId_idx" ON "recordsManagement"."archiveRelationship" USING btree ("relatedArchiveId");
CREATE SEQUENCE IF NOT EXISTS "recordsManagement"."archiverArchiveIdSequence";
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment