1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.io.berlinModel.in;
|
10
|
|
11
|
import java.sql.ResultSet;
|
12
|
import java.sql.SQLException;
|
13
|
import java.util.Collection;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.Map;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.springframework.stereotype.Component;
|
19
|
|
20
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
21
|
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelAuthorImportValidator;
|
22
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
23
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
24
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
25
|
import eu.etaxonomy.cdm.model.agent.Person;
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
import eu.etaxonomy.cdm.model.common.Extension;
|
28
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
29
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
30
|
|
31
|
|
32
|
/**
|
33
|
* Supported attributes:
|
34
|
* - AuthorId, Abbrev, FirstName, LastName, Dates, AreaOfInterest, NomStandard, createUpdateNotes
|
35
|
*
|
36
|
* @author a.mueller
|
37
|
* @created 20.03.2008
|
38
|
* @version 1.0
|
39
|
*/
|
40
|
@Component
|
41
|
public class BerlinModelAuthorImport extends BerlinModelImportBase {
|
42
|
private static final Logger logger = Logger.getLogger(BerlinModelAuthorImport.class);
|
43
|
|
44
|
public static final String NAMESPACE = "Author";
|
45
|
|
46
|
private static int recordsPerLog = 5000;
|
47
|
private static final String dbTableName = "Author";
|
48
|
private static final String pluralString = "Authors";
|
49
|
|
50
|
public BerlinModelAuthorImport(){
|
51
|
super();
|
52
|
}
|
53
|
|
54
|
|
55
|
/* (non-Javadoc)
|
56
|
* @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getRecordQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator)
|
57
|
*/
|
58
|
@Override
|
59
|
protected String getRecordQuery(BerlinModelImportConfigurator config) {
|
60
|
String strRecordQuery =
|
61
|
" SELECT * " +
|
62
|
" FROM " + dbTableName + " " +
|
63
|
" WHERE authorId IN ( " + ID_LIST_TOKEN + " )";
|
64
|
return strRecordQuery;
|
65
|
}
|
66
|
|
67
|
|
68
|
/**
|
69
|
* @param partitioner
|
70
|
* @throws SQLException
|
71
|
*/
|
72
|
//TODO public ??
|
73
|
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
74
|
String dbAttrName;
|
75
|
String cdmAttrName;
|
76
|
Map<Integer, Person> personMap = new HashMap<Integer, Person>();
|
77
|
|
78
|
boolean success = true;
|
79
|
ResultSet rs = partitioner.getResultSet();
|
80
|
try{
|
81
|
//for each author
|
82
|
while (rs.next()){
|
83
|
|
84
|
// partitioner.doLogPerLoop(recordsPerLog, pluralString);
|
85
|
|
86
|
//create Agent element
|
87
|
int authorId = rs.getInt("AuthorId");
|
88
|
|
89
|
Person author = Person.NewInstance();
|
90
|
|
91
|
dbAttrName = "Abbrev";
|
92
|
cdmAttrName = "nomenclaturalTitle";
|
93
|
success &= ImportHelper.addStringValue(rs, author, dbAttrName, cdmAttrName);
|
94
|
|
95
|
dbAttrName = "FirstName";
|
96
|
cdmAttrName = "firstname";
|
97
|
success &= ImportHelper.addStringValue(rs, author, dbAttrName, cdmAttrName);
|
98
|
|
99
|
dbAttrName = "LastName";
|
100
|
cdmAttrName = "lastname";
|
101
|
success &= ImportHelper.addStringValue(rs, author, dbAttrName, cdmAttrName);
|
102
|
|
103
|
String dates = rs.getString("dates");
|
104
|
if (dates != null){
|
105
|
dates.trim();
|
106
|
TimePeriod lifespan = TimePeriod.parseString(dates);
|
107
|
author.setLifespan(lifespan);
|
108
|
}
|
109
|
|
110
|
// //AreaOfInterest
|
111
|
String areaOfInterest = rs.getString("AreaOfInterest");
|
112
|
if (CdmUtils.isNotEmpty(areaOfInterest)){
|
113
|
Extension datesExtension = Extension.NewInstance(author, areaOfInterest, ExtensionType.AREA_OF_INTREREST());
|
114
|
}
|
115
|
|
116
|
//nomStandard
|
117
|
String nomStandard = rs.getString("NomStandard");
|
118
|
if (CdmUtils.isNotEmpty(nomStandard)){
|
119
|
Extension nomStandardExtension = Extension.NewInstance(author, nomStandard, ExtensionType.NOMENCLATURAL_STANDARD());
|
120
|
}
|
121
|
//initials
|
122
|
String initials = null;
|
123
|
for (int j = 1; j <= rs.getMetaData().getColumnCount(); j++){
|
124
|
String label = rs.getMetaData().getColumnLabel(j);
|
125
|
if (label.equalsIgnoreCase("Initials") || label.equalsIgnoreCase("K?rzel")){
|
126
|
initials = rs.getString(j);
|
127
|
break;
|
128
|
}
|
129
|
}
|
130
|
if (CdmUtils.isNotEmpty(initials)){
|
131
|
Extension initialsExtension = Extension.NewInstance(author, initials, ExtensionType.ABBREVIATION());
|
132
|
}
|
133
|
|
134
|
//created, notes
|
135
|
doIdCreatedUpdatedNotes(state, author, rs, authorId, NAMESPACE);
|
136
|
|
137
|
personMap.put(authorId, author);
|
138
|
|
139
|
} //while rs.hasNext()
|
140
|
//logger.info("save " + i + " "+pluralString + " ...");
|
141
|
getAgentService().save((Collection)personMap.values());
|
142
|
|
143
|
}catch(Exception ex){
|
144
|
logger.error(ex.getMessage());
|
145
|
ex.printStackTrace();
|
146
|
success = false;
|
147
|
}
|
148
|
return success;
|
149
|
}
|
150
|
|
151
|
/* (non-Javadoc)
|
152
|
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)
|
153
|
*/
|
154
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs) {
|
155
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
|
156
|
// no related objects exist
|
157
|
return result;
|
158
|
}
|
159
|
|
160
|
|
161
|
/* (non-Javadoc)
|
162
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
163
|
*/
|
164
|
@Override
|
165
|
protected boolean doCheck(BerlinModelImportState state){
|
166
|
IOValidator<BerlinModelImportState> validator = new BerlinModelAuthorImportValidator();
|
167
|
return validator.validate(state);
|
168
|
}
|
169
|
|
170
|
|
171
|
/* (non-Javadoc)
|
172
|
* @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getTableName()
|
173
|
*/
|
174
|
@Override
|
175
|
protected String getTableName() {
|
176
|
return dbTableName;
|
177
|
}
|
178
|
|
179
|
|
180
|
/* (non-Javadoc)
|
181
|
* @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getPluralString()
|
182
|
*/
|
183
|
@Override
|
184
|
public String getPluralString() {
|
185
|
return pluralString;
|
186
|
}
|
187
|
|
188
|
/* (non-Javadoc)
|
189
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
190
|
*/
|
191
|
protected boolean isIgnore(BerlinModelImportState state){
|
192
|
return ! state.getConfig().isDoAuthors();
|
193
|
}
|
194
|
|
195
|
}
|