Project

General

Profile

Download (3.3 KB) Statistics
| Branch: | Revision:
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

    
10
package eu.etaxonomy.cdm.io.algaterra.validation;
11

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

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
18
import eu.etaxonomy.cdm.io.common.IOValidator;
19
import eu.etaxonomy.cdm.io.common.Source;
20

    
21
/**
22
 * @author a.mueller
23
 * @since 26.02.2013
24
 */
25
public class AlgaTerraDnaImportValidator implements IOValidator<BerlinModelImportState> {
26
	@SuppressWarnings("unused")
27
	private static final Logger logger = Logger.getLogger(AlgaTerraDnaImportValidator.class);
28

    
29
	/* (non-Javadoc)
30
	 * @see eu.etaxonomy.cdm.io.common.IOValidator#validate(eu.etaxonomy.cdm.io.common.IoStateBase)
31
	 */
32
	public boolean validate(BerlinModelImportState state) {
33
		boolean result = true;
34
		result &= checkDnaFactWithoutFact(state);
35
		result &= checkDnaFactsWithMultipleFacts(state);
36
		return result;
37
	}
38
	
39
	
40
	//******************************** CHECK *************************************************
41
		
42
		private static boolean checkDnaFactWithoutFact(BerlinModelImportState state){
43
			try {
44
				boolean result = true;
45
				Source source = state.getConfig().getSource();
46
				String strQuery = " SELECT count(*) as n FROM DNAFact " +
47
							" WHERE (DNAFactID NOT IN " +
48
		                      "  (SELECT   ExtensionFk " +
49
		                      "      FROM   dbo.Fact AS f " +
50
		                      "     WHERE      (FactCategoryFk = 203))) " ; 
51
	
52
				ResultSet rs = source.getResultSet(strQuery);
53
				
54
				rs.next();
55
				int n = rs.getInt("n");
56
				if (n > 0){
57
					System.out.println("========================================================");
58
					System.out.println("There " + n + " are DNAFacts with no facts referencing them!");
59
					System.out.println("   SQL: " + strQuery);
60
					System.out.println("========================================================");
61
					result = false;
62
				}
63
				
64
				return result;
65
			} catch (SQLException e) {
66
				e.printStackTrace();
67
				return false;
68
			}
69
		}
70
		
71
		
72
		private static boolean checkDnaFactsWithMultipleFacts(BerlinModelImportState state){
73
			try {
74
				boolean result = true;
75
				Source source = state.getConfig().getSource();
76
				String strQuery = " SELECT count(*) as n FROM (" + 
77
										" SELECT ExtensionFk, COUNT(*) AS n " +
78
										" FROM Fact AS f  " +
79
										" WHERE  (FactCategoryFk = 203) " +
80
										" GROUP BY ExtensionFk " + 
81
										" HAVING (COUNT(*) > 1) " +
82
									") as tmp ";
83
				
84
				ResultSet rs = source.getResultSet(strQuery);
85
				
86
				rs.next();
87
				int n = rs.getInt("n");
88
				if (n > 0){
89
					System.out.println("========================================================");
90
					System.out.println("There " + n + " are DNAFacts with more then 1 fact referencing them!");
91
					System.out.println("   SQL: " + strQuery);
92
					System.out.println("========================================================");
93
					result = false;
94
				}
95
				
96
				return result;
97
			} catch (SQLException e) {
98
				e.printStackTrace();
99
				return false;
100
			}
101
		}
102

    
103

    
104
}
(2-2/5)