diff --git a/arkindex/dataimport/filetypes.py b/arkindex/dataimport/filetypes.py index aa42c49c643a51f31030da6f1619dbb5bdaccfe8..c71a0fc7485b5d27db8242bab64a13618db3ee4f 100644 --- a/arkindex/dataimport/filetypes.py +++ b/arkindex/dataimport/filetypes.py @@ -3,6 +3,7 @@ from arkindex.dataimport.config import ConfigFile, ImportType, VolumesImportForm from arkindex.dataimport.iiif import IIIFParser from arkindex.documents.surface import SurfaceImporter from arkindex.documents.surface_link import CorpusSurfaceLinker +from arkindex.documents.tei import TeiParser import os.path import logging @@ -167,7 +168,11 @@ class MetadataFileType(FileType): return config.path_match(ImportType.Metadata, path) and path.endswith('.xml') def handle(self): - logger.warning('Metadata imports are not yet supported') + parser = TeiParser(self.full_path) + matches = parser.match_database(self.flow.dataimport.corpus) + logger.info('Found {} metadatas matching DB'.format(len(matches))) + for db_elt, tei_elt in matches: + tei_elt.save(db_elt, self.flow.dataimport.revision) class ConfigFileType(FileType): diff --git a/arkindex/dataimport/tests/test_filetypes.py b/arkindex/dataimport/tests/test_filetypes.py index 6ea0ffa4ee3f2841fc912d6f1b0c6666192401ab..ea50e78eb9ebca14158ff9d86e6cf9ff6ff7c581 100644 --- a/arkindex/dataimport/tests/test_filetypes.py +++ b/arkindex/dataimport/tests/test_filetypes.py @@ -119,3 +119,16 @@ class TestFileTypes(FixtureTestCase): self.flow.config.path_match.return_value = False self.assertFalse(MetadataFileType.match('path/to/some.xml', self.flow.config)) + + @patch('arkindex.documents.models.Act') + @patch('arkindex.documents.tei.TeiElement') + @patch('arkindex.dataimport.filetypes.TeiParser') + def test_metadata_handle(self, tei_parser_mock, tei_elt_mock, db_elt_mock): + tei_parser_mock().match_database.return_value = [(db_elt_mock(), tei_elt_mock())] + self.flow.config.path_match.return_value = True + metadatas_diff = SimpleDiff(DiffType.Modification, 'a.xml', 'b.xml') + ft = MetadataFileType(self.flow, metadatas_diff) + ft.handle() + self.assertEqual(tei_parser_mock.call_args, call('the/repo/b.xml')) + self.assertEqual(tei_parser_mock().match_database.call_args, call(self.corpus)) + self.assertEqual(tei_elt_mock().save.call_count, 1)