Skip to content
Snippets Groups Projects
Commit c918f278 authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

Merge branch 'feat/14436_resip_connector' into 'develop'

feat/14436 : add resip feature

See merge request maarch/archivesPubliques!204
parents 6f6858ca a5abdf8d
No related branches found
No related tags found
No related merge requests found
<?php
/*
* Copyright (C) 2020 Maarch
*
* This file is part of bundle organization.
*
* Bundle organization 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 organization 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 organization. If not, see <http://www.gnu.org/licenses/>.
*/
namespace ext\archivesPubliques\bundle\seda2\Connectors;
/**
* @author Jerome Boucher <jerome.boucher@maarch.org>
*/
class Resip extends \bundle\medona\Connectors\Multiparts
{
use ResipTrait;
/**
* Get archive transfer transformed by connector
*
* @param mixed $package The source of the message
* @param array $params Additional parameters
*
* @return array Array of medona/message object
*/
public function receive($package, $params, $messageDirectory)
{
$modelpath = parent::receive($package, $params, $messageDirectory);
$modelParams = $params;
unset($modelParams['attachments']);
$this->transformXml($modelpath, $modelParams);
return $modelpath;
}
}
<?php
/*
* Copyright (C) 2015 Maarch
*
* This file is part of bundle seda.
*
* Bundle seda 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 seda 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 seda. If not, see <http://www.gnu.org/licenses/>.
*/
namespace ext\archivesPubliques\bundle\seda2\Connectors;
trait ResipTrait
{
public function transformXml($messagePath, $params)
{
$xml = new \stdClass();
$xml = \laabs::newService('dependency/xml/Document');
$xml->load($messagePath);
$xml->xpath = \laabs::newService('dependency/xml/XPath', $xml);
$xml->xpath->registerNamespace('seda2', $xml->documentElement->namespaceURI);
$xml->documentElement->removeAttribute("xml:id");
$xml->documentElement->removeAttribute("xsi:schemaLocation");
foreach ($params as $paramKey => $paramValue) {
switch ($paramKey) {
case 'MessageIdentifier':
$messageIdentifierNode = $xml->xpath->query("//seda2:MessageIdentifier")->item(0);
if (is_null($paramValue)) {
$paramValue = \laabs::uniqid();
}
if (!is_null($messageIdentifierNode)) {
$messageIdentifierNode->nodeValue .= $paramValue;
}
break;
case 'ArchivalAgreement':
$archivalAgreementNode = $xml->xpath->query("//seda2:ArchivalAgreement")->item(0);
if (!is_null($paramValue)) {
$archivalAgreementNode->nodeValue = $paramValue;
}
break;
case 'ArchivalAgencyIdentifier':
$archivalAgencyIdentifierNode = $xml->xpath->query("//seda2:ArchivalAgency/seda2:Identifier")->item(0);
if (is_null($paramValue) && is_null($archivalAgencyIdentifierNode->item(0))) {
throw new \core\Exception\BadRequestException("Archival Agency is mandatory", 400);
}
if (!is_null($paramValue)) {
$archivalAgencyIdentifierNode->nodeValue = $paramValue;
}
break;
case 'TransferringAgencyIdentifier':
$transferringAgencyIdentifierNode = $xml->xpath->query("//seda2:TransferringAgency/seda2:Identifier")->item(0);
if (is_null($paramValue) && is_null($transferringAgencyIdentifierNode->item(0))) {
throw new \core\Exception\BadRequestException("Transferring Agency is mandatory", 400);
}
if (!is_null($paramValue)) {
$transferringAgencyIdentifierNode->nodeValue = $paramValue;
}
break;
case 'OriginatingAgencyIdentifier':
$originatingAgencyIdentifierNode = $xml->xpath->query("//seda2:ManagementMetadata/seda2:OriginatingAgencyIdentifier")->item(0);
if (!is_null($paramValue)) {
$originatingAgencyIdentifierNode->nodeValue = $paramValue;
}
break;
case 'ServiceLevel':
$serviceLevelText = $xml->createTextNode($params['ServiceLevel']);
$serviceLevelNode = $xml->createElement('ServiceLevel');
$serviceLevelNode->appendChild($serviceLevelText);
$acquisitionInformationNode = $xml->xpath->query("//seda2:ManagementMetadata/seda2:AcquisitionInformation")->item(0);
$managementMetadataNode = $xml->xpath->query("//seda2:ManagementMetadata")->item(0);
if (!is_null($paramValue)) {
$managementMetadataNode->insertBefore($serviceLevelNode, $acquisitionInformationNode);
}
break;
case 'Language':
$languageText = $xml->createTextNode($paramValue);
$languageNode = $xml->createElement('Language');
$languageNode->appendChild($languageText);
foreach ($xml->xpath->query("//seda2:DataObjectPackage/seda2:DescriptiveMetadata//seda2:ArchiveUnit/seda2:Content") as $contentNode) {
$languageText = $xml->createTextNode($paramValue);
$languageNode = $xml->createElement('Language');
$languageNode->appendChild($languageText);
$transactedDateNode = $xml->xpath->query(".//seda2:TransactedDate", $contentNode)->item(0);
$contentNode->insertBefore($languageNode, $transactedDateNode);
}
break;
default:
# code...
break;
}
}
foreach ($xml->xpath->query("//seda2:DataObjectPackage/seda2:DescriptiveMetadata//seda2:ArchiveUnit") as $archiveUnitNodeList) {
$archiveUnitNodeList->attributes->item(0)->nodeValue = 'id_' . $archiveUnitNodeList->attributes->item(0)->nodeValue;
}
foreach ($xml->xpath->query("//seda2:DataObjectPackage//seda2:DataObjectGroup") as $dataObjectGroupNodeList) {
$messageDigestNodeList = $xml->xpath->query('.//seda2:MessageDigest', $dataObjectGroupNodeList);
$messageDigestNodeList->item(0)->attributes->item(0)->nodeValue = str_replace('-', '', $messageDigestNodeList->item(0)->attributes->item(0)->nodeValue);
}
file_put_contents($messagePath, $xml->saveXml());
}
}
<?php
/*
* Copyright (C) 2020 Maarch
*
* This file is part of bundle organization.
*
* Bundle organization 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 organization 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 organization. If not, see <http://www.gnu.org/licenses/>.
*/
namespace ext\archivesPubliques\bundle\seda2\Connectors;
/**
* @author Jerome Boucher <jerome.boucher@maarch.org>
*/
class ResipZIP extends \bundle\medona\Connectors\Zip
{
use ResipTrait;
/**
* Get archive transfer transformed by connector
*
* @param mixed $package The source of the message
* @param array $params Additional parameters
*
* @return array Array of medona/message object
*/
public function receive($package, $params, $messageDirectory)
{
$modelpath = parent::receive($package, $params, $messageDirectory);
$modelParams = $params;
unset($modelParams['attachments']);
$this->transformXml($modelpath, $modelParams);
return $modelpath;
}
}
......@@ -187,6 +187,110 @@ packageSchemas = "{
; type: 'file' | 'text' | 'number' | 'boolean' | 'enum' | 'organization' | 'archivalProfile' (default: 'text')
; enumNames: (only if type is 'enum'), array of texts or numbers
packageConnectors = "{
'resip' : {
'label' : 'ReSip',
'service' : 'seda2/Connectors/Resip',
'schema' : 'seda2',
'params' : {
'attachments' : {
'label' : 'Pièces',
'source' : 'input',
'type' : 'file',
'multiple' : true
},
'MessageIdentifier' : {
'label' : 'Identifiant unique',
'source' : 'input',
'type' : 'text',
'required' : false
},
'ArchivalAgreement' : {
'label' : 'Accord de versement',
'source': 'input',
'type' : 'text',
'required' : false
},
'ArchivalAgencyIdentifier' : {
'label' : 'Identifiant du service darchive',
'source' : 'input',
'type' : 'text',
'required' : true
},
'TransferringAgencyIdentifier' : {
'label' : 'Identifiant du service versant',
'source' : 'input',
'type' : 'text',
'required' : true
},
'OriginatingAgencyIdentifier' : {
'label' : 'Identifiant des services producteurs',
'source' : 'input',
'type' : 'text',
'required' : true
},
'ServiceLevel' : {
'label' :'Identifiant du niveau de service',
'source' : 'input',
'type' : 'text',
'required' : false
},
'Language' : {
'label' : 'Langue',
'source' : 'input',
'type' : 'text',
'required' : false
}
}
},
'resipZip' : {
'label' : 'ReSip Zip',
'service' : 'seda2/Connectors/ResipZip',
'schema' : 'seda2',
'params' : {
'MessageIdentifier' : {
'label' : 'Identifiant unique',
'source' : 'input',
'type' : 'text',
'required' : false
},
'ArchivalAgreement' : {
'label' : 'Accord de versement',
'source': 'input',
'type' : 'text',
'required' : false
},
'ArchivalAgencyIdentifier' : {
'label' : 'Identifiant du service darchive',
'source' : 'input',
'type' : 'text',
'required' : true
},
'TransferringAgencyIdentifier' : {
'label' : 'Identifiant du service versant',
'source' : 'input',
'type' : 'text',
'required' : true
},
'OriginatingAgencyIdentifier' : {
'label' : 'Identifiant des services producteurs',
'source' : 'input',
'type' : 'text',
'required' : true
},
'ServiceLevel' : {
'label' :'Identifiant du niveau de service',
'source' : 'input',
'type' : 'text',
'required' : false
},
'Language' : {
'label' : 'Langue',
'source' : 'input',
'type' : 'text',
'required' : false
}
}
},
'octave' : {
'label' : 'Octave',
'service' : 'seda2/Connectors/Octave',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment