19
19
import java .io .Serializable ;
20
20
import java .util .Arrays ;
21
21
import java .util .Collection ;
22
- import java .util .Date ;
23
22
import java .util .Enumeration ;
24
23
import java .util .LinkedList ;
25
24
import java .util .List ;
@@ -50,7 +49,7 @@ private GtfsPlusValidation (String feedVersionId) {
50
49
* FIXME: For now this uses the MapDB-backed GTFSFeed class. Which actually suggests that this might
51
50
* should be contained within a MonitorableJob.
52
51
*/
53
- public static GtfsPlusValidation validate (String feedVersionId ) throws IOException {
52
+ public static GtfsPlusValidation validate (String feedVersionId ) throws Exception {
54
53
GtfsPlusValidation validation = new GtfsPlusValidation (feedVersionId );
55
54
if (!DataManager .isModuleEnabled ("gtfsplus" )) {
56
55
throw new IllegalStateException ("GTFS+ module must be enabled in server.yml to run GTFS+ validation." );
@@ -60,7 +59,15 @@ public static GtfsPlusValidation validate(String feedVersionId) throws IOExcepti
60
59
FeedVersion feedVersion = Persistence .feedVersions .getById (feedVersionId );
61
60
// Load the main GTFS file.
62
61
// FIXME: Swap MapDB-backed GTFSFeed for use of SQL data?
63
- GTFSFeed gtfsFeed = GTFSFeed .fromFile (feedVersion .retrieveGtfsFile ().getAbsolutePath ());
62
+ String gtfsFeedDbFilePath = gtfsPlusStore .getPathToFeed (feedVersionId + ".db" );
63
+ // This check for existence must occur before GTFSFeed is instantiated (and the file must be discarded
64
+ // immediately).
65
+ boolean dbExists = new File (gtfsFeedDbFilePath ).isFile ();
66
+ GTFSFeed gtfsFeed = new GTFSFeed (gtfsFeedDbFilePath );
67
+ if (!dbExists ) {
68
+ LOG .info ("Loading GTFS file into new MapDB file (.db)." );
69
+ gtfsFeed .loadFromFile (new ZipFile (feedVersion .retrieveGtfsFile ().getAbsolutePath ()));
70
+ }
64
71
// check for saved GTFS+ data
65
72
File file = gtfsPlusStore .getFeed (feedVersionId );
66
73
if (file == null ) {
@@ -85,6 +92,7 @@ public static GtfsPlusValidation validate(String feedVersionId) throws IOExcepti
85
92
}
86
93
}
87
94
}
95
+ gtfsFeed .close ();
88
96
LOG .info ("GTFS+ tables found: {}/{}" , gtfsPlusTableCount , DataManager .gtfsPlusConfig .size ());
89
97
return validation ;
90
98
}
0 commit comments