Project

General

Profile

Download (2.52 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.algaterra.validation;
12

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

    
16
import org.apache.commons.lang.StringUtils;
17
import org.apache.log4j.Logger;
18

    
19
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
20
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
21
import eu.etaxonomy.cdm.io.common.IOValidator;
22
import eu.etaxonomy.cdm.io.common.Source;
23

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

    
33

    
34
	@Override
35
	public boolean validate(BerlinModelImportState state) {
36
		boolean result = true;
37
		BerlinModelImportConfigurator bmiConfig = state.getConfig();
38
		result &= checkOrphanedEcologyFacts(bmiConfig);
39
		//result &= checkPartOfJournal(bmiConfig);
40
		System.out.println("Checking for Specimen not yet fully implemented");
41
		return result;
42
	}
43
	
44
	
45
	//******************************** CHECK *************************************************
46
		
47
		private static boolean checkOrphanedEcologyFacts(BerlinModelImportConfigurator config){
48
			try {
49
				boolean result = true;
50
				Source source = config.getSource();
51
				String strQuery = "SELECT * FROM Fact " + 
52
						" WHERE FactCategoryFk = 202 AND ExtensionFk NOT IN (SELECT EcoFactId FROM EcoFact) " +
53
						" ORDER BY ExtensionFk  ";
54

    
55
				ResultSet resulSet = source.getResultSet(strQuery);
56
				boolean firstRow = true;
57
				while (resulSet.next()){
58
					if (firstRow){
59
						System.out.println("========================================================");
60
						System.out.println("There EcologyFacts with pointing to non existing EcoFacts!");
61
						System.out.println("========================================================");
62
					}
63
					int factId = resulSet.getInt("FactId");
64
					int extensionFk = resulSet.getInt("ExtensionFk");
65
					
66
					System.out.println("FactId:" + factId + "\n  ExtensionFk: " + extensionFk);
67
					
68
					result = firstRow = false;
69
				}
70
				
71
				return result;
72
			} catch (SQLException e) {
73
				e.printStackTrace();
74
				return false;
75
			}
76
		}
77

    
78
}
(4-4/5)