Project

General

Profile

Download (4.08 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.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.database.update.DatabaseTypeNotSupportedException;
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
 */
27
public class BerlinModelRefDetailImportValidator implements IOValidator<BerlinModelImportState> {
28
	private static final Logger logger = Logger.getLogger(BerlinModelRefDetailImportValidator.class);
29

    
30
	/* (non-Javadoc)
31
	 * @see eu.etaxonomy.cdm.io.common.IOValidator#validate(eu.etaxonomy.cdm.io.common.IoStateBase)
32
	 */
33
	public boolean validate(BerlinModelImportState state) {
34
		boolean result = true;
35
		result &= checkRefDetailsWithSecondarySource(state);
36
		result &= checkRefDetailsWithIdInSource(state);
37
		result &= checkRefDetailsWithNotes(state);
38
		
39
		return result;
40
	}
41

    
42
	/**
43
	 * @param state
44
	 * @return
45
	 */
46
	private boolean checkRefDetailsWithSecondarySource(BerlinModelImportState state) {
47
		boolean success = true;
48
		try {
49
			
50
			Source source = state.getConfig().getSource();
51
			String strQuery = 
52
				"SELECT count(*) AS n FROM RefDetail " + 
53
				" WHERE (SecondarySources IS NOT NULL) AND (RTRIM(LTRIM(SecondarySources)) <> '')";
54
			ResultSet rs = source.getResultSet(strQuery);
55
			rs.next();
56
			int n;
57
			n = rs.getInt("n");
58
			if (n > 0){
59
				System.out.println("========================================================");
60
				System.out.println("There are " + n + " RefDetails with a secondary source. Secondary sources are not supported yet");
61
				System.out.println("========================================================");
62
				success = false;
63
			}
64
		} catch (SQLException e) {
65
			e.printStackTrace();
66
		}
67
		return success;
68
	}
69

    
70
	/**
71
	 * @param state
72
	 * @return
73
	 */
74
	private boolean checkRefDetailsWithIdInSource(BerlinModelImportState state) {
75
		boolean success = true;
76
		try {
77
			Source source = state.getConfig().getSource();
78
			if (source.checkColumnExists("RefDetail", "idInSource")){
79
				String strQuery = 
80
					"SELECT count(*) AS n FROM RefDetail " + 
81
					" WHERE (IdInSource IS NOT NULL) AND (RTRIM(LTRIM(IdInSource)) <> '')";
82
				ResultSet rs = source.getResultSet(strQuery);
83
				rs.next();
84
				int n;
85
				n = rs.getInt("n");
86
				if (n > 0){
87
					System.out.println("========================================================");
88
					System.out.println("There are " + n + " RefDetails with an idInSource. IdInSources are not supported yet");
89
					System.out.println("========================================================");
90
					success = false;
91
				}
92
			}
93
			
94
		} catch (SQLException e) {
95
			e.printStackTrace();
96
		} catch (DatabaseTypeNotSupportedException e) {
97
			logger.debug("Source does not support checking existance of 'idInSource' column");
98
		}
99
		return success;
100
	}
101
	
102
	/**
103
	 * @param state
104
	 * @return
105
	 */
106
	private boolean checkRefDetailsWithNotes(BerlinModelImportState state) {
107
		boolean success = true;
108
		try {
109
			
110
			Source source = state.getConfig().getSource();
111
			String strQuery = 
112
				"SELECT count(*) AS n FROM RefDetail " + 
113
				" WHERE (Notes IS NOT NULL) AND (RTRIM(LTRIM(Notes)) <> '')";
114
			ResultSet rs = source.getResultSet(strQuery);
115
			rs.next();
116
			int n;
117
			n = rs.getInt("n");
118
			if (n > 0){
119
				System.out.println("========================================================");
120
				System.out.println("There are " + n + " RefDetails with a note. Notes for RefDetails are not imported!");
121
				System.out.println("========================================================");
122
				success = false;
123
			}
124
		} catch (SQLException e) {
125
			e.printStackTrace();
126
		}
127
		return success;
128
	}
129

    
130
}
(10-10/19)