Project

General

Profile

Download (3.03 KB) Statistics
| Branch: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 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

    
11
package eu.etaxonomy.cdm.io.pesi.erms.validation;
12

    
13
import java.sql.ResultSet;
14
import java.sql.SQLException;
15

    
16
import org.apache.log4j.Logger;
17

    
18

    
19
import eu.etaxonomy.cdm.io.common.IOValidator;
20
import eu.etaxonomy.cdm.io.common.Source;
21
import eu.etaxonomy.cdm.io.pesi.erms.ErmsImportConfigurator;
22
import eu.etaxonomy.cdm.io.pesi.erms.ErmsImportState;
23

    
24
/**
25
 * @author a.mueller
26
 * @created 17.02.2010
27
 * @version 1.0
28
 */
29
public class ErmsReferenceImportValidator implements IOValidator<ErmsImportState>{
30
	private static final Logger logger = Logger.getLogger(ErmsReferenceImportValidator.class);
31

    
32
	public boolean validate(ErmsImportState state){
33
		boolean result = true;
34
		ErmsImportConfigurator config = state.getConfig();
35
		logger.warn("Checking for references not yet fully implemented");
36
//		result &= checkTaxonStatus(config);
37
//		result &= checkInactivated(config);
38
		return result;
39
	}
40
	
41
	private boolean checkTaxonStatus(ErmsImportConfigurator bmiConfig){
42
		try {
43
			boolean result = true;
44
			Source source = bmiConfig.getSource();
45
			String strSQL = " SELECT RelPTaxon.RelQualifierFk, RelPTaxon.relPTaxonId, PTaxon.PTNameFk, PTaxon.PTRefFk, PTaxon_1.PTNameFk AS Expr1, PTaxon.RIdentifier, PTaxon_1.RIdentifier AS Expr3, Name.FullNameCache "  +
46
				" FROM RelPTaxon " + 
47
					" INNER JOIN PTaxon ON RelPTaxon.PTNameFk1 = PTaxon.PTNameFk AND RelPTaxon.PTRefFk1 = PTaxon.PTRefFk " + 
48
					" INNER JOIN PTaxon AS PTaxon_1 ON RelPTaxon.PTNameFk2 = PTaxon_1.PTNameFk AND RelPTaxon.PTRefFk2 = PTaxon_1.PTRefFk  " + 
49
					" INNER JOIN Name ON PTaxon.PTNameFk = Name.NameId " +
50
				" WHERE (dbo.PTaxon.StatusFk = 1) AND ((RelPTaxon.RelQualifierFk = 7) OR (RelPTaxon.RelQualifierFk = 6) OR (RelPTaxon.RelQualifierFk = 2)) ";
51
			ResultSet rs = source.getResultSet(strSQL);
52
			boolean firstRow = true;
53
			int i = 0;
54
			while (rs.next()){
55
				i++;
56
				if (firstRow){
57
					System.out.println("========================================================");
58
					logger.warn("There are taxa that have a 'is synonym of' - relationship but having taxon status 'accepted'!");
59
					System.out.println("========================================================");
60
				}
61
				int rIdentifier = rs.getInt("RIdentifier");
62
				int nameFk = rs.getInt("PTNameFk");
63
				int refFk = rs.getInt("PTRefFk");
64
				int relPTaxonId = rs.getInt("relPTaxonId");
65
				String taxonName = rs.getString("FullNameCache");
66
				
67
				System.out.println("RIdentifier:" + rIdentifier + "\n  name: " + nameFk + 
68
						"\n  taxonName: " + taxonName + "\n  refId: " + refFk + "\n  RelPTaxonId: " + relPTaxonId );
69
				result = firstRow = false;
70
			}
71
			if (i > 0){
72
				System.out.println(" ");
73
			}
74
			
75
			return result;
76
		} catch (SQLException e) {
77
			e.printStackTrace();
78
			return false;
79
		}
80
	}
81

    
82

    
83

    
84
}
(7-7/10)