<commit_before>from copy import deepcopy

from doajtest.fixtures.common import EDITORIAL, SUBJECT, NOTES, OWNER, SEAL

class JournalFixtureFactory(object):
    @staticmethod
    def make_journal_source(in_doaj=False, include_obsolete_fields=False):
        template = deepcopy(JOURNAL_SOURCE)
        if include_obsolete_fields:
            template.update(JOURNAL_OBSOLETE_OA_START)
            template.update(JOURNAL_OA_END)
        template['admin']['in_doaj'] = in_doaj
        return template

    @staticmethod
    def make_many_journal_sources(count=2, in_doaj=False):
        journal_sources = []
        for i in range(0, count):
            template = deepcopy(JOURNAL_SOURCE)
            template['id'] = 'journalid{0}'.format(i)
            # now some very quick and very dirty date generation
            fakemonth = i
            if fakemonth < 1:
                fakemonth = 1
            if fakemonth > 9:
                fakemonth = 9
            template['created_date'] = "2000-0{fakemonth}-01T00:00:00Z".format(fakemonth=fakemonth)
            template['identifier'] = [
                # not really proper ISSN format, but then 1234-5678 is not
                # a correct checksummed ISSN either. Need to write a nicer
                # faker module and just ask it for fake ISSNs, IDs, names, publishers, etc.
                {"type": "pissn", "id": "1234-{0}".format(i)},
                {"type": "eissn", "id": "{0}-5432".format(i)},
            ]
            template['admin']['in_doaj'] = in_doaj
            template['bibjson']['active'] = in_doaj  # legacy field?
            journal_sources.append(deepcopy(template))
        return journal_sources

    @staticmethod
    def make_journal_source_with_legacy_info():
        return deepcopy(JOURNAL_SOURCE_WITH_LEGACY_INFO)

    @staticmethod
    def make_journal_form():
        return deepcopy(JOURNAL_FORM)

    @staticmethod
    def make_journal_form_info():
        return deepcopy(JOURNAL_FORMINFO)

    @staticmethod
    def make_journal_apido_struct():
        return deepcopy(JOURNAL_APIDO_STRUCT)

JOURNAL_SOURCE = {
    "id": "abcdefghijk_journal",
    "created_date": "2000-01-01T00:00:00Z",
    "bibjson": {
        # "active" : true|false,
        "title": "The Title",
        "alternative_title": "Alternative Title",
        "identifier": [
            {"type": "pissn", "id": "1234-5678"},
            {"type": "eissn", "id": "9876-5432"},
        ],
        "keywords": ["word", "key"],
        "language": ["EN", "FR"],
        "country": "US",
        "publisher": "The Publisher",
        "provider": "Platform Host Aggregator",
        "institution": "Society Institution",
        "link": [
            {"type": "homepage", "url": "http://journal.url"},
            {"type": "waiver_policy", "url": "http://waiver.policy"},
            {"type": "editorial_board",
             "url": "http://editorial.board"},
            {"type": "aims_scope", "url": "http://aims.scope"},
            {"type": "author_instructions",
             "url": "http://author.instructions.com"},
            {"type": "oa_statement", "url": "http://oa.statement"}
        ],
        "subject": [
            {"scheme": "LCC", "term": "Economic theory. Demography",
             "code": "HB1-3840"},
            {"scheme": "LCC", "term": "Social Sciences", "code": "H"}
        ],

        "oa_start": {
            "year": "1980",
        },
        "apc_url" : "http://apc.com",
        "apc": {
            "currency": "GBP",
            "average_price": 2
        },
        "submission_charges_url" : "http://submission.com",
        "submission_charges": {
            "currency": "USD",
            "average_price": 4
        },
        "archiving_policy": {
            "policy": [
                "LOCKSS", "CLOCKSS",
                ["A national library", "Trinity"],
                ["Other", "A safe place"]
            ],
            "url": "http://digital.archiving.policy"
        },
        "editorial_review": {
            "process": "Open peer review",
            "url": "http://review.process"
        },
        "plagiarism_detection": {
            "detection": True,
            "url": "http://plagiarism.screening"
        },
        "article_statistics": {
            "statistics": True,
            "url": "http://download.stats"
        },
        "deposit_policy": ["Sherpa/Romeo", "Store it"],
        "author_copyright": {
            "copyright": "Sometimes",
            "url": "http://copyright.com"
        },
        "author_publishing_rights": {
            "publishing_rights": "Occasionally",
            "url": "http://publishing.rights"
        },
        "allows_fulltext_indexing": True,
        "persistent_identifier_scheme": ["DOI", "ARK", "PURL"],
        "format": ["HTML", "XML", "Wordperfect"],
        "publication_time": 8,
        "license": [
            {
                "title": "CC MY",
                "type": "CC MY",
                "url": "http://licence.url",
                "open_access": True,
                "BY": True,
                "NC": True,
                "ND": False,
                "SA": False,
                "embedded": True,
                "embedded_example_url": "http://licence.embedded"
            }
        ]
    },
    "admin": {
        "notes": [
            {"note": "First Note", "date": "2014-05-21T14:02:45Z"},
            {"note": "Second Note", "date": "2014-05-22T00:00:00Z"}
        ],
        "contact": [
            {
                "email": "<EMAIL>",
                "name": "<NAME>"
            }
        ],
        "owner": "Owner",
        "editor_group": "editorgroup",
        "editor": "associate",
        "seal": True
    }
}

