Repository: scieloorg/articles_meta

Issue:
[scieloci] Erro em data de publicação de 
### Descrição do problema

http://articlemeta.scielo.org/api/v1/article/?collection=scl&code=S0001-37652008000100006&format=xmlwos

Gerou year com valor 0000.

```xml
<ref id="B25"><element-citation publication-type="conference"><conf-name>Seminário Internacional de Manejoem Floresta Tropical-SEMA/WWF</conf-name><conf-loc>Serra dos Carajás</conf-loc><source>Presentation</source><date><day>29</day><month>01</month><year>0000</year></date><person-group><name><surname>FEARNSIDE</surname><given-names>PM</given-names></name></person-group></element-citation></ref>
```

No entanto, no registro há a data correta, no campo v64. O correto é usar `raw.publication_date` no lugar de `raw.date` entrega a data de acordo com o tipo de referência bibliográfica, ou seja, se é tese, a data da tese, se é link, a data do acesso, e assim por diante. No entanto, a data que interessa na referência bibliográfica é a data de publicação do documento.

https://github.com/scieloorg/articles_meta/blob/05743b335f07dd97b828c375c5240e2833e58657/articlemeta/export_sci.py#L230



Discussion:

Patch:
diff --git a/articlemeta/export_crossref.py b/articlemeta/export_crossref.py
index 96d23e4..2b42322 100644
--- a/articlemeta/export_crossref.py
+++ b/articlemeta/export_crossref.py
@@ -893,17 +893,19 @@ class XMLCitation(object):
         def precond(data):
             raw, xml = data
 
-            if not raw.date:
+            if not raw.publication_date:
                 raise plumber.UnmetPrecondition()
 
         @plumber.precondition(precond)
         def transform(self, data):
             raw, xml = data
 
-            pdate = ET.Element('cYear')
-            pdate.text = raw.date[0:4]
+            year = raw.publication_date[0:4]
 
-            xml.find('.').append(pdate)
+            if len(year) > 0 and year.isdigit() and int(year) > 0:
+                pdate = ET.Element("cYear")
+                pdate.text = year
+                xml.find(".").append(pdate)
 
             return data
 


Test patch:
diff --git a/tests/test_export_crossref.py b/tests/test_export_crossref.py
index 8577cf9..47eda9f 100644
--- a/tests/test_export_crossref.py
+++ b/tests/test_export_crossref.py
@@ -608,6 +608,37 @@ class ExportCrossRef_one_DOI_only_Tests(unittest.TestCase):
             self.assertIsNotNone(programs)
 
 
+    def test_date_pipe_should_includes_year_when_it_is_valid(self):
+        doi_batch = create_xmlcrossref_with_n_journal_article_element(["pt"])
+        self._raw_json["citations"] = [{"v65": [{"_": "20060320"}]}]
+        article_json = Article(self._raw_json)
+        data = [article_json, doi_batch]
+
+        xmlcrossref = export_crossref.XMLArticleCitationsPipe()
+        raw, xml = xmlcrossref.transform(data)
+
+        self.assertIsNotNone(xml.find(".//citation"))  # ensure citation
+
+        expected_c_year = xml.find(".//cYear")
+
+        self.assertIsNotNone(expected_c_year)
+        self.assertEqual(u"2006", expected_c_year.text)
+
+    def test_date_pipe_should_not_includes_year_when_it_is_zero(self):
+        doi_batch = create_xmlcrossref_with_n_journal_article_element(["pt"])
+        self._raw_json["citations"] = [{"v65": [{"_": "0000"}]}]
+        article_json = Article(self._raw_json)
+        data = [article_json, doi_batch]
+
+        xmlcrossref = export_crossref.XMLArticleCitationsPipe()
+        raw, xml = xmlcrossref.transform(data)
+
+        self.assertIsNotNone(xml.find(".//citation"))  # ensure citation
+
+        not_expected_c_year = xml.find(".//cYear")
+
+        self.assertIsNone(not_expected_c_year)
+
 class ExportCrossRef_MultiLingueDoc_with_MultipleDOI_Tests(unittest.TestCase):
 
     def setUp(self):