Project

General

Profile

Download (3.29 KB) Statistics
| Branch: | Tag: | 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.berlinModel.in.validation;
12

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

    
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
 * @created 17.02.2010
26
 * @version 1.0
27
 */
28
public class BerlinModelOccurrenceImportValidator implements IOValidator<BerlinModelImportState> {
29
	private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceImportValidator.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 &= checkTaxonIsAccepted(bmiConfig);
38
		//result &= checkPartOfJournal(bmiConfig);
39
		logger.warn("Checking for Occurrence not yet fully implemented");
40
		return result;
41
	}
42
	
43
	
44
	//******************************** CHECK *************************************************
45
		
46
		private static boolean checkTaxonIsAccepted(BerlinModelImportConfigurator bmiConfig){
47
			try {
48
				boolean result = true;
49
				Source source = bmiConfig.getSource();
50
				String strQuery = "SELECT emOccurrence.OccurrenceId, PTaxon.StatusFk, Name.FullNameCache, Status.Status, PTaxon.PTRefFk, Reference.RefCache " + 
51
							" FROM emOccurrence INNER JOIN " +
52
								" PTaxon ON emOccurrence.PTNameFk = PTaxon.PTNameFk AND emOccurrence.PTRefFk = PTaxon.PTRefFk INNER JOIN " + 
53
				                " Name ON PTaxon.PTNameFk = Name.NameId INNER JOIN " +
54
				                " Status ON PTaxon.StatusFk = Status.StatusId LEFT OUTER JOIN " +
55
				                " Reference ON PTaxon.PTRefFk = Reference.RefId " + 
56
							" WHERE (PTaxon.StatusFk <> 1)  ";
57
				
58
				ResultSet resulSet = source.getResultSet(strQuery);
59
				boolean firstRow = true;
60
				while (resulSet.next()){
61
					if (firstRow){
62
						System.out.println("========================================================");
63
						logger.warn("There are Occurrences for a taxon that is not accepted!");
64
						System.out.println("========================================================");
65
					}
66
					int occurrenceId = resulSet.getInt("OccurrenceId");
67
					int statusFk = resulSet.getInt("StatusFk");
68
					String status = resulSet.getString("Status");
69
					String fullNameCache = resulSet.getString("FullNameCache");
70
					String ptRefFk = resulSet.getString("PTRefFk");
71
					String ptRef = resulSet.getString("RefCache");
72
					
73
					System.out.println("OccurrenceId:" + occurrenceId + "\n  Status: " + status + 
74
							"\n  FullNameCache: " + fullNameCache +  "\n  ptRefFk: " + ptRefFk +
75
							"\n  sec: " + ptRef );
76
					
77
					result = firstRow = false;
78
				}
79
				
80
				return result;
81
			} catch (SQLException e) {
82
				e.printStackTrace();
83
				return false;
84
			}
85
		}
86

    
87
}
(8-8/19)