protected final UpdateableNvdCve getUpdatesNeeded ( ) throws MalformedURLException , DownloadFailedException , UpdateException { LOGGER . debug ( "starting getUpdatesNeeded() ..." ) ; final UpdateableNvdCve updates = new UpdateableNvdCve ( ) ; if ( dbProperties != null && ! dbProperties . isEmpty ( ) ) { try { final int startYear = settings . getInt ( Settings . KEYS . CVE_START_YEAR , 2002 ) ; final int endYear = Calendar . getInstance ( ) . get ( Calendar . YEAR ) ; boolean needsFullUpdate = false ; for ( int y = startYear ; y <= endYear ; y ++ ) { final long val = Long . parseLong ( dbProperties . getProperty ( DatabaseProperties . LAST_UPDATED_BASE + y , "0" ) ) ; if ( val == 0 ) { needsFullUpdate = true ; break ; } } final long lastUpdated = Long . parseLong ( dbProperties . getProperty ( DatabaseProperties . LAST_UPDATED , "0" ) ) ; final long now = System . currentTimeMillis ( ) ; final int days = settings . getInt ( Settings . KEYS . CVE_MODIFIED_VALID_FOR_DAYS , 7 ) ; String url = settings . getString ( Settings . KEYS . CVE_MODIFIED_JSON ) ; MetaProperties modified = getMetaFile ( url ) ; if ( ! needsFullUpdate && lastUpdated == modified . getLastModifiedDate ( ) ) { return updates ; } else { updates . add ( MODIFIED , url , modified . getLastModifiedDate ( ) , true ) ; if ( needsFullUpdate || ! DateUtil . withinDateRange ( lastUpdated , now , days ) ) { final int start = settings . getInt ( Settings . KEYS . CVE_START_YEAR ) ; final int end = Calendar . getInstance ( ) . get ( Calendar . YEAR ) ; final String baseUrl = settings . getString ( Settings . KEYS . CVE_BASE_JSON ) ; for ( int i = start ; i <= end ; i ++ ) { url = String . format ( baseUrl , i ) ; MetaProperties meta = getMetaFile ( url ) ; long currentTimestamp = 0 ; try { currentTimestamp = Long . parseLong ( dbProperties . getProperty ( DatabaseProperties . LAST_UPDATED_BASE + i , "0" ) ) ; } catch ( NumberFormatException ex ) { LOGGER . debug ( "Error parsing '{}' '{}' from nvdcve.lastupdated" , DatabaseProperties . LAST_UPDATED_BASE , i , ex ) ; } if ( currentTimestamp < meta . getLastModifiedDate ( ) ) { updates . add ( Integer . toString ( i ) , url , meta . getLastModifiedDate ( ) , true ) ; } } } } } catch ( NumberFormatException ex ) { LOGGER . warn ( "An invalid schema version or timestamp exists in the data.properties file." ) ; LOGGER . debug ( "" , ex ) ; } catch ( InvalidSettingException ex ) { throw new UpdateException ( "The NVD CVE start year property is set to an invalid value" , ex ) ; } } return updates ; }
Determines if the index needs to be updated . This is done by fetching the NVD CVE meta data and checking the last update date . If the data needs to be refreshed this method will return the NvdCveUrl for the files that need to be updated .