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
.sql
.SQLException
;
14 import java
.util
.HashMap
;
15 import java
.util
.HashSet
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.springframework
.stereotype
.Component
;
22 import eu
.etaxonomy
.cdm
.io
.berlinModel
.in
.BerlinModelReferenceImport
;
23 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
24 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
33 public class MexicoEfloraRefOtherBooksImport
extends MexicoEfloraReferenceImportBase
{
35 private static final long serialVersionUID
= -1186364983750790695L;
36 private static final Logger logger
= Logger
.getLogger(MexicoEfloraRefOtherBooksImport
.class);
38 public static final String NAMESPACE
= "OtherBooks";
40 private static final String pluralString
= "Other books";
41 private static final String dbTableName
= "RefOtherBooks";
43 public MexicoEfloraRefOtherBooksImport(){
44 super(dbTableName
, pluralString
);
48 public boolean doPartition(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner
, MexicoEfloraImportState state
) {
50 boolean success
= true ;
51 MexicoEfloraImportConfigurator config
= state
.getConfig();
52 Set
<Reference
> refsToSave
= new HashSet
<>();
54 @SuppressWarnings("unchecked")
55 Map
<String
, Reference
> refMap
= partitioner
.getObjectMap(BerlinModelReferenceImport
.REFERENCE_NAMESPACE
);
57 ResultSet rs
= partitioner
.getResultSet();
61 // if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("PTaxa handled: " + (i-1));}
63 //create TaxonName element
64 String type
= rs
.getString("PubType");
65 int refId
= rs
.getInt("CONABIO-BIB-ID");
66 String authorStr
= rs
.getString("Author");
67 String yearStr
= rs
.getString("Year");
68 String titleStr
= rs
.getString("Title");
69 String volumeStr
= rs
.getString("Volume");
70 String pagesStr
= rs
.getString("Pages");
71 String observacionesStr
= rs
.getString("Observaciones");
72 String urlStr
= rs
.getString("URL");
73 String doiStr
= rs
.getString("DOI");
74 String isbnStr
= rs
.getString("ISBN");
77 Reference ref
= ReferenceFactory
.newBook();
79 if (!"B".equals(type
)) {
80 logger
.warn(refId
+ ": Type not 'B'");
84 handleAuthorStr(state
, authorStr
, ref
, refId
);
87 handleYearStr(state
, yearStr
, ref
, refId
);
90 handleTitleStr(state
, titleStr
, ref
, refId
);
93 if (isNotBlank(volumeStr
)) {
94 ref
.setVolume(volumeStr
);
96 logger
.info(refId
+ ": No volume");
100 handleUrlStr(state
, urlStr
, ref
, refId
);
103 handleDoiStr(state
, doiStr
, ref
, refId
);
106 if (isNotBlank(isbnStr
) && !"NA".equals(isbnStr
)) {
107 if (isbnStr
.startsWith("ISBN:")) {
108 isbnStr
= isbnStr
.replace("ISBN:", "").trim();
109 }else if (isbnStr
.startsWith("ISSN ")) {
110 isbnStr
= isbnStr
.replace("ISSN ", "").trim();
112 ref
.setIsbn(isbnStr
);
115 //register id and make import source
116 handleId(state
, refId
, ref
, null);
118 partitioner
.startDoSave();
120 } catch (Exception e
) {
121 logger
.warn("An exception (" +e
.getMessage()+") occurred when creating reference with id " + refId
+ ". Reference could not be saved.");
125 } catch (Exception e
) {
126 logger
.error("SQLException:" + e
);
130 getReferenceService().save(refsToSave
);
135 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
, MexicoEfloraImportState state
) {
139 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
142 Set
<String
> nameIdSet
= new HashSet
<>();
143 Set
<String
> referenceIdSet
= new HashSet
<>();
145 // handleForeignKey(rs, nameIdSet, "PTNameFk");
146 // handleForeignKey(rs, referenceIdSet, "PTRefFk");
150 nameSpace
= BerlinModelReferenceImport
.REFERENCE_NAMESPACE
;
151 idSet
= referenceIdSet
;
152 Map
<String
, Reference
> referenceMap
= getCommonService().getSourcedObjectsByIdInSourceC(Reference
.class, idSet
, nameSpace
);
153 result
.put(nameSpace
, referenceMap
);
155 } catch (SQLException e
) {
156 throw new RuntimeException(e
);
162 protected String
getTableName() {
167 public String
getPluralString() {