Example #1
0
def register_pid_v3(pid_database_engine, xml_sps):
    pid_v2 = xml_sps.scielo_pid_v2
    pid_v3 = xml_sps.scielo_pid_v3
    pid_prev = xml_sps.aop_pid

    if not pid_v3:
        # procura pid_v3 na base pid_manager
        pid_v3 = (pid_prev and pid_manager.get_pid_v3_by_v2(
            pid_database_engine, pid_prev) or pid_v2
                  and pid_manager.get_pid_v3_by_v2(pid_database_engine, pid_v2)
                  or scielo_ids_generator.generate_scielo_pid())
        xml_sps.scielo_pid_v3 = pid_v3

    # há pid_v3 no XML
    for v2 in (pid_prev, pid_v2):
        if v2:
            record = pid_manager.get_record(pid_database_engine, v2, pid_v3)
            if not record:
                pid_manager.create_pid(pid_database_engine, v2, pid_v3)
    def create_scielo_id(self):
        PATHS = [".//article-meta"]

        def _append_node(parent, new_node):
            node = parent.findall(".//article-id")
            if node:
                parent.insert(parent.index(node[0]), new_node)
            else:
                parent.append(new_node)

        iterators = [self.xmltree.iterfind(path) for path in PATHS]
        for article in itertools.chain(*iterators):

            node = article.findall(".//article-id[@specific-use='scielo']")
            if not node:
                articleId = etree.Element("article-id")
                articleId.set("pub-id-type", "publisher-id")
                articleId.set("specific-use", "scielo")
                articleId.text = scielo_ids_generator.generate_scielo_pid()
                _append_node(article, articleId)

        return self.xmltree
Example #3
0
    def test_generate_scielo_pid(self, mk_uuid4):
        mk_uuid4.return_value = UUID("585b0b68-aa1d-41ab-8f19-aaa37c516337")

        self.assertEqual(scielo_ids_generator.generate_scielo_pid(),
                         "FX6F3cbyYmmwvtGmMB7WCgr")