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.out;
|
10
|
|
11
|
import java.sql.SQLException;
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.springframework.stereotype.Component;
|
16
|
import org.springframework.transaction.TransactionStatus;
|
17
|
|
18
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.CreatedAndNotesMapper;
|
19
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbStringMapper;
|
20
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbTimePeriodMapper;
|
21
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.IdMapper;
|
22
|
import eu.etaxonomy.cdm.io.common.IExportConfigurator;
|
23
|
import eu.etaxonomy.cdm.io.common.Source;
|
24
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
25
|
import eu.etaxonomy.cdm.model.agent.Person;
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
|
28
|
|
29
|
/**
|
30
|
* @author a.mueller
|
31
|
* @created 20.03.2008
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
@Component
|
35
|
public class BerlinModelAuthorExport extends BerlinModelExportBase<Person> {
|
36
|
private static final Logger logger = Logger.getLogger(BerlinModelAuthorExport.class);
|
37
|
|
38
|
private static int modCount = 1000;
|
39
|
private static final String dbTableName = "Author";
|
40
|
private static final String pluralString = "Authors";
|
41
|
private static final Class<? extends CdmBase> standardMethodParameter = Person.class;
|
42
|
public BerlinModelAuthorExport(){
|
43
|
super();
|
44
|
}
|
45
|
|
46
|
/* (non-Javadoc)
|
47
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
48
|
*/
|
49
|
@Override
|
50
|
protected boolean doCheck(IExportConfigurator config){
|
51
|
boolean result = true;
|
52
|
logger.warn("Checking for "+pluralString+" not yet implemented");
|
53
|
//result &= checkArticlesWithoutJournal(bmiConfig);
|
54
|
//result &= checkPartOfJournal(bmiConfig);
|
55
|
|
56
|
return result;
|
57
|
}
|
58
|
|
59
|
private BerlinModelExportMapping getMapping(){
|
60
|
String tableName = dbTableName;
|
61
|
BerlinModelExportMapping mapping = new BerlinModelExportMapping(tableName);
|
62
|
mapping.addMapper(IdMapper.NewInstance("AuthorId"));
|
63
|
mapping.addMapper(DbStringMapper.NewInstance("nomenclaturalTitle", "Abbrev"));
|
64
|
mapping.addMapper(DbStringMapper.NewInstance("firstname", "FirstName"));
|
65
|
mapping.addMapper(DbStringMapper.NewInstance("lastname", "LastName"));
|
66
|
mapping.addMapper(DbTimePeriodMapper.NewInstance("lifespan", "Dates"));
|
67
|
|
68
|
//TODO
|
69
|
// mapping.addMapper(DbStringMapper.NewInstance("", "NomStandard"));
|
70
|
// mapping.addMapper(DbStringMapper.NewInstance("", "K?rzel"));
|
71
|
// mapping.addMapper(DbStringMapper.NewInstance("", "DraftK?rz"));
|
72
|
// mapping.addMapper(DbStringMapper.NewInstance("", "Initials"));
|
73
|
|
74
|
mapping.addMapper(CreatedAndNotesMapper.NewInstance());
|
75
|
|
76
|
return mapping;
|
77
|
}
|
78
|
|
79
|
|
80
|
protected boolean doInvoke(BerlinModelExportState<BerlinModelExportConfigurator> state){
|
81
|
try{
|
82
|
BerlinModelExportConfigurator bmeConfig = (BerlinModelExportConfigurator)state.getConfig();
|
83
|
|
84
|
logger.info("start make "+pluralString+" ...");
|
85
|
boolean success = true ;
|
86
|
doDelete(bmeConfig);
|
87
|
|
88
|
TransactionStatus txStatus = startTransaction(true);
|
89
|
Class<Person> clazz = Person.class;
|
90
|
List<? extends Person> persons = getAgentService().list(clazz, 100000000, 0);
|
91
|
|
92
|
BerlinModelExportMapping mapping = getMapping();
|
93
|
mapping.initialize(state);
|
94
|
|
95
|
logger.info("save "+pluralString+" ...");
|
96
|
int count = 0;
|
97
|
for (AgentBase<?> agent : persons){
|
98
|
doCount(count++, modCount, pluralString);
|
99
|
if (agent instanceof Person){
|
100
|
success &= mapping.invoke(agent);
|
101
|
}
|
102
|
}
|
103
|
|
104
|
commitTransaction(txStatus);
|
105
|
logger.info("end make "+pluralString+" ...");
|
106
|
return success;
|
107
|
}catch(SQLException e){
|
108
|
e.printStackTrace();
|
109
|
logger.error(e.getMessage());
|
110
|
return false;
|
111
|
}
|
112
|
}
|
113
|
|
114
|
protected boolean doDelete(BerlinModelExportConfigurator config){
|
115
|
|
116
|
//TODO make more generic for all BerlinModelExport classes
|
117
|
String sql;
|
118
|
Source destination = config.getDestination();
|
119
|
//RelPTaxon
|
120
|
sql = "DELETE FROM RelPTaxon";
|
121
|
destination.setQuery(sql);
|
122
|
destination.update(sql);
|
123
|
//Fact
|
124
|
sql = "DELETE FROM Fact";
|
125
|
destination.setQuery(sql);
|
126
|
destination.update(sql);
|
127
|
//PTaxon
|
128
|
sql = "DELETE FROM PTaxon";
|
129
|
destination.setQuery(sql);
|
130
|
destination.update(sql);
|
131
|
|
132
|
//NameHistory
|
133
|
sql = "DELETE FROM NameHistory";
|
134
|
destination.setQuery(sql);
|
135
|
destination.update(sql);
|
136
|
//RelName
|
137
|
sql = "DELETE FROM RelName";
|
138
|
destination.setQuery(sql);
|
139
|
destination.update(sql);
|
140
|
//NomStatusRel
|
141
|
sql = "DELETE FROM NomStatusRel";
|
142
|
destination.setQuery(sql);
|
143
|
destination.update(sql);
|
144
|
//Name
|
145
|
sql = "DELETE FROM Name";
|
146
|
destination.setQuery(sql);
|
147
|
destination.update(sql);
|
148
|
//RefDetail
|
149
|
sql = "DELETE FROM RefDetail";
|
150
|
destination.setQuery(sql);
|
151
|
destination.update(sql);
|
152
|
//Reference
|
153
|
sql = "DELETE FROM Reference";
|
154
|
destination.setQuery(sql);
|
155
|
destination.update(sql);
|
156
|
//AuthorTeamSequence
|
157
|
sql = "DELETE FROM AuthorTeamSequence";
|
158
|
destination.setQuery(sql);
|
159
|
destination.update(sql);
|
160
|
//AuthorTeam
|
161
|
sql = "DELETE FROM AuthorTeam";
|
162
|
destination.setQuery(sql);
|
163
|
destination.update(sql);
|
164
|
//Author
|
165
|
sql = "DELETE FROM Author";
|
166
|
destination.setQuery(sql);
|
167
|
destination.update(sql);
|
168
|
return true;
|
169
|
}
|
170
|
|
171
|
/* (non-Javadoc)
|
172
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
173
|
*/
|
174
|
protected boolean isIgnore(IExportConfigurator config){
|
175
|
return ! ((BerlinModelExportConfigurator)config).isDoAuthors();
|
176
|
}
|
177
|
|
178
|
/* (non-Javadoc)
|
179
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportBase#getStandardMethodParameter()
|
180
|
*/
|
181
|
@Override
|
182
|
public Class<? extends CdmBase> getStandardMethodParameter() {
|
183
|
return standardMethodParameter;
|
184
|
}
|
185
|
|
186
|
}
|