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.berlinModel.out.mapper.CreatedAndNotesMapper;
|
20
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbObjectMapper;
|
21
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.IdMapper;
|
22
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.MethodMapper;
|
23
|
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.RefDetailMapper;
|
24
|
import eu.etaxonomy.cdm.io.common.IExportConfigurator;
|
25
|
import eu.etaxonomy.cdm.io.common.Source;
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
28
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
29
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
30
|
|
31
|
|
32
|
/**
|
33
|
* @author a.mueller
|
34
|
* @created 20.03.2008
|
35
|
* @version 1.0
|
36
|
*/
|
37
|
@Component
|
38
|
public class BerlinModelNameRelationExport extends BerlinModelExportBase {
|
39
|
private static final Logger logger = Logger.getLogger(BerlinModelNameRelationExport.class);
|
40
|
|
41
|
private static int modCount = 1000;
|
42
|
private static final String dbTableName = "RelName";
|
43
|
private static final String pluralString = "NameRelationships";
|
44
|
private static final Class<? extends CdmBase> standardMethodParameter = NameRelationship.class;
|
45
|
|
46
|
|
47
|
public BerlinModelNameRelationExport(){
|
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(IExportConfigurator config){
|
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("RelNameId"));
|
68
|
|
69
|
mapping.addMapper(DbObjectMapper.NewInstance("fromName", "NameFk1"));
|
70
|
mapping.addMapper(DbObjectMapper.NewInstance("toName", "NameFk1"));
|
71
|
|
72
|
|
73
|
mapping.addMapper(MethodMapper.NewInstance("RelNameQualifierFk", this));
|
74
|
|
75
|
mapping.addMapper(DbObjectMapper.NewInstance("citation", "RefFk"));
|
76
|
mapping.addMapper(RefDetailMapper.NewInstance("citationMicroReference","citation", "RefDetailFk"));
|
77
|
mapping.addMapper(CreatedAndNotesMapper.NewInstance());
|
78
|
|
79
|
// NameRelationship r = null;
|
80
|
// r.getFromName()
|
81
|
|
82
|
return mapping;
|
83
|
}
|
84
|
|
85
|
protected boolean doInvoke(BerlinModelExportState<BerlinModelExportConfigurator> state){
|
86
|
try{
|
87
|
logger.info("start make " + pluralString + " ...");
|
88
|
boolean success = true ;
|
89
|
doDelete(state);
|
90
|
|
91
|
TransactionStatus txStatus = startTransaction(true);
|
92
|
|
93
|
List<RelationshipBase> list = getNameService().getAllRelationships(100000000, 0);
|
94
|
|
95
|
BerlinModelExportMapping mapping = getMapping();
|
96
|
mapping.initialize(state);
|
97
|
|
98
|
int count = 0;
|
99
|
for (RelationshipBase<?,?,?> rel : list){
|
100
|
if (rel.isInstanceOf(NameRelationship.class) || rel.isInstanceOf(HybridRelationship.class )){
|
101
|
doCount(count++, modCount, pluralString);
|
102
|
success &= mapping.invoke(rel);
|
103
|
}
|
104
|
}
|
105
|
commitTransaction(txStatus);
|
106
|
logger.info("end make " + pluralString + " ...");
|
107
|
return success;
|
108
|
}catch(SQLException e){
|
109
|
e.printStackTrace();
|
110
|
logger.error(e.getMessage());
|
111
|
return false;
|
112
|
}
|
113
|
}
|
114
|
|
115
|
|
116
|
protected boolean doDelete(BerlinModelExportState<BerlinModelExportConfigurator> state){
|
117
|
BerlinModelExportConfigurator bmeConfig = state.getConfig();
|
118
|
|
119
|
String sql;
|
120
|
Source destination = bmeConfig.getDestination();
|
121
|
//RelPTaxon
|
122
|
sql = "DELETE FROM RelPTaxon";
|
123
|
destination.setQuery(sql);
|
124
|
destination.update(sql);
|
125
|
|
126
|
return true;
|
127
|
}
|
128
|
|
129
|
|
130
|
/* (non-Javadoc)
|
131
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
132
|
*/
|
133
|
protected boolean isIgnore(IExportConfigurator config){
|
134
|
return ! ((BerlinModelExportConfigurator)config).isDoTaxonNames();
|
135
|
}
|
136
|
|
137
|
//called by MethodMapper
|
138
|
@SuppressWarnings("unused")
|
139
|
private static Integer getRelNameQualifierFk(RelationshipBase<?, ?, ?> rel){
|
140
|
return BerlinModelTransformer.nameRel2RelNameQualifierFk(rel);
|
141
|
}
|
142
|
|
143
|
/* (non-Javadoc)
|
144
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportBase#getStandardMethodParameter()
|
145
|
*/
|
146
|
@Override
|
147
|
public Class<? extends CdmBase> getStandardMethodParameter() {
|
148
|
return standardMethodParameter;
|
149
|
}
|
150
|
}
|