Project

General

Profile

Revision 0d76bb7d

ID0d76bb7da68666fba6f91d0396e626c354c7b580
Parent d0c77267
Child 71571fbe

Added by Andreas Müller almost 2 years ago

add tests for occurrences sources with unwanted whitespaces

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelOccurrenceImportValidator.java
25 25
 * @since 17.02.2010
26 26
 */
27 27
public class BerlinModelOccurrenceImportValidator implements IOValidator<BerlinModelImportState> {
28
	private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceImportValidator.class);
28
	@SuppressWarnings("unused")
29
    private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceImportValidator.class);
29 30

  
30 31
	@Override
31 32
	public boolean validate(BerlinModelImportState state) {
32 33
		boolean result = true;
33
		BerlinModelImportConfigurator bmiConfig = state.getConfig();
34
		result &= checkTaxonIsAccepted(bmiConfig);
35
		//result &= checkPartOfJournal(bmiConfig);
36
		System.out.println("Checking for Occurrence not yet fully implemented");
34
		BerlinModelImportConfigurator config = state.getConfig();
35
		result &= checkTaxonIsAccepted(config);
36
		result &= checkSourcesWithWhitespace(config);
37 37
		return result;
38 38
	}
39 39

  
......
71 71

  
72 72
				}
73 73
				int occurrenceId = resultSet.getInt("OccurrenceId");
74
//					int statusFk = resulSet.getInt("StatusFk");
74
//			    int statusFk = resulSet.getInt("StatusFk");
75 75
				String status = resultSet.getString("Status");
76 76
				String fullNameCache = resultSet.getString("FullNameCache");
77 77
				String ptRefFk = resultSet.getString("PTRefFk");
......
92 92
		}
93 93
	}
94 94

  
95
    private static boolean checkSourcesWithWhitespace(BerlinModelImportConfigurator config){
96
        try {
97
            boolean result = true;
98
            Source source = config.getSource();
99
            String strSelect = "SELECT OccurrenceId, PTNameFk, PTRefFk, AreaFk, Sources, Created_When, Created_Who, Updated_When, Updated_Who, Notes, Occurrence ";
100
            String strCount = " count(*) ";
101
            String strQueryBase =
102
                    " FROM emOccurrence " +
103
                    " WHERE (Sources LIKE '%  %') OR (Sources LIKE '% ') OR (Sources LIKE ' %') ";
104

  
105
            ResultSet rs = source.getResultSet(strCount + strQueryBase);
106
            rs.next();
107
            int n = rs.getInt("n");
108
            if (n > 0){
109
                System.out.println("=======================================================================");
110
                System.out.println("There are "+n+" occurrences with source attribute has unexpected whitespace!");
111
                System.out.println("---------------------------------------------------------------");
112
                System.out.println(strSelect + strQueryBase);
113
                System.out.println("=======================================================================");
114
            }
115

  
116
            rs = source.getResultSet(strSelect + strQueryBase);
117
            while (rs.next()){
118
                int occurrenceId = rs.getInt("OccurrenceId");
119
                String sources = rs.getString("Sources");
120

  
121
                System.out.println("OccurrenceSourceId:" + occurrenceId +
122
                        "\n  Sources: " + sources)
123
                        ;
124
            }
125
            return result;
126
        } catch (SQLException e) {
127
            e.printStackTrace();
128
            return false;
129
        }
130
    }
95 131
}
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelOccurrenceSourceImportValidator.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
26 26
public class BerlinModelOccurrenceSourceImportValidator implements IOValidator<BerlinModelImportState> {
27 27
	private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceSourceImportValidator.class);
28 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) {
29
	@Override
30
    public boolean validate(BerlinModelImportState state) {
33 31
		boolean result = true;
34
		BerlinModelImportConfigurator bmiConfig = state.getConfig();
35
//		result &= checkTaxonIsAccepted(bmiConfig);
36
		//result &= checkPartOfJournal(bmiConfig);
37
		System.out.println("Checking for OccurrenceSources not yet implemented");
32
		BerlinModelImportConfigurator config = state.getConfig();
33
        result &= checkSourcesWithWhitespace(config);
38 34
		return result;
39 35
	}
40
	
41
	
36

  
37

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

  
84 80

  
85 81
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)