1
|
/**
|
2
|
* Copyright (C) 2009 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.pesi.out;
|
10
|
|
11
|
import org.apache.log4j.Logger;
|
12
|
import org.springframework.stereotype.Component;
|
13
|
|
14
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
15
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
16
|
|
17
|
/**
|
18
|
* The export class for {@link eu.etaxonomy.cdm.model.name.TaxonNameBase TaxonNames}.<p>
|
19
|
* Inserts into DataWarehouse database table <code>Taxon</code>.
|
20
|
* It is divided into four phases:<p><ul>
|
21
|
* <li>Phase 1: Export of all {@link eu.etaxonomy.cdm.model.name.TaxonNameBase TaxonNames} except some data exported in the following phases.
|
22
|
* <li>Phase 2: Export of additional data: ParenTaxonFk and TreeIndex.
|
23
|
* <li>Phase 3: Export of additional data: Rank data, KingdomFk, TypeNameFk, expertFk and speciesExpertFk.
|
24
|
* <li>Phase 4: Export of Inferred Synonyms.</ul>
|
25
|
* @author e.-m.lee
|
26
|
* @since 23.02.2010
|
27
|
*
|
28
|
*/
|
29
|
@Component
|
30
|
public class PesiFinalUpdateExport extends PesiExportBase {
|
31
|
|
32
|
private static final long serialVersionUID = 6190569804410237104L;
|
33
|
private static final Logger logger = Logger.getLogger(PesiFinalUpdateExport.class);
|
34
|
|
35
|
private static final Class<? extends CdmBase> standardMethodParameter = TaxonBase.class;
|
36
|
|
37
|
private static final String pluralString = "taxa";
|
38
|
|
39
|
public PesiFinalUpdateExport() {
|
40
|
super();
|
41
|
}
|
42
|
|
43
|
@Override
|
44
|
public Class<? extends CdmBase> getStandardMethodParameter() {
|
45
|
return standardMethodParameter;
|
46
|
}
|
47
|
|
48
|
@Override
|
49
|
protected boolean doCheck(PesiExportState state) {
|
50
|
boolean result = true;
|
51
|
return result;
|
52
|
}
|
53
|
|
54
|
|
55
|
@Override
|
56
|
protected void doInvoke(PesiExportState state) {
|
57
|
try {
|
58
|
logger.info("*** Started Making " + pluralString + " ...");
|
59
|
|
60
|
// Stores whether this invoke was successful or not.
|
61
|
boolean success = true;
|
62
|
|
63
|
//updates to TaxonStatus and others
|
64
|
success &= doPhaseUpdates(state);
|
65
|
|
66
|
|
67
|
logger.info("*** Finished Making " + pluralString + " ..." + getSuccessString(success));
|
68
|
|
69
|
if (!success){
|
70
|
state.getResult().addError("An unknown error occurred in PesiFinalUpdateExport.invoke");
|
71
|
}
|
72
|
return;
|
73
|
} catch (Exception e) {
|
74
|
e.printStackTrace();
|
75
|
logger.error(e.getMessage());
|
76
|
state.getResult().addException(e, e.getMessage());
|
77
|
return;
|
78
|
}
|
79
|
}
|
80
|
|
81
|
|
82
|
private boolean doPhaseUpdates(PesiExportState state) {
|
83
|
|
84
|
|
85
|
String oldStatusFilter = " 7 "; //"= '" + PesiTransformer.T_STATUS_STR_UNACCEPTED + "' ";
|
86
|
String emStr = PesiTransformer.SOURCE_STR_EM;
|
87
|
String feStr = PesiTransformer.SOURCE_STR_FE;
|
88
|
String ifStr = PesiTransformer.SOURCE_STR_IF;
|
89
|
|
90
|
//NOT ACCEPTED names
|
91
|
String updateNotAccepted = " UPDATE Taxon SET TaxonStatusFk = %d, TaxonStatusCache = '%s' " +
|
92
|
" WHERE OriginalDB = '%s' AND taxonstatusfk = 1 AND ParentTaxonFk = %s AND RankFk > 180 ";
|
93
|
updateNotAccepted = String.format(updateNotAccepted, 8, "NOT ACCEPTED: TAXONOMICALLY VALUELESS LOCAL OR SINGULAR BIOTYPE", emStr, oldStatusFilter);
|
94
|
int updated = state.getConfig().getDestination().update(updateNotAccepted);
|
95
|
|
96
|
//alternative names
|
97
|
String updateAlternativeName = "UPDATE Taxon SET TaxonStatusFk = 1, TaxonStatusCache = 'accepted' " +
|
98
|
" FROM RelTaxon RIGHT OUTER JOIN Taxon ON RelTaxon.TaxonFk1 = Taxon.TaxonId " +
|
99
|
" WHERE (RelTaxon.RelTaxonQualifierFk = 17) AND (Taxon.TaxonStatusFk = %s) ";
|
100
|
updateAlternativeName = String.format(updateAlternativeName, oldStatusFilter);
|
101
|
System.out.println(updateAlternativeName);
|
102
|
updated = state.getConfig().getDestination().update(updateAlternativeName);
|
103
|
|
104
|
String updateSynonyms = " UPDATE Taxon SET TaxonStatusFk = 2, TaxonStatusCache = 'synonym' " +
|
105
|
" FROM RelTaxon RIGHT OUTER JOIN Taxon ON RelTaxon.TaxonFk1 = Taxon.TaxonId " +
|
106
|
" WHERE (RelTaxon.RelTaxonQualifierFk in (1, 3)) AND (Taxon.TaxonStatusFk = %s)";
|
107
|
updateSynonyms = String.format(updateSynonyms, oldStatusFilter);
|
108
|
System.out.println(updateSynonyms);
|
109
|
updated = state.getConfig().getDestination().update(updateSynonyms);
|
110
|
|
111
|
// cache citation - check if this can't be done in getCacheCitation
|
112
|
// cache citation - FE
|
113
|
// String updateCacheCitationFE = " UPDATE Taxon " +
|
114
|
// " SET CacheCitation = IsNull(SpeciesExpertName + '. ', '') + WebShowName + '. Accessed through: Fauna Europaea at http://www.faunaeur.org/full_results.php?id=' + cast(TempFE_Id as varchar) " +
|
115
|
// " WHERE OriginalDb = '%s'";
|
116
|
// updateCacheCitationFE = String.format(updateCacheCitationFE, feStr);
|
117
|
// updated = state.getConfig().getDestination().update(updateCacheCitationFE);
|
118
|
|
119
|
// cache citation - EM
|
120
|
String updateCacheCitationEM = " UPDATE Taxon " +
|
121
|
" SET CacheCitation = SpeciesExpertName + ' ' + WebShowName + '. Accessed through: Euro+Med PlantBase at http://ww2.bgbm.org/euroPlusMed/PTaxonDetail.asp?UUID=' + GUID " +
|
122
|
" WHERE OriginalDb = '%s'";
|
123
|
updateCacheCitationEM = String.format(updateCacheCitationEM, emStr);
|
124
|
updated = state.getConfig().getDestination().update(updateCacheCitationEM);
|
125
|
|
126
|
// cache citation - IF
|
127
|
// String updateCacheCitationIF = " UPDATE Taxon " +
|
128
|
// " SET CacheCitation = IsNull(SpeciesExpertName + ' ', '') + WebShowName + '. Accessed through: Index Fungorum at http://www.indexfungorum.org/names/NamesRecord.asp?RecordID=' + cast(TempIF_Id as varchar) " +
|
129
|
// " WHERE OriginalDb = '%s'";
|
130
|
// updateCacheCitationIF = String.format(updateCacheCitationIF, ifStr);
|
131
|
// updated = state.getConfig().getDestination().update(updateCacheCitationIF);
|
132
|
|
133
|
return true;
|
134
|
}
|
135
|
|
136
|
@Override
|
137
|
protected boolean isIgnore(PesiExportState state) {
|
138
|
return ! state.getConfig().isDoTaxa();
|
139
|
}
|
140
|
|
141
|
}
|