def issue_to_kernel(issue):
    """Transforma um objeto Issue (xylose) para o formato
    de dados equivalente ao persistido pelo Kernel em um banco
    mongodb"""

    issn_id = issue.data["issue"]["v35"][0]["_"]
    _creation_date = parse_date(issue.publication_date)
    _metadata = {}
    _bundle = {
        "created": _creation_date,
        "updated": _creation_date,
        "items": [],
        "metadata": _metadata,
    }

    _year = str(date_to_datetime(_creation_date).year)
    _month = str(date_to_datetime(_creation_date).month)
    _metadata["publication_year"] = set_metadata(_creation_date, _year)

    if issue.volume:
        _metadata["volume"] = set_metadata(_creation_date, issue.volume)

    if issue.number:
        _metadata["number"] = set_metadata(_creation_date, issue.number)

    _supplement = None
    if issue.type is "supplement":
        _supplement = "0"

        if issue.supplement_volume:
            _supplement = issue.supplement_volume
        elif issue.supplement_number:
            _supplement = issue.supplement_number

        _metadata["supplement"] = set_metadata(_creation_date, _supplement)

    if issue.titles:
        _titles = [{
            "language": lang,
            "value": value
        } for lang, value in issue.titles.items()]
        _metadata["titles"] = set_metadata(_creation_date, _titles)

    publication_months = {}
    if issue.start_month and issue.end_month:
        publication_months["range"] = (int(issue.start_month),
                                       int(issue.end_month))
    elif _month:
        publication_months["month"] = int(_month)

    _metadata["publication_months"] = set_metadata(_creation_date,
                                                   publication_months)

    _id = scielo_ids_generator.issue_id(issn_id, _year, issue.volume,
                                        issue.number, _supplement)
    _bundle["_id"] = _id
    _bundle["id"] = _id

    return _bundle
예제 #2
0
 def test_issn_year_volume_suppl(self):
     self.assertEqual(
         scielo_ids_generator.issue_id("ISSN",
                                       "YEAR",
                                       "VOLUME",
                                       supplement="SUPPL"),
         "ISSN-YEAR-vVOLUME-sSUPPL",
     )
예제 #3
0
 def test_issue_id_returns_ISSN_YEAR_NUM_and_no_vol_because_it_is_00(self):
     self.assertEqual(
         scielo_ids_generator.issue_id("ISSN",
                                       "YEAR",
                                       volume="00",
                                       number="19"),
         "ISSN-YEAR-n19",
     )
def get_documents_bundle(session_db, data):
    issns = list(
        set([
            data[issn_type] for issn_type in ("eissn", "pissn", "issn")
            if data.get(issn_type)
        ]))
    is_issue = data.get("volume") or data.get("number")
    bad_bundle_id = []
    for issn in issns:
        if is_issue:
            bundle_id = scielo_ids_generator.issue_id(
                issn,
                data.get("year"),
                data.get("volume"),
                data.get("number"),
                data.get("supplement"),
            )
        else:
            bundle_id = scielo_ids_generator.aops_bundle_id(issn)
        logger.debug("Fetch documents bundle {}".format(bundle_id))
        try:
            documents_bundle = session_db.documents_bundles.fetch(bundle_id)
        except DoesNotExist:
            bad_bundle_id.append(bundle_id)
        else:
            return documents_bundle
    if is_issue:
        raise ValueError("Nenhum documents_bundle encontrado %s" %
                         ", ".join(bad_bundle_id))
    else:
        bad_issn = []
        for issn in issns:
            try:
                documents_bundle = create_aop_bundle(session_db, issn)
            except DoesNotExist:
                bad_issn.append(issn)
            else:
                return documents_bundle
        raise ValueError("Nenhum periódico encontrado para criação do AOP %s" %
                         ", ".join(bad_issn))
예제 #5
0
 def test_issn_year_number(self):
     self.assertEqual(
         scielo_ids_generator.issue_id("ISSN", "YEAR", number="03"),
         "ISSN-YEAR-n3",
     )
예제 #6
0
 def test_issn_year_volume(self):
     self.assertEqual(
         scielo_ids_generator.issue_id("ISSN", "YEAR", "VOLUME"),
         "ISSN-YEAR-vVOLUME",
     )
def register_documents_in_documents_bundle(session_db, file_documents: str,
                                           file_journals: str) -> None:

    err_filename = os.path.join(config.get("ERRORS_PATH"),
                                "insert_documents_in_bundle.err")

    not_registered = []
    journals = reading.read_json_file(file_journals)
    documents = reading.read_json_file(file_documents)

    data_journal = {}
    for journal in journals:
        o_journal = Journal(journal)
        if o_journal.print_issn:
            data_journal[o_journal.print_issn] = o_journal.scielo_issn
        if o_journal.electronic_issn:
            data_journal[o_journal.electronic_issn] = o_journal.scielo_issn
        if o_journal.scielo_issn:
            data_journal[o_journal.scielo_issn] = o_journal.scielo_issn

    documents_bundles = {}
    for scielo_id, document in documents.items():
        is_issue = bool(document.get("volume") or document.get("number"))

        issn = ""
        for issn_type in ("eissn", "pissn", "issn"):
            issn = document.get(issn_type)
            if issn: break

        if is_issue:
            bundle_id = scielo_ids_generator.issue_id(
                data_journal[issn],
                document.get("year"),
                document.get("volume"),
                document.get("number"),
                document.get("supplement"),
            )
        else:
            bundle_id = scielo_ids_generator.aops_bundle_id(data_journal[issn])

        documents_bundles.setdefault(bundle_id, {})
        documents_bundles[bundle_id].setdefault("items", [])

        documents_bundles[bundle_id]["items"].append({
            "id":
            scielo_id,
            "order":
            document.get("order", ""),
        })
        documents_bundles[bundle_id]["data"] = {
            "is_issue": is_issue,
            "bundle_id": bundle_id,
            "issn": data_journal[document.get("issn")],
        }

    for documents_bundle in documents_bundles.values():

        data = documents_bundle["data"]
        items = documents_bundle["items"]
        try:
            documents_bundle = get_documents_bundle(session_db,
                                                    data["bundle_id"],
                                                    data["is_issue"],
                                                    data["issn"])
        except ValueError as error:
            files.write_file(err_filename, data["bundle_id"] + "\n", "a")
            not_registered.append(data["bundle_id"])
        else:
            link_documents_bundles_with_documents(documents_bundle, items,
                                                  session_db)
예제 #8
0
 def test_issue_id_raises_value_error_because_vol_00_and_num_00(self):
     with self.assertRaises(scielo_ids_generator.NotAnIssueError):
         scielo_ids_generator.issue_id("ISSN",
                                       "YEAR",
                                       volume="00",
                                       number="00")