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.sql.Types;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.springframework.stereotype.Component;
|
17
|
import org.springframework.transaction.TransactionStatus;
|
18
|
|
19
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.CreatedAndNotesMapper;
|
20
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbConstantMapper;
|
21
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbObjectMapper;
|
22
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.MethodMapper;
|
23
|
import eu.etaxonomy.cdm.io.common.DbExportStateBase;
|
24
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
25
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
26
|
import eu.etaxonomy.cdm.model.taxon.ITreeNode;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
28
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
30
|
|
31
|
|
32
|
/**
|
33
|
* @author a.mueller
|
34
|
* @created 20.03.2008
|
35
|
* @version 1.0
|
36
|
*/
|
37
|
@Component
|
38
|
public class BerlinModelClassificationExport extends BerlinModelExportBase<RelationshipBase> {
|
39
|
private static final Logger logger = Logger.getLogger(BerlinModelClassificationExport.class);
|
40
|
|
41
|
private static int modCount = 1000;
|
42
|
private static final String dbTableName = "RelPTaxon";
|
43
|
private static final String pluralString = "TaxonNodes";
|
44
|
private static final Class<? extends CdmBase> standardMethodParameter = TaxonNode.class;
|
45
|
|
46
|
|
47
|
public BerlinModelClassificationExport(){
|
48
|
super();
|
49
|
}
|
50
|
|
51
|
/* (non-Javadoc)
|
52
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
53
|
*/
|
54
|
@Override
|
55
|
protected boolean doCheck(BerlinModelExportState state){
|
56
|
boolean result = true;
|
57
|
logger.warn("Checking for " + pluralString + " not yet implemented");
|
58
|
//result &= checkArticlesWithoutJournal(bmiConfig);
|
59
|
//result &= checkPartOfJournal(bmiConfig);
|
60
|
|
61
|
return result;
|
62
|
}
|
63
|
|
64
|
private BerlinModelExportMapping getMapping(){
|
65
|
String tableName = dbTableName;
|
66
|
BerlinModelExportMapping mapping = new BerlinModelExportMapping(tableName);
|
67
|
// mapping.addMapper(IdMapper.NewInstance("RelPTaxonId")); //is Identity column
|
68
|
|
69
|
mapping.addMapper(MethodMapper.NewInstance("PTNameFk1", this.getClass(), "getPTNameFk1", standardMethodParameter, DbExportStateBase.class));
|
70
|
mapping.addMapper(MethodMapper.NewInstance("PTRefFk1", this.getClass(), "getPTRefFk1", standardMethodParameter, DbExportStateBase.class));
|
71
|
|
72
|
mapping.addMapper(MethodMapper.NewInstance("PTNameFk2", this.getClass(), "getPTNameFk2", standardMethodParameter, DbExportStateBase.class));
|
73
|
mapping.addMapper(MethodMapper.NewInstance("PTRefFk2", this.getClass(), "getPTRefFk2", standardMethodParameter, DbExportStateBase.class));
|
74
|
|
75
|
mapping.addMapper(DbConstantMapper.NewInstance("RelQualifierFk", Types.INTEGER, 1));
|
76
|
|
77
|
mapping.addMapper(DbObjectMapper.NewInstance("referenceForParentChildRelation", "RelRefFk"));
|
78
|
// mapping.addMapper(RefDetailMapper.NewInstance("citationMicroReference","citation", "FactRefDetailFk"));
|
79
|
mapping.addMapper(CreatedAndNotesMapper.NewInstance());
|
80
|
|
81
|
return mapping;
|
82
|
}
|
83
|
|
84
|
protected void doInvoke(BerlinModelExportState state){
|
85
|
if (state.getConfig().isUseClassification() == false){
|
86
|
return;
|
87
|
}
|
88
|
|
89
|
try{
|
90
|
logger.info("start make " + pluralString + " ...");
|
91
|
boolean success = true ;
|
92
|
doDelete(state);
|
93
|
|
94
|
TransactionStatus txStatus = startTransaction(true);
|
95
|
|
96
|
List<Classification> list = getClassificationService().list(null,10000000,0,null,null);
|
97
|
|
98
|
BerlinModelExportMapping mapping = getMapping();
|
99
|
mapping.initialize(state);
|
100
|
|
101
|
int count = 0;
|
102
|
for (Classification tree : list){
|
103
|
for (TaxonNode node : tree.getAllNodes()){
|
104
|
if (node.isTopmostNode()){
|
105
|
continue;
|
106
|
}else{
|
107
|
doCount(count++, modCount, pluralString);
|
108
|
success &= mapping.invoke(node);
|
109
|
}
|
110
|
}
|
111
|
}
|
112
|
commitTransaction(txStatus);
|
113
|
logger.info("end make " + pluralString + " ..." + getSuccessString(success));
|
114
|
if (!success){
|
115
|
state.setUnsuccessfull();
|
116
|
}
|
117
|
return;
|
118
|
}catch(SQLException e){
|
119
|
e.printStackTrace();
|
120
|
logger.error(e.getMessage());
|
121
|
state.setUnsuccessfull();
|
122
|
return;
|
123
|
}
|
124
|
}
|
125
|
|
126
|
|
127
|
protected boolean doDelete(BerlinModelExportState state){
|
128
|
BerlinModelExportConfigurator bmeConfig = state.getConfig();
|
129
|
|
130
|
//already deleted in BerlinModelTaxonRelationExport
|
131
|
// String sql;
|
132
|
// Source destination = bmeConfig.getDestination();
|
133
|
// //RelPTaxon
|
134
|
// sql = "DELETE FROM RelPTaxon ";
|
135
|
// destination.setQuery(sql);
|
136
|
// destination.update(sql);
|
137
|
|
138
|
return true;
|
139
|
}
|
140
|
|
141
|
|
142
|
/* (non-Javadoc)
|
143
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
144
|
*/
|
145
|
protected boolean isIgnore(BerlinModelExportState state){
|
146
|
return ! state.getConfig().isDoRelTaxa();
|
147
|
}
|
148
|
|
149
|
//called by MethodMapper
|
150
|
|
151
|
@SuppressWarnings("unused")
|
152
|
private static Integer getPTNameFk1(TaxonNode node, DbExportStateBase<?> state){
|
153
|
return getObjectFk(node, state, true, true);
|
154
|
}
|
155
|
|
156
|
@SuppressWarnings("unused")
|
157
|
private static Integer getPTRefFk1(TaxonNode node, DbExportStateBase<?> state){
|
158
|
return getObjectFk(node, state, false, true);
|
159
|
}
|
160
|
|
161
|
@SuppressWarnings("unused")
|
162
|
private static Integer getPTNameFk2(TaxonNode node, DbExportStateBase<?> state){
|
163
|
return getObjectFk(node, state, true, false);
|
164
|
}
|
165
|
|
166
|
@SuppressWarnings("unused")
|
167
|
private static Integer getPTRefFk2(TaxonNode node, DbExportStateBase<?> state){
|
168
|
return getObjectFk(node, state, false, false);
|
169
|
}
|
170
|
|
171
|
private static Integer getObjectFk(TaxonNode node, DbExportStateBase<?> state, boolean isName, boolean isFrom){
|
172
|
TaxonNode treeNode = (isFrom) ? node : node.getParent();
|
173
|
if (treeNode != null){
|
174
|
Taxon taxon = treeNode.getTaxon();
|
175
|
CdmBase cdmBase = (isName) ? taxon.getName(): taxon.getSec();
|
176
|
return state.getDbId(cdmBase);
|
177
|
}
|
178
|
logger.warn("No taxon or parent taxon found for taxon node: " + node.toString());
|
179
|
return null;
|
180
|
}
|
181
|
|
182
|
|
183
|
/* (non-Javadoc)
|
184
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportBase#getStandardMethodParameter()
|
185
|
*/
|
186
|
@Override
|
187
|
public Class<? extends CdmBase> getStandardMethodParameter() {
|
188
|
return standardMethodParameter;
|
189
|
}
|
190
|
}
|