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