Project

General

Profile

Download (6.01 KB) Statistics
| Branch: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.io.pesi.out;
11

    
12
import org.apache.log4j.Logger;
13
import org.springframework.stereotype.Component;
14

    
15
import eu.etaxonomy.cdm.model.common.CdmBase;
16
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
17

    
18
/**
19
 * The export class for {@link eu.etaxonomy.cdm.model.name.TaxonNameBase TaxonNames}.<p>
20
 * Inserts into DataWarehouse database table <code>Taxon</code>.
21
 * It is divided into four phases:<p><ul>
22
 * <li>Phase 1:	Export of all {@link eu.etaxonomy.cdm.model.name.TaxonNameBase TaxonNames} except some data exported in the following phases.
23
 * <li>Phase 2:	Export of additional data: ParenTaxonFk and TreeIndex.
24
 * <li>Phase 3:	Export of additional data: Rank data, KingdomFk, TypeNameFk, expertFk and speciesExpertFk.
25
 * <li>Phase 4:	Export of Inferred Synonyms.</ul>
26
 * @author e.-m.lee
27
 * @date 23.02.2010
28
 *
29
 */
30
@Component
31
public class PesiFinalUpdateExport extends PesiExportBase {
32
	private static final Logger logger = Logger.getLogger(PesiFinalUpdateExport.class);
33
	private static final Class<? extends CdmBase> standardMethodParameter = TaxonBase.class;
34

    
35
	private static final String pluralString = "taxa";
36

    
37
	public PesiFinalUpdateExport() {
38
		super();
39
	}
40

    
41
	/* (non-Javadoc)
42
	 * @see eu.etaxonomy.cdm.io.common.DbExportBase#getStandardMethodParameter()
43
	 */
44
	@Override
45
	public Class<? extends CdmBase> getStandardMethodParameter() {
46
		return standardMethodParameter;
47
	}
48

    
49
	/* (non-Javadoc)
50
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
51
	 */
52
	@Override
53
	protected boolean doCheck(PesiExportState state) {
54
		boolean result = true;
55
		return result;
56
	}
57
	
58
	
59
	/* (non-Javadoc)
60
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IoStateBase)
61
	 */
62
	@Override
63
	protected void doInvoke(PesiExportState state) {
64
		try {
65
			logger.info("*** Started Making " + pluralString + " ...");
66

    
67
			// Stores whether this invoke was successful or not.
68
			boolean success = true;
69
	
70
			//updates to TaxonStatus and others
71
			success &= doPhaseUpdates(state);
72

    
73
			
74
			logger.info("*** Finished Making " + pluralString + " ..." + getSuccessString(success));
75

    
76
			if (!success){
77
				state.setUnsuccessfull();
78
			}
79
			return;
80
		} catch (Exception e) {
81
			e.printStackTrace();
82
			logger.error(e.getMessage());
83
			state.setUnsuccessfull();
84
			return;
85
		}
86
	}
87

    
88
	
89
	private boolean doPhaseUpdates(PesiExportState state) {
90
		
91
		
92
		String oldStatusFilter = " 7 ";  //"= '" + PesiTransformer.T_STATUS_STR_UNACCEPTED + "' ";
93
		String emStr = PesiTransformer.SOURCE_STR_EM;
94
		String feStr = PesiTransformer.SOURCE_STR_FE;
95
		String ifStr = PesiTransformer.SOURCE_STR_IF;
96
		
97
		//NOT ACCEPTED names
98
		String updateNotAccepted = " UPDATE Taxon SET TaxonStatusFk = %d, TaxonStatusCache = '%s' " +
99
				" WHERE OriginalDB = '%s' AND taxonstatusfk = 1 AND ParentTaxonFk = %s AND RankFk > 180 ";
100
		updateNotAccepted = String.format(updateNotAccepted, 8, "NOT ACCEPTED: TAXONOMICALLY VALUELESS LOCAL OR SINGULAR BIOTYPE", emStr, oldStatusFilter);
101
		int updated = state.getConfig().getDestination().update(updateNotAccepted);
102
		
103
		//alternative names
104
		String updateAlternativeName = "UPDATE Taxon SET TaxonStatusFk = 1, TaxonStatusCache = 'accepted' " + 
105
				" FROM RelTaxon RIGHT OUTER JOIN Taxon ON RelTaxon.TaxonFk1 = Taxon.TaxonId " +
106
				" WHERE (RelTaxon.RelTaxonQualifierFk = 17) AND (Taxon.TaxonStatusFk = %s) ";
107
		updateAlternativeName = String.format(updateAlternativeName, oldStatusFilter);
108
		System.out.println(updateAlternativeName);
109
		updated = state.getConfig().getDestination().update(updateAlternativeName);
110
		
111
		String updateSynonyms = " UPDATE Taxon SET TaxonStatusFk = 2, TaxonStatusCache = 'synonym' " + 
112
					" FROM RelTaxon RIGHT OUTER JOIN Taxon ON RelTaxon.TaxonFk1 = Taxon.TaxonId " + 
113
					" WHERE (RelTaxon.RelTaxonQualifierFk in (1, 3)) AND (Taxon.TaxonStatusFk = %s)";
114
		updateSynonyms = String.format(updateSynonyms, oldStatusFilter);
115
		System.out.println(updateSynonyms);
116
		updated = state.getConfig().getDestination().update(updateSynonyms);
117
		
118
		// cache citation  - check if this can't be done in getCacheCitation
119
		// cache citation - FE
120
//		String updateCacheCitationFE = " UPDATE Taxon " +
121
//				" SET CacheCitation = IsNull(SpeciesExpertName + '. ', '') + WebShowName + '. Accessed through: Fauna Europaea at http://www.faunaeur.org/full_results.php?id=' + cast(TempFE_Id as varchar) " +
122
//				" WHERE OriginalDb = '%s'";
123
//		updateCacheCitationFE = String.format(updateCacheCitationFE, feStr);
124
//		updated = state.getConfig().getDestination().update(updateCacheCitationFE);
125
		
126
		// cache citation - EM
127
		String updateCacheCitationEM = " UPDATE Taxon " +
128
				" SET CacheCitation = SpeciesExpertName + ' ' + WebShowName + '. Accessed through: Euro+Med PlantBase at http://ww2.bgbm.org/euroPlusMed/PTaxonDetail.asp?UUID=' + GUID " +
129
				" WHERE OriginalDb = '%s'";
130
		updateCacheCitationEM = String.format(updateCacheCitationEM, emStr);
131
		updated = state.getConfig().getDestination().update(updateCacheCitationEM);
132
		
133
		// cache citation - IF
134
//		String updateCacheCitationIF = " UPDATE Taxon " +
135
//				" SET CacheCitation = IsNull(SpeciesExpertName + ' ', '') + WebShowName + '. Accessed through: Index Fungorum at http://www.indexfungorum.org/names/NamesRecord.asp?RecordID=' + cast(TempIF_Id as varchar) " +
136
//				" WHERE OriginalDb = '%s'";
137
//		updateCacheCitationIF = String.format(updateCacheCitationIF, ifStr);
138
//		updated = state.getConfig().getDestination().update(updateCacheCitationIF);
139
		
140
		return true;
141
	}
142

    
143
	/* (non-Javadoc)
144
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IoStateBase)
145
	 */
146
	@Override
147
	protected boolean isIgnore(PesiExportState state) {
148
		return ! state.getConfig().isDoTaxa();
149
	}
150

    
151
}
(8-8/12)