Show
Ignore:
Timestamp:
12/04/11 13:10:15 (6 months ago)
Author:
martijn
Message:

QC on database capabilities

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/org.bridgedb.tools.qc/src/org/bridgedb/tools/qc/BridgeQC.java

    r553 r554  
    33import java.sql.Connection; 
    44import java.sql.SQLException; 
     5import java.text.ParseException; 
     6import java.text.SimpleDateFormat; 
     7import java.util.Date; 
    58import java.util.HashMap; 
    69import java.util.Map; 
     
    1013import org.bridgedb.IDMapperException; 
    1114import org.bridgedb.bio.BioDataSource; 
     15import org.bridgedb.bio.Organism; 
    1216import org.bridgedb.rdb.SimpleGdb; 
    1317import org.bridgedb.rdb.SimpleGdbFactory; 
     
    133137        } 
    134138 
     139        public static boolean safeEquals (Object a, Object b) 
     140        { 
     141                return a == null ? b == null : a.equals(b); 
     142        } 
     143 
     144        public interface PropertyChecker 
     145        { 
     146                abstract void check(String oldVal, String newVal); 
     147        } 
     148         
     149        enum Props implements PropertyChecker 
     150        { 
     151                ORGANISM (true, false) { 
     152                        public void check(String oldVal, String newVal)  
     153                        { 
     154                                if (newVal != null) 
     155                                { 
     156                                        Organism o = Organism.fromLatinName(newVal); 
     157                                        if (o == null) System.out.println ("WARNING: species '" + newVal + "' is not a recognized latin name"); 
     158                                } 
     159                        } 
     160                }, 
     161                DATASOURCENAME (true, true) { 
     162                        public void check(String oldVal, String newVal) {} 
     163                }, 
     164                SERIES (true, true) { 
     165                        public void check(String oldVal, String newVal) {} 
     166                }, 
     167                DATATYPE (true, true) { 
     168                        public void check(String oldVal, String newVal) {} 
     169                }, 
     170                DATASOURCEVERSION (false, true) { 
     171                        public void check(String oldVal, String newVal) {} 
     172                }, 
     173                BUILDDATE (false, true) { 
     174                        public void check(String oldVal, String newVal) { 
     175                                SimpleDateFormat sft = new SimpleDateFormat("yyyyMMdd"); 
     176                                Date oldDate = null; 
     177                                Date newDate = null; 
     178                                try 
     179                                { 
     180                                        if (oldVal != null) 
     181                                                oldDate = sft.parse(oldVal); 
     182                                } 
     183                                catch (ParseException e) 
     184                                { 
     185                                        System.out.println ("ERROR: " + oldVal + " does not match pattern yyyymmdd");  
     186                                } 
     187                                try 
     188                                { 
     189                                        if (newVal != null) 
     190                                                newDate = sft.parse(newVal); 
     191                                } 
     192                                catch (ParseException e) 
     193                                { 
     194                                        System.out.println ("ERROR: " + oldVal + " does not match pattern yyyymmdd");  
     195                                } 
     196                                if (oldDate != null && newDate != null && oldDate.after(newDate)) 
     197                                { 
     198                                        System.out.println ("ERROR: new date " + newVal + " is older than old date " + oldVal);  
     199                                } 
     200                        } 
     201                }, 
     202                SCHEMAVERSION (false, true) { 
     203                        public void check(String oldVal, String newVal) {} 
     204                }, 
     205                ; 
     206                 
     207                private boolean mustBeSame; 
     208                private boolean mustBeDefined; 
     209                 
     210                Props(boolean mustBeSame, boolean mustBeDefined) 
     211                { 
     212                        this.mustBeSame = mustBeSame; 
     213                        this.mustBeDefined = mustBeDefined; 
     214                } 
     215                 
     216                public void checkWrap(String oldVal, String newVal) 
     217                { 
     218                        if (mustBeSame && !safeEquals (oldVal, newVal)) 
     219                                System.out.println ("WARNING: old " + name() + "'" + oldVal + "' doesn\'t match new " + name() + " '" + newVal + "'"); 
     220                        if (mustBeDefined && (newVal == null || newVal.equals(""))) 
     221                                System.out.println ("WARNING: property " + name() + " is undefined"); 
     222                        check(oldVal, newVal); 
     223                } 
     224        } 
     225         
     226        public void compareInfo() 
     227        { 
     228                for (Props p : Props.values()) 
     229                { 
     230                        p.checkWrap(oldGdb.getCapabilities().getProperty(p.name()), 
     231                                        newGdb.getCapabilities().getProperty(p.name())); 
     232                } 
     233        } 
     234         
    135235        public void run() throws IDMapperException, SQLException 
    136236        { 
    137237                initDatabases(); 
     238                compareInfo(); 
    138239                compareDataSources(); 
    139240 
     
    141242                 
    142243                compareAttributes(); 
    143                 compareFileSizes(); 
     244                compareFileSizes();              
    144245        } 
    145246