2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.io
.mexico
;
12 import java
.sql
.ResultSet
;
13 import java
.util
.HashMap
;
14 import java
.util
.HashSet
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.springframework
.stereotype
.Component
;
21 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
22 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
23 import eu
.etaxonomy
.cdm
.model
.reference
.IJournal
;
24 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
32 public class MexicoEfloraRefArticlesImport
extends MexicoEfloraReferenceImportBase
{
34 private static final long serialVersionUID
= -1186364983750790695L;
36 private static final Logger logger
= Logger
.getLogger(MexicoEfloraRefArticlesImport
.class);
38 private static final String pluralString
= "Articles";
39 private static final String dbTableName
= "RefArticles";
40 private static final Map
<String
,IJournal
> journalMap
= new HashMap
<>();
42 public MexicoEfloraRefArticlesImport(){
43 super(dbTableName
, pluralString
);
47 public boolean doPartition(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner
, MexicoEfloraImportState state
) {
49 boolean success
= true ;
50 Set
<Reference
> refsToSave
= new HashSet
<>();
52 ResultSet rs
= partitioner
.getResultSet();
56 // if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("PTaxa handled: " + (i-1));}
58 //create TaxonName element
59 int refId
= rs
.getInt("CONABIO-BIB-ID");
60 String type
= rs
.getString("PubType");
61 String authorStr
= rs
.getString("Author");
62 String yearStr
= rs
.getString("Year");
63 String articleTitleStr
= rs
.getString("ArticleTitle");
64 String journalTitleStr
= rs
.getString("JournalTitle");
65 String concat
= rs
.getString("Concatenation");
66 //TODO _minor V and P in articles
67 String vStr
= rs
.getString("V");
68 String pStr
= rs
.getString("P");
69 String urlStr
= rs
.getString("URL");
70 String doiStr
= rs
.getString("DOI");
71 String issnStr
= rs
.getString("ISSN");
74 Reference ref
= ReferenceFactory
.newArticle();
76 if (!"A".equals(type
)) {
77 logger
.warn(refId
+ ": Type not 'A'");
81 handleAuthorStr(state
, authorStr
, ref
, refId
);
84 handleYearStr(state
, yearStr
, ref
, refId
);
87 handleTitleStr(state
, articleTitleStr
, ref
, refId
);
90 if (isNotBlank(journalTitleStr
)) {
92 IJournal journal
= journalMap
.get(journalTitleStr
);
93 if (journal
== null) {
94 journal
= ReferenceFactory
.newJournal();
95 journal
.setTitle(journalTitleStr
);
96 journalMap
.put(journalTitleStr
, journal
);
99 ref
.setInJournal(journal
);
101 logger
.warn(refId
+ ": No journal title");
105 if (isNotBlank(concat
)) {
106 String
[] split
= concat
.split(":");
107 String volume
= split
[0];
108 ref
.setVolume(volume
);
109 if (split
.length
> 1) {
110 String pages
= split
[1];
114 logger
.info(refId
+ ": No volume");
118 handleUrlStr(state
, urlStr
, ref
, refId
);
121 handleDoiStr(state
, doiStr
, ref
, refId
);
124 if (isNotBlank(issnStr
) && !"NA".equals(issnStr
)) {
125 if (issnStr
.startsWith("ISSN:")) {
126 issnStr
= issnStr
.replace("ISSN:", "").trim();
127 }else if (issnStr
.startsWith("ISSN ")) {
128 issnStr
= issnStr
.replace("ISSN ", "").trim();
130 ref
.getInJournal().setIssn(issnStr
);
133 //register id and make import source
134 handleId(state
, refId
, ref
);
136 partitioner
.startDoSave();
138 } catch (Exception e
) {
139 logger
.warn("An exception (" +e
.getMessage()+") occurred when creating reference with id " + refId
+ ". Reference could not be saved.");
143 } catch (Exception e
) {
144 logger
.error("SQLException:" + e
);
148 getReferenceService().save(refsToSave
);
154 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
, MexicoEfloraImportState state
) {
156 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
161 protected String
getTableName() {
166 public String
getPluralString() {