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.BerlinModelTransformer;
|
19
|
import eu.etaxonomy.cdm.io.common.Source;
|
20
|
import eu.etaxonomy.cdm.io.common.mapping.out.CdmDbExportMapping;
|
21
|
import eu.etaxonomy.cdm.io.common.mapping.out.CreatedAndNotesMapper;
|
22
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbBooleanMapper;
|
23
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbExtensionMapper;
|
24
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbIntegerExtensionMapper;
|
25
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbMarkerMapper;
|
26
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbObjectMapper;
|
27
|
import eu.etaxonomy.cdm.io.common.mapping.out.DbStringMapper;
|
28
|
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
|
29
|
import eu.etaxonomy.cdm.io.common.mapping.out.MethodMapper;
|
30
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
31
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
32
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
33
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
34
|
|
35
|
|
36
|
/**
|
37
|
* @author a.mueller
|
38
|
* @created 20.03.2008
|
39
|
* @version 1.0
|
40
|
*/
|
41
|
@Component
|
42
|
public class BerlinModelTaxonExport extends BerlinModelExportBase<TaxonBase> {
|
43
|
private static final Logger logger = Logger.getLogger(BerlinModelTaxonExport.class);
|
44
|
|
45
|
private static int modCount = 1000;
|
46
|
private static final String dbTableName = "PTaxon";
|
47
|
private static final String pluralString = "Taxa";
|
48
|
private static final Class<? extends CdmBase> standardMethodParameter = TaxonBase.class;
|
49
|
|
50
|
public BerlinModelTaxonExport(){
|
51
|
super();
|
52
|
}
|
53
|
|
54
|
/* (non-Javadoc)
|
55
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
56
|
*/
|
57
|
@Override
|
58
|
protected boolean doCheck(BerlinModelExportState state){
|
59
|
boolean result = true;
|
60
|
logger.warn("Checking for " + pluralString + " not yet implemented");
|
61
|
//result &= checkArticlesWithoutJournal(bmiConfig);
|
62
|
//result &= checkPartOfJournal(bmiConfig);
|
63
|
|
64
|
return result;
|
65
|
}
|
66
|
|
67
|
private CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> getMapping(){
|
68
|
String tableName = dbTableName;
|
69
|
CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = new CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer>(tableName);
|
70
|
mapping.addMapper(DbObjectMapper.NewInstance("name", "PTNameFk"));
|
71
|
mapping.addMapper(DbObjectMapper.NewInstance("sec", "PTRefFk"));
|
72
|
mapping.addMapper(MethodMapper.NewInstance("StatusFk", this));
|
73
|
mapping.addMapper(MethodMapper.NewInstance("DoubtfulFlag", this) );
|
74
|
mapping.addMapper(DbBooleanMapper.NewInstance("useNameCache", "UseNameCacheFlag", false));
|
75
|
mapping.addMapper(DbStringMapper.NewFacultativeInstance("appendedPhrase", "NamePhrase"));
|
76
|
|
77
|
//detail
|
78
|
ExtensionType detailExtensionType = (ExtensionType)getTermService().find(BerlinModelTransformer.DETAIL_EXT_UUID);
|
79
|
if (detailExtensionType != null){
|
80
|
mapping.addMapper(DbExtensionMapper.NewInstance(detailExtensionType, "Detail"));
|
81
|
}
|
82
|
//idInSource
|
83
|
ExtensionType idInSourceExtensionType = (ExtensionType)getTermService().find(BerlinModelTransformer.ID_IN_SOURCE_EXT_UUID);
|
84
|
if (idInSourceExtensionType != null){
|
85
|
mapping.addMapper(DbIntegerExtensionMapper.NewInstance(idInSourceExtensionType, "IdInSource"));
|
86
|
}
|
87
|
// //namePhrase
|
88
|
// ExtensionType namePhraseExtensionType = (ExtensionType)getTermService().getTermByUuid(BerlinModelTaxonImport.APPENDED_TITLE_PHRASE);
|
89
|
// if (namePhraseExtensionType != null){
|
90
|
// mapping.addMapper(DbExtensionMapper.NewInstance(namePhraseExtensionType, "NamePhrase"));
|
91
|
// }
|
92
|
// //useNameCacheFlag
|
93
|
// MarkerType useNameCacheMarkerType = (MarkerType)getTermService().getTermByUuid(BerlinModelTaxonImport.USE_NAME_CACHE);
|
94
|
// if (useNameCacheMarkerType != null){
|
95
|
// mapping.addMapper(DbMarkerMapper.NewInstance(useNameCacheMarkerType, "UseNameCacheFlag", false));
|
96
|
// }
|
97
|
//publisheFlag
|
98
|
mapping.addMapper(DbMarkerMapper.NewInstance(MarkerType.PUBLISH(), "PublishFlag", true));
|
99
|
|
100
|
//notes
|
101
|
mapping.addMapper(CreatedAndNotesMapper.NewInstance());
|
102
|
|
103
|
//TODO
|
104
|
// ,[RIdentifier]
|
105
|
// ,ProParte etc.
|
106
|
|
107
|
return mapping;
|
108
|
}
|
109
|
|
110
|
protected void doInvoke(BerlinModelExportState state){
|
111
|
try{
|
112
|
logger.info("start make " + pluralString + " ...");
|
113
|
boolean success = true ;
|
114
|
doDelete(state);
|
115
|
|
116
|
TransactionStatus txStatus = startTransaction(true);
|
117
|
|
118
|
List<TaxonBase> list = getTaxonService().list(null,100000000, 0, null, null);
|
119
|
|
120
|
CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = getMapping();
|
121
|
mapping.initialize(state);
|
122
|
|
123
|
int count = 0;
|
124
|
for (TaxonBase<?> taxon : list){
|
125
|
doCount(count++, modCount, pluralString);
|
126
|
success &= mapping.invoke(taxon);
|
127
|
}
|
128
|
commitTransaction(txStatus);
|
129
|
logger.info("end make " + pluralString + " ..." + getSuccessString(success));
|
130
|
if (!success){
|
131
|
state.setUnsuccessfull();
|
132
|
}
|
133
|
return;
|
134
|
}catch(SQLException e){
|
135
|
e.printStackTrace();
|
136
|
logger.error(e.getMessage());
|
137
|
state.setUnsuccessfull();
|
138
|
return;
|
139
|
}
|
140
|
}
|
141
|
|
142
|
|
143
|
|
144
|
|
145
|
protected boolean doDelete(BerlinModelExportState state){
|
146
|
BerlinModelExportConfigurator bmeConfig = state.getConfig();
|
147
|
|
148
|
String sql;
|
149
|
Source destination = bmeConfig.getDestination();
|
150
|
//RelPTaxon
|
151
|
sql = "DELETE FROM RelPTaxon";
|
152
|
destination.setQuery(sql);
|
153
|
destination.update(sql);
|
154
|
//Fact
|
155
|
sql = "DELETE FROM Fact";
|
156
|
destination.setQuery(sql);
|
157
|
destination.update(sql);
|
158
|
//PTaxon
|
159
|
sql = "DELETE FROM PTaxon";
|
160
|
destination.setQuery(sql);
|
161
|
destination.update(sql);
|
162
|
|
163
|
return true;
|
164
|
}
|
165
|
|
166
|
|
167
|
/* (non-Javadoc)
|
168
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
169
|
*/
|
170
|
protected boolean isIgnore(BerlinModelExportState state){
|
171
|
return ! state.getConfig().isDoTaxa();
|
172
|
}
|
173
|
|
174
|
//called by MethodMapper
|
175
|
@SuppressWarnings("unused")
|
176
|
private static Integer getStatusFk(TaxonBase<?> taxon){
|
177
|
return BerlinModelTransformer.taxonBase2statusFk(taxon);
|
178
|
}
|
179
|
|
180
|
@SuppressWarnings("unused")
|
181
|
private static String getDoubtfulFlag(TaxonBase<?> taxon){
|
182
|
if (taxon.isDoubtful()){
|
183
|
return "d";
|
184
|
}else{
|
185
|
return "a";
|
186
|
}
|
187
|
}
|
188
|
|
189
|
/* (non-Javadoc)
|
190
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportBase#getStandardMethodParameter()
|
191
|
*/
|
192
|
@Override
|
193
|
public Class<? extends CdmBase> getStandardMethodParameter() {
|
194
|
return standardMethodParameter;
|
195
|
}
|
196
|
}
|