Project

General

Profile

Download (3.14 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 AlgaTerraTypeImportValidator implements IOValidator<BerlinModelImportState> {
30
	private static final Logger logger = Logger.getLogger(AlgaTerraTypeImportValidator.class);
31

    
32
	/* (non-Javadoc)
33
	 * @see eu.etaxonomy.cdm.io.common.IOValidator#validate(eu.etaxonomy.cdm.io.common.IoStateBase)
34
	 */
35
	public boolean validate(BerlinModelImportState state) {
36
		boolean result = true;
37
		BerlinModelImportConfigurator bmiConfig = state.getConfig();
38
		result &= checkMultipleEntriesInTypeSpecimenDesignation(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 checkMultipleEntriesInTypeSpecimenDesignation(BerlinModelImportConfigurator config){
48
			try {
49
				boolean result = true;
50
				Source source = config.getSource();
51
				String strQuery = " SELECT COUNT(*) AS n, TypeSpecimenFk " +
52
							" FROM TypeSpecimenDesignation " +
53
							" GROUP BY TypeSpecimenFk " +
54
							" HAVING (COUNT(*) > 1)  ";
55

    
56
				ResultSet resulSet = source.getResultSet(strQuery);
57
				if (resulSet.next()){
58
					System.out.println("========================================================");
59
					System.out.println("There are multiple TypeSpecimenDesignations sharing the same TypeSpecimen!");
60
					System.out.println("This is not supported by the current import and will lead to duplicates!");
61
					System.out.println("========================================================");
62
					result = false;
63
				}
64

    
65
				strQuery = " SELECT COUNT(*) AS n, TypeDesignationFk " +
66
						" FROM TypeSpecimenDesignation " +
67
						" GROUP BY TypeDesignationFk " +
68
						" HAVING (COUNT(*) > 1)  ";
69

    
70
				resulSet = source.getResultSet(strQuery);
71
				if (resulSet.next()){
72
					System.out.println("========================================================");
73
					System.out.println("There are multiple TypeSpecimenDesignations sharing the same TypeDesignation!");
74
					System.out.println("This is not supported by the current import and will lead to duplicates!");
75
					System.out.println("========================================================");
76
					result = false;
77
				}
78

    
79
				
80
				return result;
81
			} catch (SQLException e) {
82
				e.printStackTrace();
83
				return false;
84
			}
85
		}
86

    
87
}
(5-5/5)