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.
9 package eu
.etaxonomy
.cdm
.io
.mexico
;
11 import java
.sql
.ResultSet
;
12 import java
.util
.HashMap
;
13 import java
.util
.HashSet
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.springframework
.stereotype
.Component
;
20 import eu
.etaxonomy
.cdm
.common
.URI
;
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 MexicoEfloraRefWebSitesImport
extends MexicoEfloraReferenceImportBase
{
33 private static final long serialVersionUID
= -1186364983750790695L;
34 private static final Logger logger
= Logger
.getLogger(MexicoEfloraRefWebSitesImport
.class);
36 private static final String pluralString
= "Websites";
37 private static final String dbTableName
= "RefWebSites";
39 public MexicoEfloraRefWebSitesImport(){
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 urlStr
= rs
.getString("URL");
62 String issnStr
= rs
.getString("ISBN");
65 Reference ref
= ReferenceFactory
.newBook();
67 if (!"B".equals(type
)) {
68 logger
.warn(refId
+ ": Type not 'B'");
72 handleAuthorStr(state
, authorStr
, ref
, refId
);
75 handleYearStr(state
, yearStr
, ref
, refId
);
78 handleTitleStr(state
, titleStr
, ref
, refId
);
81 if (isNotBlank(urlStr
)) {
84 uri
= URI
.fromString(urlStr
);
86 } catch (Exception e
) {
87 logger
.warn(refId
+ ": parse exception for " + urlStr
);
90 //do not report anymore, is in doc file already
91 logger
.info(refId
+ ": No uri");
95 if (isNotBlank(issnStr
) && !"NA".equals(issnStr
)) {
96 if (issnStr
.startsWith("ISSN ")) {
97 issnStr
= issnStr
.replace("ISSN ", "").trim();
102 //register id and make import source
103 handleId(state
, refId
, ref
);
105 partitioner
.startDoSave();
107 } catch (Exception e
) {
108 logger
.warn("An exception (" +e
.getMessage()+") occurred when creating reference with id " + refId
+ ". Reference could not be saved.");
112 } catch (Exception e
) {
113 logger
.error("SQLException:" + e
);
117 getReferenceService().save(refsToSave
);
122 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
, MexicoEfloraImportState state
) {
124 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
129 protected String
getTableName() {
134 public String
getPluralString() {