Project

General

Profile

Download (4.07 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.berlinModel.in.validation;
11

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

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.database.update.DatabaseTypeNotSupportedException;
18
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
19
import eu.etaxonomy.cdm.io.common.IOValidator;
20
import eu.etaxonomy.cdm.io.common.Source;
21

    
22
/**
23
 * @author a.mueller
24
 * @created 17.02.2010
25
 */
26
public class BerlinModelRefDetailImportValidator implements IOValidator<BerlinModelImportState> {
27
	private static final Logger logger = Logger.getLogger(BerlinModelRefDetailImportValidator.class);
28

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

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

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

    
129
}
(10-10/19)