Skip to content
Snippets Groups Projects
Commit 0c969b18 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

dev #72435 : reject authorities with repeated title and log it

parent 27a1c1f6
Branches
Tags
2 merge requests!2894Dev#72435 3 explo autorite etape 1 minsoc09 communaute importer un fichier autorite,!2874Dev#72435 3 explo autorite etape 1 minsoc09 communaute importer un fichier autorite
Pipeline #5239 passed with stage
in 31 minutes and 21 seconds
......@@ -26,8 +26,6 @@ class Class_Cosmogramme_Integration_PhaseAuthority
const MY_ID = 0;
protected static $_service_runner;
protected function _init($phase) {}
......@@ -41,9 +39,11 @@ class Class_Cosmogramme_Integration_PhaseAuthority
public function importRecord($data, $integration) {
$integrator = new Class_Cosmogramme_Integration_Record_Authority($integration);
$integrator->import($data);
$this->_incrementCount($integrator->getStatut());
$result = (new Class_Cosmogramme_Integration_Record_Authority($integration))->import($data);
$this->_incrementCount($result->getStatus());
if ($result->isReject() && ($message = $result->getMessage()))
$this->_log->error($message);
}
......@@ -106,10 +106,4 @@ class Class_Cosmogramme_Integration_PhaseAuthority
protected function _headerOfHook($integration) {
return '';
}
/** @category testing */
public static function setServiceRunner($runner) {
static::$_service_runner = $runner;
}
}
......@@ -23,15 +23,9 @@
class Class_Cosmogramme_Integration_Record_Authority {
use Trait_TimeSource, Trait_Translator;
const
RECORD_REJECT = 0,
RECORD_INSERT = 1;
protected
$_reader,
$_integration,
$_statut,
$_error,
$_authority_type,
$_codif_provider;
......@@ -46,17 +40,14 @@ class Class_Cosmogramme_Integration_Record_Authority {
public function import($data) {
$this->_reader->setNotice($data, $this->_encoding());
if (!$id_origine = $this->_getId()) {
$this->_statut = static::RECORD_REJECT;
$this->_error = $this->_('Autorité sans 001');
return;
}
if (!$id_origine = $this->_getId())
return $this->_rejectWith($this->_('Autorité sans 001'));
if (!$title = $this->_getTitle()) {
$this->_statut = static::RECORD_REJECT;
$this->_error = $this->_('Autorité sans vedette');
return;
}
if ($this->_isRepeatedTitle())
return $this->_rejectWith($this->_('Autorité avec vedette répétée (%s)', $id_origine));
if (!$title = $this->_getTitle())
return $this->_rejectWith($this->_('Autorité sans vedette'));
$record = ['unimarc' => $data,
'type' => Class_Notice::TYPE_AUTHORITY,
......@@ -69,7 +60,12 @@ class Class_Cosmogramme_Integration_Record_Authority {
$this->_save($id_origine, $record);
$this->_saveCodifFor($record['type_doc'], $title);
$this->_statut = static::RECORD_INSERT;
return Class_Cosmogramme_Integration_Record_AuthorityResult::newInsert();
}
protected function _rejectWith($message) {
return Class_Cosmogramme_Integration_Record_AuthorityResult::newRejectWith($message);
}
......@@ -186,6 +182,11 @@ class Class_Cosmogramme_Integration_Record_Authority {
}
protected function _isRepeatedTitle() {
return $this->_authority_type->isRepeatedIn('2', 'a', $this->_reader);
}
protected function _getAuthorityType() {
$detected = $this->_authority_type->codeFromFirstIn('2', $this->_reader);
return $detected ? $detected : $this->_reader->labelPart(9, 1);
......
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Cosmogramme_Integration_Record_AuthorityResult {
const
RECORD_REJECT = 0,
RECORD_INSERT = 1;
protected
$_status,
$_message = '';
public static function newRejectWith($message) {
return new static(static::RECORD_REJECT, $message);
}
public static function newInsert() {
return new static(static::RECORD_INSERT);
}
public function __construct($status, $message='') {
$this->_status = $status;
$this->_message = $message;
}
public function isReject() {
return static::RECORD_REJECT === $this->_status;
}
public function getStatus() {
return $this->_status;
}
public function getMessage() {
return $this->_message;
}
}
......@@ -64,6 +64,13 @@ class Class_Cosmogramme_Integration_Record_AuthorityType {
}
public function isRepeatedIn($prefix, $subfield, $reader) {
foreach($this->_variantsOfOne($prefix) as $field)
if ($result = $reader->get_subfield($field, $subfield))
return 1 < count($result);
}
public function valuesFrom($prefix, $subfield, $reader) {
$values = [];
foreach($this->_variantsOfOne($prefix) as $field)
......
......@@ -59,12 +59,6 @@ class PhaseAuthorityTest extends Class_Cosmogramme_Integration_PhaseTestCase {
'traite' => 'non',
'fichier' => 'authorities_tess_mini.mrc',
'pointeur_reprise' => 0]);
$this->_service_runner = $this->mock()
->whenCalled('run')
->answers(['statut' => 'KO']);
Class_Cosmogramme_Integration_PhaseNotice::setServiceRunner($this->_service_runner);
}
......@@ -94,6 +88,18 @@ class PhaseAuthorityTest extends Class_Cosmogramme_Integration_PhaseTestCase {
}
/** @test */
public function repeated250DollarAShouldNotBeImported() {
$this->assertNull($this->_recordWithIdOrigine('191145'));
}
/** @test */
public function repeated250DollarAShouldBeLoggedAsError() {
$this->assertLogContains('Autorité avec vedette répétée (191145)');
}
/** @test */
public function amenagementDuTerritoireShouldExists() {
$this->assertNotNull($record = $this->_recordWithIdOrigine('185349'));
......
00978 a2200277 450000500170000010000290001715200090004625000310005555000420008655000360012855000360016455000280020055000360022855000400026455000410030455000320034555000490037755000400042655000340046655000290050055000260052955000540055555000460060999900380065500100070069320171128140014.0 a20170831afrey50 ba0 bTESS aAménagement du territoire 31921565ga1 - CADRE ET MILIEU DE VIE 31856115haDéveloppement local 31861065haEquipement collectif 31861135haMilieu rural 31906215haAménagement foncier 31887235haDéveloppement régional 31911715haCoopération territoriale 31885705haZone touristique 31872935haZone d'aménagement du territoire 31909415haPôle de compétitivité 31854275haZone d'entreprises 31905315haOuvrage d'art 31889315haTerritoire 31853835haPolitique d'aménagement du territoire 31900005haCoopération transfrontalière 9tess:TESS/AMENAGEMENTDUTERRITOIRE18534900339 a2200133 450000500170000010000290001715200090004625000230005555000310007855000300010955000300013999900290016900100070019820171128140013.0 a20170831afrey50 ba0 bTESS aSystème de santé 31853865gaSanté publique 3185351aAssurance maladie 3185351aAssurance maladie 9tess:TESS/SYSTEMEDESANTE18535000408 a2200157 450000500170000010000290001715200090004625000220005555000330007755000190011055000210012955000310015055000310018199900310021200100070024320171128140004.0 a20170831afrey50 ba0 bTESS aAssurance maladie 31877265gaAssurance sociale 31885535haCMU 31888975haCMU-C 3185350aSystème de santé 3185350aSystème de santé 9tess:TESS/ASSURANCEMALADIE18535100229 a2200109 450000500170000010000290001715200090004625000100005555000270006599900200009200100070011220171128140024.0 a20170831afrey50 ba0 bTESS aBilan 31922585gaMots-outils 9tess:TESS/BILAN18535200234 a2200109 450000500170000010000290001715200090004625000130005555000270006899900220009500100070011720171128140027.0 a20170831afrey50 ba0 bTESS aRéforme 31922585gaMots-outils 9tess:TESS/REFORME18535300462 a2200157 450000500170000010000290001715200090004625000090005545000390006445000560010345000560015945000270021555000360024299900190027800100070029720171128140039.0 a20170831afrey50 ba0 bTESS aPLIE aPlan local d'insertion économique aPlan local pluriannuel pour l'insertion et l'emploi aPlan local pluriannuel pour l'insertion et l'emploi 3778899aReject with id 31868085gaMesure pour l'emploi 9tess:TESS/PLIE192516
\ No newline at end of file
00978 a2200277 450000500170000010000290001715200090004625000310005555000420008655000360012855000360016455000280020055000360022855000400026455000410030455000320034555000490037755000400042655000340046655000290050055000260052955000540055555000460060999900380065500100070069320171128140014.0 a20170831afrey50 ba0 bTESS aAménagement du territoire 31921565ga1 - CADRE ET MILIEU DE VIE 31856115haDéveloppement local 31861065haEquipement collectif 31861135haMilieu rural 31906215haAménagement foncier 31887235haDéveloppement régional 31911715haCoopération territoriale 31885705haZone touristique 31872935haZone d'aménagement du territoire 31909415haPôle de compétitivité 31854275haZone d'entreprises 31905315haOuvrage d'art 31889315haTerritoire 31853835haPolitique d'aménagement du territoire 31900005haCoopération transfrontalière 9tess:TESS/AMENAGEMENTDUTERRITOIRE18534900339 a2200133 450000500170000010000290001715200090004625000230005555000310007855000300010955000300013999900290016900100070019820171128140013.0 a20170831afrey50 ba0 bTESS aSystème de santé 31853865gaSanté publique 3185351aAssurance maladie 3185351aAssurance maladie 9tess:TESS/SYSTEMEDESANTE18535000408 a2200157 450000500170000010000290001715200090004625000220005555000330007755000190011055000210012955000310015055000310018199900310021200100070024320171128140004.0 a20170831afrey50 ba0 bTESS aAssurance maladie 31877265gaAssurance sociale 31885535haCMU 31888975haCMU-C 3185350aSystème de santé 3185350aSystème de santé 9tess:TESS/ASSURANCEMALADIE18535100229 a2200109 450000500170000010000290001715200090004625000100005555000270006599900200009200100070011220171128140024.0 a20170831afrey50 ba0 bTESS aBilan 31922585gaMots-outils 9tess:TESS/BILAN18535200234 a2200109 450000500170000010000290001715200090004625000130005555000270006899900220009500100070011720171128140027.0 a20170831afrey50 ba0 bTESS aRéforme 31922585gaMots-outils 9tess:TESS/REFORME18535300462 a2200157 450000500170000010000290001715200090004625000090005545000390006445000560010345000560015945000270021555000360024299900190027800100070029720171128140039.0 a20170831afrey50 ba0 bTESS aPLIE aPlan local d'insertion économique aPlan local pluriannuel pour l'insertion et l'emploi aPlan local pluriannuel pour l'insertion et l'emploi 3778899aReject with id 31868085gaMesure pour l'emploi 9tess:TESS/PLIE19251600177 a2200085 450000100070000000500170000725000290002410000290005315200090008219114520171123192627.0 aCodeaSécurité sociale a20171123afrey50 ba0 bTESS
\ No newline at end of file
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