Project

General

Profile

Download (3.13 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.commons.lang.StringUtils;
16
import org.apache.log4j.Logger;
17

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

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

    
31
	/* (non-Javadoc)
32
	 * @see eu.etaxonomy.cdm.io.common.IOValidator#validate(eu.etaxonomy.cdm.io.common.IoStateBase)
33
	 */
34
	public boolean validate(BerlinModelImportState state) {
35
		boolean result = true;
36
		BerlinModelImportConfigurator bmiConfig = state.getConfig();
37
		result &= checkMultipleEntriesInTypeSpecimenDesignation(bmiConfig);
38
		//result &= checkPartOfJournal(bmiConfig);
39
		System.out.println("Checking for Specimen not yet fully implemented");
40
		return result;
41
	}
42
	
43
	
44
	//******************************** CHECK *************************************************
45
		
46
		private static boolean checkMultipleEntriesInTypeSpecimenDesignation(BerlinModelImportConfigurator config){
47
			try {
48
				boolean result = true;
49
				Source source = config.getSource();
50
				String strQuery = " SELECT COUNT(*) AS n, TypeSpecimenFk " +
51
							" FROM TypeSpecimenDesignation " +
52
							" GROUP BY TypeSpecimenFk " +
53
							" HAVING (COUNT(*) > 1)  ";
54

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

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

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

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

    
86
}
(5-5/5)