Verified Commit b6eccee0 authored by Alexandre Morin's avatar Alexandre Morin
Browse files

refactor (#8555) : actions

parent ef71d552
......@@ -134,7 +134,13 @@ chainWithTimestamp = false;
; Any operation on this list will no be logged in the application journal
;ignoreMethods = "['read']"
[medona]
; Enable or disable the transaction mode
; true = Enable
; false = Disable
transaction = false
messageDirectory = "%laabsDirectory%/data/maarchRM/medona"
autoValidateSize = 2147000
......
......@@ -98,8 +98,14 @@ class ArchiveDestructionRequest extends abstractMessage
*
* @return The request message generated
*/
public function send($reference, $archives, $comment = null, $requesterOrgRegNumber = null, $archiverOrgRegNumber = null, $originatorOrgRegNumber=null)
{
public function send(
$reference,
$archives,
$comment = null,
$requesterOrgRegNumber = null,
$archiverOrgRegNumber = null,
$originatorOrgRegNumber = null
) {
if (!is_array($archives)) {
$archives = array($archives);
}
......@@ -136,7 +142,9 @@ class ArchiveDestructionRequest extends abstractMessage
}
if ($message->schema != 'medona') {
$archiveDestructionRequestController = \laabs::newController($message->schema.'/ArchiveDestructionRequest');
$archiveDestructionRequestController = \laabs::newController(
$message->schema.'/ArchiveDestructionRequest'
);
$archiveDestructionRequestController->send($message);
} else {
$archiveDestructionRequest = $this->sendMessage($message);
......
......@@ -791,31 +791,6 @@ class message
return $messageSchema;
}
/**
* Get the message type and schema specific controller
* @param medona/message $message The message object
*
* @return The controller
*/
protected function getMessageTypeController($message)
{
if (!isset($message->type)) {
$message->type = $message->xml->documentElement->nodeName;
}
if (!isset($message->schema)) {
$messageNamespace = $message->xml->documentElement->namespaceURI;
if (!$messageSchema = \laabs::resolveXmlNamespace($messageNamespace)) {
throw new \Exception('Unknown message namespace'.$messageNamespace, 400);
}
$message->schema = $messageSchema;
}
$this->messageTypeController = \laabs::newController($message->schema.LAABS_URI_SEPARATOR.$message->type);
return $this->messageTypeController;
}
/**
* Get the message type and schema specific parser
* @param medona/message $message The message object
......
......@@ -28,11 +28,14 @@ trait archiveDestructionTrait
{
/**
* Flag for disposal
* @param array $archiveIds The archives ids
*
* @return bool The result of the operation
* @param array $archiveIds The archives ids
* @param string $identifier
* @param string $comment
* @return mixed
* @throws \bundle\recordsManagement\Exception\notDisposableArchiveException
*/
public function dispose($archiveIds)
public function dispose($archiveIds, $identifier = null, $comment = null)
{
$archives = [];
......@@ -58,15 +61,24 @@ trait archiveDestructionTrait
$this->logDestructionRequest($archive);
}
$this->sendDestructionRequest($archives, $reference = null, $comment = null);
if (\laabs::configuration("medona")['transaction']) {
$this->sendDestructionRequest($archives, $identifier, $comment);
}
return $archiveList;
}
/**
*
* Send destruction request
*
* @param $archives
* @param null $identifier
* @param null $comment
* @return mixed
* @throws \Exception
*/
protected function sendDestructionRequest($archives, $reference = null, $comment = null)
protected function sendDestructionRequest($archives, $identifier = null, $comment = null)
{
$archiveDestructionRequestController = \laabs::newController("medona/ArchiveDestructionRequest");
......@@ -107,7 +119,14 @@ trait archiveDestructionTrait
$unique['reference'] = $reference = $identifier.'_'.$i;
}
$archiveDestructionRequestController->send($reference, $archives, $comment, $requesterOrgRegNumber, $recipientOrgRegNumber, $originatorOrgRegNumber);
$archiveDestructionRequestController->send(
$reference,
$archives,
$comment,
$requesterOrgRegNumber,
$recipientOrgRegNumber,
$originatorOrgRegNumber
);
}
return $archives;
......@@ -194,7 +213,10 @@ trait archiveDestructionTrait
foreach ($archives['success'] as $archiveId) {
$archive = $this->retrieve((string)$archiveId);
if ($archive->status != 'disposed' && $archive->status != 'restituted' && $archive->status != 'transfered') {
if ($archive->status != 'disposed'
&& $archive->status != 'restituted'
&& $archive->status != 'transfered'
) {
$destructArchives['error'][] = $archive;
continue;
}
......@@ -300,6 +322,12 @@ trait archiveDestructionTrait
return $archiveIds;
}
/**
* @param $archive
* @param bool $isChild
* @return array
* @throws \bundle\recordsManagement\Exception\notDisposableArchiveException
*/
public function checkDisposalRights($archive, $isChild = false)
{
$archiveIds = [];
......@@ -316,13 +344,23 @@ trait archiveDestructionTrait
}
if (isset($archive->finalDisposition) && $archive->finalDisposition != "destruction") {
throw new \bundle\recordsManagement\Exception\notDisposableArchiveException($beforeError."Archive not set for destruction.");
throw new \bundle\recordsManagement\Exception\notDisposableArchiveException(
$beforeError."Archive not set for destruction."
);
}
if (isset($archive->disposalDate) && $archive->disposalDate > $currentDate) {
throw new \bundle\recordsManagement\Exception\notDisposableArchiveException($beforeError."Disposal date not reached.");
throw new \bundle\recordsManagement\Exception\notDisposableArchiveException(
$beforeError."Disposal date not reached."
);
}
if ((!isset($archive->finalDisposition) || empty($archive->finalDisposition) || empty($archive->disposalDate)) && $actionWithoutRetentionRule == "preserve") {
throw new \bundle\recordsManagement\Exception\notDisposableArchiveException($beforeError."There is a missing management information (date or retention rule).");
if ((!isset($archive->finalDisposition)
|| empty($archive->finalDisposition)
|| empty($archive->disposalDate)
)
&& $actionWithoutRetentionRule == "preserve") {
throw new \bundle\recordsManagement\Exception\notDisposableArchiveException(
$beforeError."There is a missing management information (date or retention rule)."
);
}
return $archiveIds ;
......@@ -333,7 +371,8 @@ trait archiveDestructionTrait
$currentService = \laabs::getToken("ORGANIZATION");
$archive = $this->sdoFactory->read('recordsManagement/archive', $archiveId);
if (($currentService->registrationNumber != $archive->archiverOrgRegNumber || !\laabs::callService('auth/userAccount/readHasprivilege', "destruction/destructionRequest"))
if (($currentService->registrationNumber != $archive->archiverOrgRegNumber
|| !\laabs::callService('auth/userAccount/readHasprivilege', "destruction/destructionRequest"))
&& !in_array("owner", $currentService->orgRoleCodes)) {
return false ;
}
......
......@@ -38,7 +38,9 @@ trait archiveModificationTrait
$archive = $this->sdoFactory->read('recordsManagement/archive', $archiveId);
if ($archive->status === 'frozen') {
throw new \bundle\recordsManagement\Exception\retentionRuleException('A frozen archive can\'t be modified.');
throw new \bundle\recordsManagement\Exception\retentionRuleException(
'A frozen archive can\'t be modified.'
);
}
return \laabs::castMessage($archive, 'recordsManagement/archiveRetentionRule');
......@@ -56,7 +58,9 @@ trait archiveModificationTrait
$archive = $this->sdoFactory->read('recordsManagement/archive', $archiveId);
if ($archive->status === 'frozen') {
throw new \bundle\recordsManagement\Exception\retentionRuleException('A frozen archive can\'t be modified.');
throw new \bundle\recordsManagement\Exception\retentionRuleException(
'A frozen archive can\'t be modified.'
);
}
$this->getAccessRule($archive);
......@@ -66,12 +70,15 @@ trait archiveModificationTrait
/**
* Modify the archive retention rule
* @param recordsManagement/archiveRetentionRule $retentionRule The retention rule object
* @param mixed $archiveIds The archives ids
*
* @return bool The result of the operation
* @param recordsManagement/archiveRetentionRule $retentionRule The retention rule object
* @param @param mixed $archiveIds The archives ids
* @param null $comment
* @param null $identifier
* @return array
* @throws \Exception
*/
public function modifyRetentionRule($retentionRule, $archiveIds)
public function modifyRetentionRule($retentionRule, $archiveIds, $comment = null, $identifier = null)
{
$retentionRuleReceived = $retentionRule;
......@@ -126,7 +133,10 @@ trait archiveModificationTrait
$retentionRule->disposalDate = null;
} else {
if (!empty($retentionRule->retentionDuration) && !empty($retentionRule->retentionStartDate)) {
$retentionRule->disposalDate = $this->calculateDate($retentionRule->retentionStartDate, $retentionRule->retentionDuration);
$retentionRule->disposalDate = $this->calculateDate(
$retentionRule->retentionStartDate,
$retentionRule->retentionDuration
);
}
}
......@@ -151,19 +161,23 @@ trait archiveModificationTrait
}
}
$this->sendModificationNotification($archives, $comment = null, $identifier = null);
if (\laabs::configuration("medona")['transaction']) {
$this->sendModificationNotification($archives, $comment, $identifier);
}
return $res;
}
/**
* Modify the archive access
*
* @param recordsManagement/archiveAccessCode $accessRule The access rule object
* @param array $archiveIds The archives ids
*
* @return bool The result of the operation
* @param null $comment
* @param null $identifier
* @return array
*/
public function modifyAccessRule($accessRule, $archiveIds)
public function modifyAccessRule($accessRule, $archiveIds, $comment = null, $identifier = null)
{
if (!is_array($archiveIds)) {
$archiveIds = array($archiveIds);
......@@ -203,7 +217,10 @@ trait archiveModificationTrait
} elseif (!empty($accessRule->accessRuleDuration) && $accessRule->accessRuleDuration->y >= 9999) {
$accessRule->accessRuleComDate = null;
} elseif (!empty($accessRule->accessRuleDuration) && !empty($accessRule->accessRuleStartDate)) {
$accessRule->accessRuleComDate = $this->calculateDate($accessRule->accessRuleStartDate, $accessRule->accessRuleDuration);
$accessRule->accessRuleComDate = $this->calculateDate(
$accessRule->accessRuleStartDate,
$accessRule->accessRuleDuration
);
}
$accessRule->lastModificationDate = \laabs::newTimestamp();
......@@ -228,7 +245,9 @@ trait archiveModificationTrait
}
}
$this->sendModificationNotification($archives, $comment = null, $identifier = null);
if (\laabs::configuration("medona")['transaction']) {
$this->sendModificationNotification($archives, $comment, $identifier);
}
return $res;
}
......@@ -236,10 +255,12 @@ trait archiveModificationTrait
/**
* Suspend archives
* @param mixed $archiveIds Array of archive identifier
* @param null $comment
* @param null $identifier
*
* @return array
*/
public function freeze($archiveIds)
public function freeze($archiveIds, $comment = null, $identifier = null)
{
if (!is_array($archiveIds)) {
$archiveIds = array($archiveIds);
......@@ -267,7 +288,9 @@ trait archiveModificationTrait
$this->logFreeze($archive, false);
}
$this->sendModificationNotification($archives, $comment = null, $identifier = null);
if (\laabs::configuration("medona")['transaction']) {
$this->sendModificationNotification($archives, $comment, $identifier);
}
return $res;
}
......@@ -275,10 +298,12 @@ trait archiveModificationTrait
/**
* Liberate archives
* @param mixed $archiveIds Array of archive identifier
* @param null $comment
* @param null $identifier
*
* @return array
*/
public function unfreeze($archiveIds)
public function unfreeze($archiveIds, $comment = null, $identifier = null)
{
if (!is_array($archiveIds)) {
$archiveIds = array($archiveIds);
......@@ -306,7 +331,9 @@ trait archiveModificationTrait
$this->logUnfreeze($archive, false);
}
$this->sendModificationNotification($archives, $comment = null, $identifier = null);
if (\laabs::configuration("medona")['transaction']) {
$this->sendModificationNotification($archives, $comment, $identifier);
}
return $res;
}
......@@ -393,7 +420,9 @@ trait archiveModificationTrait
$this->logMetadataModification($archive, $operationResult);
$this->sendModificationNotification([$archive], $comment = null, $identifier = null);
if (\laabs::configuration("medona")['transaction']) {
$this->sendModificationNotification([$archive]);
}
return $res;
}
......@@ -413,7 +442,9 @@ trait archiveModificationTrait
// Life cycle journal
$this->logRelationshipAdding($archive, $archiveRelationship);
$this->sendModificationNotification([$archive], $comment = null, $identifier = null);
if (\laabs::configuration("medona")['transaction']) {
$this->sendModificationNotification([$archive]);
}
return true;
}
......@@ -433,7 +464,9 @@ trait archiveModificationTrait
// Life cycle journal
$this->logRelationshipDeleting($archive, $archiveRelationship);
$this->sendModificationNotification([$archive], $comment = null, $identifier = null);
if (\laabs::configuration("medona")['transaction']) {
$this->sendModificationNotification([$archive]);
}
return true;
}
......@@ -449,7 +482,15 @@ trait archiveModificationTrait
$res = [];
$res['success'] = [];
$res['fail'] = [];
$archivesToIndex = $this->sdoFactory->find('recordsManagement/archive', "fullTextIndexation='requested'", [], null, null, $limit);
$archivesToIndex = $this->sdoFactory->find(
'recordsManagement/archive',
"fullTextIndexation='requested'",
[],
null,
null,
$limit
);
if (isset(\laabs::configuration('recordsManagement')['stopWordsFilePath'])) {
$stopWords = \laabs::configuration('recordsManagement')['stopWordsFilePath'];
$stopWords = utf8_encode(file_get_contents($stopWords));
......@@ -507,7 +548,14 @@ trait archiveModificationTrait
*/
public function updateArchiveRetentionRule($limit = 1000)
{
$archives = $this->sdoFactory->find('recordsManagement/archive', 'retentionRuleCode != null AND retentionStartDate != null AND retentionDuration !=null AND retentionRuleStatus = "changed"', null, null, null, $limit);
$archives = $this->sdoFactory->find(
'recordsManagement/archive',
'retentionRuleCode != null AND retentionStartDate != null AND retentionDuration !=null AND retentionRuleStatus = "changed"',
null,
null,
null,
$limit
);
$retentionRules = [];
foreach ($archives as $archive) {
......@@ -551,7 +599,7 @@ trait archiveModificationTrait
// Valid URL file:// http:// data://
if (filter_var($contents, FILTER_VALIDATE_URL)) {
$contents = stream_get_contents($contents);
} else if (preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $contents)) {
} elseif (preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $contents)) {
$contents = base64_decode($contents);
} elseif (is_file($contents)) {
if (empty($filename)) {
......@@ -581,7 +629,10 @@ trait archiveModificationTrait
}
try {
$this->digitalResourceController->openContainers($this->currentServiceLevel->digitalResourceClusterId, $archive->storagePath);
$this->digitalResourceController->openContainers(
$this->currentServiceLevel->digitalResourceClusterId,
$archive->storagePath
);
$this->digitalResourceController->store($digitalResource);
$this->logAddResource($archive, $digitalResource, true);
......@@ -627,7 +678,7 @@ trait archiveModificationTrait
$this->sdoFactory->update($archiveUserOrgRegNumbers);
}
protected function sendModificationNotification($archives, $comment, $identifier = null)
protected function sendModificationNotification($archives, $comment = null, $identifier = null)
{
$currentOrg = \laabs::getToken("ORGANIZATION");
......@@ -664,7 +715,13 @@ trait archiveModificationTrait
$unique['reference'] = $reference = $identifier.'_'.$i;
}
$message = $archiveModificationNotificationController->send($reference, $archives, $senderOrg, $recipientOrg, $comment);
$archiveModificationNotificationController->send(
$reference,
$archives,
$senderOrg,
$recipientOrg,
$comment
);
}
}
}
......@@ -120,6 +120,8 @@ class archive
$this->view->translate();
$transaction = \laabs::configuration("medona")["transaction"];
//access code selector
$accessRuleController = \laabs::newController('recordsManagement/accessRule');
$accessRules = $accessRuleController->index();
......@@ -148,14 +150,24 @@ class archive
$currentDate = \laabs::newDate();
foreach ($archives as $archive) {
$archive->finalDispositionDesc = $this->view->translator->getText($archive->finalDisposition, false, "recordsManagement/messages");
$archive->statusDesc = $this->view->translator->getText($archive->status, false, "recordsManagement/messages");
$archive->finalDispositionDesc = $this->view->translator->getText(
$archive->finalDisposition,
false,
"recordsManagement/messages"
);
$archive->statusDesc = $this->view->translator->getText(
$archive->status,
false,
"recordsManagement/messages"
);
if (!empty($archive->disposalDate) && $archive->disposalDate <= $currentDate) {
$archive->disposable = true;
}
if (empty($archive->disposalDate) && (empty($archive->retentionRuleCode) || empty($archive->retentionDuration))) {
if (empty($archive->disposalDate)
&& (empty($archive->retentionRuleCode) || empty($archive->retentionDuration))
) {
$archive->noRetention = true;
}
......@@ -163,12 +175,16 @@ class archive
$archive->originatorOrgName = $orgsByRegNumber[$archive->originatorOrgRegNumber]->displayName;
try {
if ($archive->status == 'disposed' || $archive->status == 'error' || $archive->status == 'restituted' || $archive->status == 'transfered') {
if ($archive->status == 'disposed'
|| $archive->status == 'error'
|| $archive->status == 'restituted'
|| $archive->status == 'transfered'
) {
$archive->hasRights = false;
} else {
$archive->hasRights = $archiveController->checkRights($archive);
}
} catch(\Exception $e) {
} catch (\Exception $e) {
$archive->hasRights = false;
}
}
......@@ -189,6 +205,7 @@ class archive
$this->view->setSource("accessRules", $accessRules);
$this->view->setSource("retentionRules", $retentionRules);
$this->view->setSource('archive', $archives);
$this->view->setSource('transaction', $transaction);
$this->view->merge();
return $this->view->saveHtml();
......
......@@ -59,10 +59,12 @@ $('.multipleActionMenu').on('click', 'li', function() {
if(type == "checkHash") {
ArchivesAction.checkHash(selection['ids'].join("&archiveIds[]="));
} else {
ModificationModal.loadMultiple(selection.selected, selection.relevant, selection.ids, selection.names,type);
}
var transaction = false;
$("#transaction").val() ? transaction = true : transaction = false;
})
ModificationModal.loadMultiple(selection.selected, selection.relevant, selection.ids, selection.names,type, transaction);
}
});
$('#archiveList').on('click', '.actionMenu li', function() {
var button = $(this);
......@@ -74,9 +76,12 @@ $('#archiveList').on('click', '.actionMenu li', function() {
if(type == "checkHash") {
ArchivesAction.checkHash(id);
} else {
ModificationModal.load(id, name, type);
var transaction = false;
$("#transaction").val() ? transaction = true : transaction = false;
ModificationModal.load(id, name, type, transaction);
}
})
});
var ArchivesAction = {
actionsPossibility : {
......
......@@ -74,62 +74,30 @@
var ArchiveModification = {
modal: $('#modificationModal'),
serialize: function (type) {
var parameter = {}
if (type === "accessRule") {
var code = this.modal.find('[name="accessRuleCode"]').find('option:selected').data('json');
parameter.accessRule = {
accessRuleCode: this.modal.find('[name="accessRuleCode"]').val(),
accessRuleStartDate: this.modal.find('[name="startDate"]').val(),
accessRuleDuration: code.duration
}
} else if (type === "retentionRule") {
var code = this.modal.find('[name="retentionRuleCode"]').find('option:selected').data('json');
parameter.retentionRule = {
retentionStartDate: this.modal.find('[name="startDate"]').val(),
retentionRuleCode: this.modal.find('[name="retentionRuleCode"]').val()
};
if (code) {
parameter.retentionRule.retentionDuration = code.duration;
}
if (!($("#updateFinalDisposition").css('display') === 'block' && $('#retentionRuleFinalDisposition').prop("disabled"))) {
parameter.retentionRule.finalDisposition = $('#retentionRuleFinalDisposition').val();
}
console.log("passage");
var parameter = {};
var transaction = false;
$("#transaction").val() ? transaction = true : transaction = false;