def get_xml_data(xml_content, xml_package_name):
    """
    - Obter scielo ID
    - Obter infos de periódico e fascículo
    - Obter nomes dos arquivos ativos digitais
    - Obter nomes dos arquivos PDF
    - Obter idiomas (original e traduções)
    """
    parser = etree.XMLParser(remove_blank_text=True, no_network=True)
    try:
        metadata = SPS_Package(etree.XML(xml_content, parser),
                               xml_package_name)
    except (etree.XMLSyntaxError, TypeError) as exc:
        raise PutXMLInObjectStoreException(
            'Could not get xml data from "{}" : {}'.format(
                xml_package_name, str(exc))) from None
    else:
        pdfs = [{
            "lang": metadata.original_language,
            "filename": "{}.pdf".format(xml_package_name),
            "mimetype": "application/pdf",
        }]
        for lang in metadata.translation_languages:
            pdfs.append({
                "lang": lang,
                "filename": "{}-{}.pdf".format(xml_package_name, lang),
                "mimetype": "application/pdf",
            })

        _xml_data = {
            "scielo_id":
            metadata.scielo_id,
            "issn":
            metadata.issn,
            "year":
            metadata.year,
            "order":
            metadata.order,
            "xml_package_name":
            xml_package_name,
            "assets": [{
                "asset_id": asset_name
            } for asset_name in metadata.assets_names],
            "pdfs":
            pdfs,
        }
        for attr in ["volume", "number", "supplement"]:
            if getattr(metadata, attr) is not None:
                _xml_data[attr] = getattr(metadata, attr)
        return _xml_data
def put_xml_into_object_store(zipfile, xml_filename):
    try:
        xml_file = zipfile.read(xml_filename)
    except KeyError as exc:
        raise PutXMLInObjectStoreException(
            'Could not read file "{}" from zipfile "{}": {}'.format(
                xml_filename, zipfile, exc)) from None
    xml_data = get_xml_data(xml_file, os.path.splitext(xml_filename)[-2])
    Logger.info('Putting XML file "%s" to Object Store', xml_filename)
    xml_data["xml_url"] = put_object_in_object_store(xml_file,
                                                     xml_data["issn"],
                                                     xml_data["scielo_id"],
                                                     xml_filename)
    return xml_data
 def test_register_update_documents_logs_error_if_put_xml_into_object_store_error(
     self,
     MockZipFile,
     MockLogger,
     mk_put_xml_into_object_store,
     mk_put_assets_and_pdfs_in_object_store,
     mk_register_update_doc_into_kernel,
 ):
     MockZipFile.return_value.__enter__.return_value.read.return_value = b""
     mk_put_xml_into_object_store.side_effect = [
         {},
         PutXMLInObjectStoreException("Put Doc in Object Store Error"),
         {},
     ]
     register_update_documents(**self.kwargs)
     MockLogger.error.assert_any_call(
         'Could not put document "%s" in object store: %s',
         self.kwargs["xmls_to_preserve"][1],
         "Put Doc in Object Store Error",
     )