final void doPopulateTimeDimensions ( ) { final List < TimeDimension > timeDimensions = this . timeDimensionDao . getTimeDimensions ( ) ; if ( timeDimensions . isEmpty ( ) ) { logger . info ( "No TimeDimensions exist, creating them" ) ; } else if ( timeDimensions . size ( ) != ( 24 * 60 ) ) { this . logger . info ( "There are only " + timeDimensions . size ( ) + " time dimensions in the database, there should be " + ( 24 * 60 ) + " creating missing dimensions" ) ; } else { this . logger . debug ( "Found expected " + timeDimensions . size ( ) + " time dimensions" ) ; return ; } LocalTime nextTime = new LocalTime ( 0 , 0 ) ; final LocalTime lastTime = new LocalTime ( 23 , 59 ) ; for ( final TimeDimension timeDimension : timeDimensions ) { LocalTime dimensionTime = timeDimension . getTime ( ) ; if ( nextTime . isBefore ( dimensionTime ) ) { do { checkShutdown ( ) ; this . timeDimensionDao . createTimeDimension ( nextTime ) ; nextTime = nextTime . plusMinutes ( 1 ) ; } while ( nextTime . isBefore ( dimensionTime ) ) ; } else if ( nextTime . isAfter ( dimensionTime ) ) { do { checkShutdown ( ) ; this . timeDimensionDao . createTimeDimension ( dimensionTime ) ; dimensionTime = dimensionTime . plusMinutes ( 1 ) ; } while ( nextTime . isAfter ( dimensionTime ) ) ; } nextTime = dimensionTime . plusMinutes ( 1 ) ; } // Add any missing times from the tail while ( nextTime . isBefore ( lastTime ) || nextTime . equals ( lastTime ) ) { checkShutdown ( ) ; this . timeDimensionDao . createTimeDimension ( nextTime ) ; if ( nextTime . equals ( lastTime ) ) { break ; } nextTime = nextTime . plusMinutes ( 1 ) ; } }
Populate the time dimensions