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
.Reference
;
24 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
31 public class MexicoEfloraRefOtherBooksImport
extends MexicoEfloraReferenceImportBase
{
33 private static final long serialVersionUID
= -1186364983750790695L;
34 private static final Logger logger
= Logger
.getLogger(MexicoEfloraRefOtherBooksImport
.class);
36 private static final String pluralString
= "Other books";
37 private static final String dbTableName
= "RefOtherBooks";
39 public MexicoEfloraRefOtherBooksImport(){
40 super(dbTableName
, pluralString
);
44 public boolean doPartition(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner
, MexicoEfloraImportState state
) {
46 boolean success
= true ;
47 Set
<Reference
> refsToSave
= new HashSet
<>();
49 ResultSet rs
= partitioner
.getResultSet();
53 // if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("PTaxa handled: " + (i-1));}
55 //create TaxonName element
56 String type
= rs
.getString("PubType");
57 int refId
= rs
.getInt("CONABIO-BIB-ID");
58 String authorStr
= rs
.getString("Author");
59 String yearStr
= rs
.getString("Year");
60 String titleStr
= rs
.getString("Title");
61 String volumeStr
= rs
.getString("Volume");
62 String pagesStr
= rs
.getString("Pages");
63 //exported as Excel table
64 // String observacionesStr = rs.getString("Observaciones");
65 String urlStr
= rs
.getString("URL");
66 String doiStr
= rs
.getString("DOI");
67 String isbnStr
= rs
.getString("ISBN");
70 Reference ref
= ReferenceFactory
.newBook();
72 if (!"B".equals(type
)) {
73 logger
.warn(refId
+ ": Type not 'B'");
77 handleAuthorStr(state
, authorStr
, ref
, refId
);
80 handleYearStr(state
, yearStr
, ref
, refId
);
83 handleTitleStr(state
, titleStr
, ref
, refId
);
86 if (isNotBlank(pagesStr
)) {
87 ref
.setPages(pagesStr
);
91 if (isNotBlank(volumeStr
)) {
92 ref
.setVolume(volumeStr
);
94 logger
.info(refId
+ ": No volume");
98 handleUrlStr(state
, urlStr
, ref
, refId
);
101 handleDoiStr(state
, doiStr
, ref
, refId
);
104 if (isNotBlank(isbnStr
) && !"NA".equals(isbnStr
)) {
105 if (isbnStr
.startsWith("ISBN:")) {
106 isbnStr
= isbnStr
.replace("ISBN:", "").trim();
107 }else if (isbnStr
.startsWith("ISSN ")) {
108 isbnStr
= isbnStr
.replace("ISSN ", "").trim();
110 ref
.setIsbn(isbnStr
);
113 //register id and make import source
114 handleId(state
, refId
, ref
);
116 partitioner
.startDoSave();
118 } catch (Exception e
) {
119 logger
.warn("An exception (" +e
.getMessage()+") occurred when creating reference with id " + refId
+ ". Reference could not be saved.");
123 } catch (Exception e
) {
124 logger
.error("SQLException:" + e
);
128 getReferenceService().save(refsToSave
);
133 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
, MexicoEfloraImportState state
) {
135 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
140 protected String
getTableName() {
145 public String
getPluralString() {