Project

General

Profile

Download (3.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.io.berlinModel.in.BerlinModelImportConfigurator;
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
 * @since 17.02.2010
25
 */
26
public class BerlinModelOccurrenceSourceImportValidator implements IOValidator<BerlinModelImportState> {
27
	private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceSourceImportValidator.class);
28

    
29
	@Override
30
    public boolean validate(BerlinModelImportState state) {
31
		boolean result = true;
32
		BerlinModelImportConfigurator config = state.getConfig();
33
        result &= checkSourcesWithWhitespace(config);
34
		return result;
35
	}
36

    
37

    
38
	//******************************** CHECK *************************************************
39

    
40
    private static boolean checkSourcesWithWhitespace(BerlinModelImportConfigurator config){
41
        try {
42
            boolean result = true;
43
            Source source = config.getSource();
44
            String strSelect = " SELECT OccurrenceSourceId, OccurrenceFk, Source, SourceNumber, OldName, OldNameFk, PreferredReferenceFlag ";
45
            String strCount = " count(*) ";
46
            String strQueryBase =
47
                    " FROM emOccurrenceSource " +
48
                    " WHERE SourceNumber LIKE '% %' ";
49

    
50
            ResultSet rs = source.getResultSet(strCount + strQueryBase);
51
            rs.next();
52
            int n = rs.getInt("n");
53
            if (n > 0){
54
                System.out.println("=======================================================================");
55
                System.out.println("There are "+n+" occurrence source numbers with whitespace!");
56
                System.out.println("---------------------------------------------------------------");
57
                System.out.println(strSelect + strQueryBase);
58
                System.out.println("=======================================================================");
59
            }
60

    
61
            rs = source.getResultSet(strSelect + strQueryBase);
62
            while (rs.next()){
63
                int occurrenceSourceId = rs.getInt("OccurrenceSourceId");
64
                String sourceNumber = rs.getString("SourceNumber");
65
                String Source = rs.getString("Source");
66

    
67
                System.out.println("OccurrenceSourceId:" + occurrenceSourceId +
68
                        "\n  Source Number: " + sourceNumber +
69
                        "\n  Source: " + Source)
70
                        ;
71
            }
72

    
73
            return result;
74
        } catch (SQLException e) {
75
            e.printStackTrace();
76
            return false;
77
        }
78
    }
79

    
80

    
81
}
(9-9/19)