Project

General

Profile

Download (6.01 KB) Statistics
| Branch: | Revision:
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
 * @date 23.02.2010
27
 *
28
 */
29
@Component
30
public class PesiFinalUpdateExport extends PesiExportBase {
31
	private static final Logger logger = Logger.getLogger(PesiFinalUpdateExport.class);
32
	private static final Class<? extends CdmBase> standardMethodParameter = TaxonBase.class;
33

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

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

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

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

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

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

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

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

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

    
150
}
(8-8/12)