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.DbBooleanMapper;
|
20
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.IdMapper;
|
21
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.MethodMapper;
|
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.Team;
|
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 BerlinModelAuthorTeamExport extends BerlinModelExportBase {
|
36
|
private static final Logger logger = Logger.getLogger(BerlinModelAuthorTeamExport.class);
|
37
|
|
38
|
private static int modCount = 1000;
|
39
|
private static final String dbTableName = "AuthorTeam";
|
40
|
private static final String pluralString = "AuthorTeams";
|
41
|
private static final Class<? extends CdmBase> standardMethodParameter = Team.class;
|
42
|
public BerlinModelAuthorTeamExport(){
|
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("AuthorTeamId"));
|
63
|
mapping.addMapper(MethodMapper.NewInstance("AuthorTeamCache", this));
|
64
|
mapping.addMapper(MethodMapper.NewInstance("FullAuthorTeamCache", this));
|
65
|
//mapping.addMapper(new DbStringMapper("infraGenericEpithet", "GenusSubDivisionEpi"));
|
66
|
mapping.addMapper(DbBooleanMapper.NewFalseInstance("isProtectedTitleCache", "PreliminaryFlag"));
|
67
|
mapping.addMapper(CreatedAndNotesMapper.NewInstance());
|
68
|
|
69
|
|
70
|
// Team n = null;
|
71
|
//n.isProtectedTitleCache()
|
72
|
return mapping;
|
73
|
}
|
74
|
|
75
|
|
76
|
protected boolean doInvoke(BerlinModelExportState<BerlinModelExportConfigurator> state){
|
77
|
//MapWrapper<AgentBase> teamMap = (MapWrapper<AgentBase>)stores.get(ICdmIO.AUTHOR_STORE);
|
78
|
//MapWrapper<AgentBase> teamMap = (MapWrapper<AgentBase>)stores.get(ICdmIO.AUTHOR_STORE);
|
79
|
|
80
|
try{
|
81
|
BerlinModelExportConfigurator bmeConfig = (BerlinModelExportConfigurator)state.getConfig();
|
82
|
|
83
|
logger.info("start make "+pluralString+" ...");
|
84
|
boolean success = true ;
|
85
|
doDelete(bmeConfig);
|
86
|
|
87
|
TransactionStatus txStatus = startTransaction(true);
|
88
|
Class<Team> clazz = Team.class;
|
89
|
List<? extends AgentBase> persons = getAgentService().list(clazz, 100000000, 0);
|
90
|
|
91
|
BerlinModelExportMapping mapping = getMapping();
|
92
|
mapping.initialize(state);
|
93
|
|
94
|
// for (AgentBase agent : persons){
|
95
|
// if (agent instanceof Person){
|
96
|
// success &= mapping.invoke(agent);
|
97
|
// }
|
98
|
// }
|
99
|
logger.info("save "+pluralString+" ...");
|
100
|
int count = 0;
|
101
|
for (AgentBase<?> agent : persons){
|
102
|
doCount(count++, modCount, pluralString);
|
103
|
if (agent instanceof Team){
|
104
|
success &= mapping.invoke(agent);
|
105
|
}
|
106
|
}
|
107
|
|
108
|
commitTransaction(txStatus);
|
109
|
|
110
|
logger.info("end make "+pluralString+" ...");
|
111
|
return success;
|
112
|
}catch(SQLException e){
|
113
|
e.printStackTrace();
|
114
|
logger.error(e.getMessage());
|
115
|
return false;
|
116
|
}
|
117
|
}
|
118
|
|
119
|
protected boolean doDelete(BerlinModelExportConfigurator config){
|
120
|
String sql;
|
121
|
Source destination = config.getDestination();
|
122
|
//RelPTaxon
|
123
|
sql = "DELETE FROM RelPTaxon";
|
124
|
destination.setQuery(sql);
|
125
|
destination.update(sql);
|
126
|
//Fact
|
127
|
sql = "DELETE FROM Fact";
|
128
|
destination.setQuery(sql);
|
129
|
destination.update(sql);
|
130
|
//PTaxon
|
131
|
sql = "DELETE FROM PTaxon";
|
132
|
destination.setQuery(sql);
|
133
|
destination.update(sql);
|
134
|
|
135
|
//NameHistory
|
136
|
sql = "DELETE FROM NameHistory";
|
137
|
destination.setQuery(sql);
|
138
|
destination.update(sql);
|
139
|
//RelName
|
140
|
sql = "DELETE FROM RelName";
|
141
|
destination.setQuery(sql);
|
142
|
destination.update(sql);
|
143
|
//NomStatusRel
|
144
|
sql = "DELETE FROM NomStatusRel";
|
145
|
destination.setQuery(sql);
|
146
|
destination.update(sql);
|
147
|
//Name
|
148
|
sql = "DELETE FROM Name";
|
149
|
destination.setQuery(sql);
|
150
|
destination.update(sql);
|
151
|
//RefDetail
|
152
|
sql = "DELETE FROM RefDetail";
|
153
|
destination.setQuery(sql);
|
154
|
destination.update(sql);
|
155
|
//Reference
|
156
|
sql = "DELETE FROM Reference";
|
157
|
destination.setQuery(sql);
|
158
|
destination.update(sql);
|
159
|
//AuthorTeamSequence
|
160
|
sql = "DELETE FROM AuthorTeamSequence";
|
161
|
destination.setQuery(sql);
|
162
|
destination.update(sql);
|
163
|
//AuthorTeam
|
164
|
sql = "DELETE FROM AuthorTeam";
|
165
|
destination.setQuery(sql);
|
166
|
destination.update(sql);
|
167
|
return true;
|
168
|
}
|
169
|
|
170
|
//called by MethodMapper
|
171
|
@SuppressWarnings("unused")
|
172
|
private static String getAuthorTeamCache(Team team){
|
173
|
if (team.isProtectedTitleCache()){
|
174
|
return team.getTitleCache();
|
175
|
}else{
|
176
|
return null;
|
177
|
}
|
178
|
}
|
179
|
|
180
|
//called by MethodMapper
|
181
|
@SuppressWarnings("unused")
|
182
|
private static String getFullAuthorTeamCache(Team team){
|
183
|
if (team.isProtectedTitleCache()){
|
184
|
return team.getNomenclaturalTitle();
|
185
|
}else{
|
186
|
return null;
|
187
|
}
|
188
|
}
|
189
|
|
190
|
|
191
|
/* (non-Javadoc)
|
192
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
193
|
*/
|
194
|
protected boolean isIgnore(IExportConfigurator config){
|
195
|
return ! ((BerlinModelExportConfigurator)config).isDoAuthors();
|
196
|
}
|
197
|
|
198
|
/* (non-Javadoc)
|
199
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportBase#getStandardMethodParameter()
|
200
|
*/
|
201
|
@Override
|
202
|
public Class<? extends CdmBase> getStandardMethodParameter() {
|
203
|
return standardMethodParameter;
|
204
|
}
|
205
|
|
206
|
}
|