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
.berlinModel
.in
;
11 import java
.sql
.ResultSet
;
12 import java
.sql
.SQLException
;
13 import java
.util
.Collection
;
14 import java
.util
.HashMap
;
17 import org
.apache
.commons
.lang
.StringUtils
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.springframework
.stereotype
.Component
;
21 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
22 import eu
.etaxonomy
.cdm
.io
.berlinModel
.in
.validation
.BerlinModelAuthorImportValidator
;
23 import eu
.etaxonomy
.cdm
.io
.common
.IOValidator
;
24 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
25 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
27 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.Extension
;
29 import eu
.etaxonomy
.cdm
.model
.common
.ExtensionType
;
30 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
34 * Supported attributes:
35 * - AuthorId, Abbrev, FirstName, LastName, Dates, AreaOfInterest, NomStandard, createUpdateNotes
42 public class BerlinModelAuthorImport
extends BerlinModelImportBase
{
43 private static final boolean BLANK_TO_NULL
= true;
45 private static final Logger logger
= Logger
.getLogger(BerlinModelAuthorImport
.class);
47 public static final String NAMESPACE
= "Author";
49 private static int recordsPerLog
= 5000;
50 private static final String dbTableName
= "Author";
51 private static final String pluralString
= "Authors";
53 public BerlinModelAuthorImport(){
58 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getIdQuery()
61 protected String
getIdQuery(BerlinModelImportState state
) {
62 String result
= " SELECT authorId FROM " + getTableName();
63 if (StringUtils
.isNotBlank(state
.getConfig().getAuthorFilter())){
64 result
+= " WHERE " + state
.getConfig().getAuthorFilter();
70 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getRecordQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator)
73 protected String
getRecordQuery(BerlinModelImportConfigurator config
) {
74 String strRecordQuery
=
76 " FROM " + dbTableName
+ " " +
77 " WHERE authorId IN ( " + ID_LIST_TOKEN
+ " )";
78 return strRecordQuery
;
84 * @throws SQLException
87 public boolean doPartition(ResultSetPartitioner partitioner
, BerlinModelImportState state
) {
90 Map
<Integer
, Person
> personMap
= new HashMap
<Integer
, Person
>();
92 boolean success
= true;
93 ResultSet rs
= partitioner
.getResultSet();
98 // partitioner.doLogPerLoop(recordsPerLog, pluralString);
100 //create Agent element
101 int authorId
= rs
.getInt("AuthorId");
103 Person author
= Person
.NewInstance();
105 dbAttrName
= "Abbrev";
106 cdmAttrName
= "nomenclaturalTitle";
107 success
&= ImportHelper
.addStringValue(rs
, author
, dbAttrName
, cdmAttrName
, BLANK_TO_NULL
);
109 dbAttrName
= "FirstName";
110 cdmAttrName
= "firstname";
111 success
&= ImportHelper
.addStringValue(rs
, author
, dbAttrName
, cdmAttrName
, BLANK_TO_NULL
);
113 dbAttrName
= "LastName";
114 cdmAttrName
= "lastname";
115 success
&= ImportHelper
.addStringValue(rs
, author
, dbAttrName
, cdmAttrName
, BLANK_TO_NULL
);
117 String dates
= rs
.getString("dates");
120 TimePeriod lifespan
= TimePeriod
.parseString(dates
);
121 author
.setLifespan(lifespan
);
125 String areaOfInterest
= rs
.getString("AreaOfInterest");
126 if (CdmUtils
.isNotEmpty(areaOfInterest
)){
127 Extension datesExtension
= Extension
.NewInstance(author
, areaOfInterest
, ExtensionType
.AREA_OF_INTREREST());
131 String nomStandard
= rs
.getString("NomStandard");
132 if (CdmUtils
.isNotEmpty(nomStandard
)){
133 Extension nomStandardExtension
= Extension
.NewInstance(author
, nomStandard
, ExtensionType
.NOMENCLATURAL_STANDARD());
136 String initials
= null;
137 for (int j
= 1; j
<= rs
.getMetaData().getColumnCount(); j
++){
138 String label
= rs
.getMetaData().getColumnLabel(j
);
139 if (label
.equalsIgnoreCase("Initials") || label
.equalsIgnoreCase("Kürzel")){
140 initials
= rs
.getString(j
);
144 if (CdmUtils
.isNotEmpty(initials
)){
145 Extension initialsExtension
= Extension
.NewInstance(author
, initials
, ExtensionType
.ABBREVIATION());
149 doIdCreatedUpdatedNotes(state
, author
, rs
, authorId
, NAMESPACE
);
151 personMap
.put(authorId
, author
);
153 } //while rs.hasNext()
154 //logger.info("save " + i + " "+pluralString + " ...");
155 getAgentService().save((Collection
)personMap
.values());
157 }catch(Exception ex
){
158 logger
.error(ex
.getMessage());
159 ex
.printStackTrace();
166 * @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)
168 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
) {
169 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<Object
, Map
<String
, ?
extends CdmBase
>>();
170 // no related objects exist
176 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
179 protected boolean doCheck(BerlinModelImportState state
){
180 IOValidator
<BerlinModelImportState
> validator
= new BerlinModelAuthorImportValidator();
181 return validator
.validate(state
);
186 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getTableName()
189 protected String
getTableName() {
195 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getPluralString()
198 public String
getPluralString() {
203 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
205 protected boolean isIgnore(BerlinModelImportState state
){
206 return ! state
.getConfig().isDoAuthors();