JOURNAL_OBSOLETE_OA_START = {
    "bibjson": {
        "oa_start": {
            "volume": "1",
            "number": "1"
        }
    }
}

JOURNAL_OA_END = {
    "bibjson": {
        "oa_end": {
            "volume": "10",
            "number": "10",
            "year": "1985",
        }
    }
}


JOURNAL_SOURCE_WITH_LEGACY_INFO = deepcopy(JOURNAL_SOURCE)
JOURNAL_SOURCE_WITH_LEGACY_INFO['bibjson']["author_pays"] = "Y"
JOURNAL_SOURCE_WITH_LEGACY_INFO['bibjson']["author_pays_url"] = "http://author.pays"
JOURNAL_SOURCE_WITH_LEGACY_INFO['bibjson']["oa_end"] = {}
JOURNAL_SOURCE_WITH_LEGACY_INFO['bibjson']["oa_end"]["year"] = 1991

JOURNAL_INFO = {
    "title": "The Title",
    "url": "http://journal.url",
    "alternative_title": "Alternative Title",
    "pissn": "1234-5678",
    "eissn": "9876-5432",
    "publisher": "The Publisher",
    "society_institution": "Society Institution",
    "platform": "Platform Host Aggregator",
    "contact_name": "<NAME>",<commit_msg>fix obscure xwalk form failure<commit_after>from copy import deepcopy

from doajtest.fixtures.common import EDITORIAL, SUBJECT, NOTES, OWNER, SEAL

class JournalFixtureFactory(object):
    @staticmethod
    def make_journal_source(in_doaj=False, include_obsolete_fields=False):
        template = deepcopy(JOURNAL_SOURCE)
        if include_obsolete_fields:
            template.update(JOURNAL_OBSOLETE_OA_START)
            template.update(JOURNAL_OA_END)
        template['admin']['in_doaj'] = in_doaj
        return template

    @staticmethod
    def make_many_journal_sources(count=2, in_doaj=False):
        journal_sources = []
        for i in range(0, count):
            template = deepcopy(JOURNAL_SOURCE)
            template['id'] = 'journalid{0}'.format(i)
            # now some very quick and very dirty date generation
            fakemonth = i
            if fakemonth < 1:
                fakemonth = 1
            if fakemonth > 9:
                fakemonth = 9
            template['created_date'] = "2000-0{fakemonth}-01T00:00:00Z".format(fakemonth=fakemonth)
            template['identifier'] = [
                # not really proper ISSN format, but then 1234-5678 is not
                # a correct checksummed ISSN either. Need to write a nicer
                # faker module and just ask it for fake ISSNs, IDs, names, publishers, etc.
                {"type": "pissn", "id": "1234-{0}".format(i)},
                {"type": "eissn", "id": "{0}-5432".format(i)},
            ]
            template['admin']['in_doaj'] = in_doaj
            template['bibjson']['active'] = in_doaj  # legacy field?
            journal_sources.append(deepcopy(template))
        return journal_sources

    @staticmethod
    def make_journal_source_with_legacy_info():
        return deepcopy(JOURNAL_SOURCE_WITH_LEGACY_INFO)

    @staticmethod
    def make_journal_form():
        return deepcopy(JOURNAL_FORM)

    @staticmethod
    def make_journal_form_info():
        return deepcopy(JOURNAL_FORMINFO)

    @staticmethod
    def make_journal_apido_struct():
        return deepcopy(JOURNAL_APIDO_STRUCT)

JOURNAL_SOURCE = {
    "id": "abcdefghijk_journal",
    "created_date": "2000-01-01T00:00:00Z",
    "bibjson": {
        # "active" : true|false,
        "title": "The Title",
        "alternative_title": "Alternative Title",
        "identifier": [
            {"type": "pissn", "id": "1234-5678"},
            {"type": "eissn", "id": "9876-5432"},
        ],
        "keywords": ["word", "key"],
        "language": ["EN", "FR"],
        "country": "US",
        "publisher": "The Publisher",
        "provider": "Platform Host Aggregator",
        "institution": "Society Institution",
        "link": [
            {"type": "homepage", "url": "http://journal.url"},
            {"type": "waiver_policy", "url": "http://waiver.policy"},
            {"type": "editorial_board",
             "url": "http://editorial.board"},
            {"type": "aims_scope", "url": "http://aims.scope"},
            {"type": "author_instructions",
             "url": "http://author.instructions.com"},
            {"type": "oa_statement", "url": "http://oa.statement"}
        ],
        "subject": [
            {"scheme": "LCC", "term": "Economic theory. Demography",
             "code": "HB1-3840"},
            {"scheme": "LCC", "term": "Social Sciences", "code": "H"}
        ],

        "oa_start": {
            "year": 1980,
        },
        "apc_url" : "http://apc.com",
        "apc": {
            "currency": "GBP",
            "average_price": 2
        },
        "submission_charges_url" : "http://submission.com",
        "submission_charges": {
            "currency": "USD",
            "average_price": 4
        },
        "archiving_policy": {
            "policy": [
                "LOCKSS", "CLOCKSS",
                ["A national library", "Trinity"],
                ["Other", "A safe place"]
            ],
            "url": "http://digital.archiving.policy"
        },
        "editorial_review": {
            "process": "Open peer review",
            "url": "http://review.process"
        },
        "plagiarism_detection": {
            "detection": True,
            "url": "http://plagiarism.screening"
        },
        "article_statistics": {
            "statistics": True,
            "url": "http://download.stats"
        },
        "deposit_policy": ["Sherpa/Romeo", "Store it"],
        "author_copyright": {
            "copyright": "Sometimes",
            "url": "http://copyright.com"
        },
        "author_publishing_rights": {
            "publishing_rights": "Occasionally",
            "url": "http://publishing.rights"
        },
        "allows_fulltext_indexing": True,
        "persistent_identifier_scheme": ["DOI", "ARK", "PURL"],
        "format": ["HTML", "XML", "Wordperfect"],
        "publication_time": 8,
        "license": [
            {
                "title": "CC MY",
                "type": "CC MY",
                "url": "http://licence.url",
                "open_access": True,
                "BY": True,
                "NC": True,
                "ND": False,
                "SA": False,
                "embedded": True,
                "embedded_example_url": "http://licence.embedded"
            }
        ]
    },
    "admin": {
        "notes": [
            {"note": "First Note", "date": "2014-05-21T14:02:45Z"},
            {"note": "Second Note", "date": "2014-05-22T00:00:00Z"}
        ],
        "contact": [
            {
                "email": "<EMAIL>",
                "name": "<NAME>"
            }
        ],
        "owner": "Owner",
        "editor_group": "editorgroup",
        "editor": "associate",
        "seal": True
    }
}

JOURNAL_OBSOLETE_OA_START = {
    "bibjson": {
        "oa_start": {
            "volume": "1",
            "number": "1",
            "year": "1980",  # some journals do have those as strings in live
        }
    }
}

JOURNAL_OA_END = {
    "bibjson": {
        "oa_end": {
            "volume": "10",
            "number": "10",
            "year": "1985",
        }
    }
}


JOURNAL_SOURCE_WITH_LEGACY_INFO = deepcopy(JOURNAL_SOURCE)
JOURNAL_SOURCE_WITH_LEGACY_INFO['bibjson']["author_pays"] = "Y"
JOURNAL_SOURCE_WITH_LEGACY_INFO['bibjson']["author_pays_url"] = "http://author.pays"
JOURNAL_SOURCE_WITH_LEGACY_INFO['bibjson']["oa_end"] = {}
JOURNAL_SOURCE_WITH_LEGACY_INFO['bibjson']["oa_end"]["year"] = 1991

JOURNAL_INFO = {
    "title": "The Title",
    "url": "http://journal.url",
    "alternative_title": "Alternative Title",
    "pissn": "1234-5678",
    "eissn": "9876-5432",
    "publisher": "The Publisher",
    "society_institution": "Society Institution",
    "platform": "Platform Host Aggregator",
    "contact_name": "<NAME>",
{'fraction_non_alphanumeric': 0.15797273266152934, 'fraction_numerical': 0.02074688796680498, 'mean_word_length': 1.9781553398058251, 'pattern_counts': {'":': 227, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3601206', 'n_tokens_mistral': 4512, 'n_tokens_neox': 4219, 'n_words': 794}