2525import static com .conveyal .analysis .util .HttpUtils .getFormField ;
2626import static com .conveyal .file .FileCategory .DATASOURCES ;
2727import static com .conveyal .file .FileStorageFormat .SHP ;
28- import static com .google .common .base .Preconditions .checkNotNull ;
29- import static com .google .common .base .Preconditions .checkState ;
3028
3129/**
3230 * Given a batch of uploaded files, put them into FileStorage, categorize and validate them, and record metadata as
@@ -51,12 +49,6 @@ public class DataSourceUploadAction implements TaskAction {
5149 */
5250 private DataSourceIngester ingester ;
5351
54- /**
55- * The file to be ingested, after it has been moved into storage. For Shapefiles and other such "sidecar" formats,
56- * this is the main file (.shp), with the same base name and in the same directory as all its sidecar files.
57- */
58- private File file ;
59-
6052 // This method is a stopgaps - it seems like this should be done differently.
6153 public String getDataSourceName () {
6254 return ingester .dataSource ().name ;
@@ -77,8 +69,8 @@ public DataSourceUploadAction (
7769 @ Override
7870 public final void action (ProgressListener progressListener ) throws Exception {
7971 progressListener .setWorkProduct (ingester .dataSource ().toWorkProduct ());
80- moveFilesIntoStorage (progressListener );
81- ingester .ingest (file , progressListener );
72+ File dataSourceFile = moveFilesIntoStorage (progressListener );
73+ ingester .ingest (dataSourceFile , progressListener );
8274 dataSourceCollection .insert (ingester .dataSource ());
8375 }
8476
@@ -90,11 +82,12 @@ public final void action (ProgressListener progressListener) throws Exception {
9082 * We should also consider whether preprocessing like conversion of GTFS to MapDBs should happen at this upload
9183 * stage. If so, then this logic needs to change a bit.
9284 */
93- private final void moveFilesIntoStorage (ProgressListener progressListener ) {
85+ private File moveFilesIntoStorage (ProgressListener progressListener ) {
9486 // Loop through uploaded files, registering the extensions and writing to storage
9587 // (with filenames that correspond to the source id)
9688 progressListener .beginTask ("Moving files into storage..." , 1 );
9789 final String dataSourceId = ingester .dataSource ()._id .toString ();
90+ File dataSourceFile = null ;
9891 for (File file : files ) {
9992 // Use canonical extension from file type - files may be uploaded with e.g. tif instead of tiff or geotiff.
10093 String extension = ingester .dataSource ().fileFormat .extension ;
@@ -106,11 +99,14 @@ private final void moveFilesIntoStorage (ProgressListener progressListener) {
10699 FileStorageKey key = new FileStorageKey (DATASOURCES , dataSourceId , extension );
107100 fileStorage .moveIntoStorage (key , file );
108101 if (files .size () == 1 || extension .equalsIgnoreCase (SHP .extension )) {
109- file = fileStorage .getFile (key );
102+ dataSourceFile = fileStorage .getFile (key );
110103 }
111104 }
112- checkNotNull (file );
113- checkState (file .exists ());
105+
106+ if (dataSourceFile == null || !dataSourceFile .exists ()) {
107+ throw new DataSourceException ("Uploaded file cannot be found." );
108+ }
109+ return dataSourceFile ;
114110 }
115111
116112 /**
0 commit comments