Project

General

Profile

« Previous | Next » 

Revision 34743ac7

Added by Andreas Müller over 4 years ago

ref #8508, ref #8577 treeindex test for E+M validation and common base class for E+M and Erms validation

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/validate/PesiErmsValidator.java
27 27
 * @author a.mueller
28 28
 * @since 01.09.2019
29 29
 */
30
public class PesiErmsValidator {
30
public class PesiErmsValidator extends PesiValidatorBase {
31 31

  
32 32
    private static final Logger logger = Logger.getLogger(PesiErmsValidator.class);
33 33

  
34 34
    private static final Source defaultSource = PesiSources.PESI2019_ERMS_2019();
35
    private static final Source defaultDestination = PesiDestinations.pesi_test_local_CDM_ERMS2PESI();
36
//    private static final Source defaultDestination = PesiDestinations.pesi_test_local_CDM_ERMS2PESI_2();
35
//    private static final Source defaultDestination = PesiDestinations.pesi_test_local_CDM_ERMS2PESI();
36
    private static final Source defaultDestination = PesiDestinations.pesi_test_local_CDM_ERMS2PESI_2();
37 37

  
38 38
    private Source source = defaultSource;
39 39
    private Source destination = defaultDestination;
......
427 427
        }
428 428
    }
429 429

  
430
    private boolean testTreeIndex(ResultSet destRS, String childIndexAttr, String parentIndexAttr, String id) throws SQLException {
431
        boolean result;
432
        int taxonStatusFk = destRS.getInt("TaxonStatusFk");
433
        String parentTaxonId = destRS.getString("parentTaxonFk");
434
        int rankFk = destRS.getInt("RankFk");
435
        if (taxonStatusFk == 2 || taxonStatusFk == 4 || rankFk <= 10){  //synonym; pro parte syn; kingdom and higher
436
            result = isNull(childIndexAttr, destRS, id);
437
        }else{
438
            String childIndex = destRS.getString(childIndexAttr);
439
            String parentIndex = destRS.getString(parentIndexAttr);
440
            parentIndex = parentIndex == null? "#": parentIndex;
441
            result = equals("Tree index", childIndex, parentIndex + parentTaxonId + "#", id);
442
        }
443
        return result;
444
    }
445

  
446 430
    boolean namePartsFirst = true;
447 431
    private boolean compareNameParts(ResultSet srcRS, ResultSet destRS, String id) throws SQLException {
448 432
        if (namePartsFirst){
......
904 888
        return yearStr;
905 889
    }
906 890

  
907
    private boolean isNull(String attrName, ResultSet destRS, String id) throws SQLException {
908
        Object value = destRS.getObject(attrName);
909
        if (value != null){
910
            String message = attrName + " was expected to be null but was: " + value.toString() + "; id = " + id;
911
            logger.warn(message);
912
            return false;
913
        }else{
914
            logger.info(attrName + " was null as expected; id = " + id);
915
            return true;
916
        }
917
    }
918

  
919 891
    private boolean equals(String messageStart, Timestamp srcDate, Timestamp destDate, String id) {
920 892
        if (!CdmUtils.nullSafeEqual(srcDate, destDate)){
921 893
            String message = id + ": " + messageStart + " must be equal, but was not.\n Source: "+  srcDate + "; Destination: " + destDate;
......
939 911
        }
940 912
    }
941 913

  
942
    private boolean equals(String messageStart, String strSrc, String strDest, String id) {
943
        if (StringUtils.isBlank(strSrc)){
944
            strSrc = null;
945
        }else{
946
            strSrc = strSrc.trim();
947
        }
948
        //we do not trim strDest here because this should be done during import already. If not it should be shown here
949
        if (!CdmUtils.nullSafeEqual(strSrc, strDest)){
950
            int index = CdmUtils.diffIndex(strSrc, strDest);
951
            String message = id+ ": " + messageStart + " must be equal, but was not at "+index+".\n  Source:      "+  strSrc + "\n  Destination: " + strDest;
952
            logger.warn(message);
953
            return false;
954
        }else{
955
            logger.info(id+ ": " + messageStart + " were equal: " + strSrc);
956
            return true;
957
        }
958
    }
959

  
960
    protected Integer nullSafeInt(ResultSet rs, String columnName) throws SQLException {
961
        Object intObject = rs.getObject(columnName);
962
        if (intObject == null){
963
            return null;
964
        }else{
965
            return Integer.valueOf(intObject.toString());
966
        }
967
    }
968

  
969 914
//** ************* MAIN ********************************************/
970 915

  
971

  
972

  
973 916
    public static void main(String[] args){
974 917
        PesiErmsValidator validator = new PesiErmsValidator();
975 918
        validator.invoke(defaultSource, defaultDestination);

Also available in: Unified diff