25
25
import static com .conveyal .analysis .util .HttpUtils .getFormField ;
26
26
import static com .conveyal .file .FileCategory .DATASOURCES ;
27
27
import static com .conveyal .file .FileStorageFormat .SHP ;
28
- import static com .google .common .base .Preconditions .checkNotNull ;
29
- import static com .google .common .base .Preconditions .checkState ;
30
28
31
29
/**
32
30
* 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 {
51
49
*/
52
50
private DataSourceIngester ingester ;
53
51
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
-
60
52
// This method is a stopgaps - it seems like this should be done differently.
61
53
public String getDataSourceName () {
62
54
return ingester .dataSource ().name ;
@@ -77,8 +69,8 @@ public DataSourceUploadAction (
77
69
@ Override
78
70
public final void action (ProgressListener progressListener ) throws Exception {
79
71
progressListener .setWorkProduct (ingester .dataSource ().toWorkProduct ());
80
- moveFilesIntoStorage (progressListener );
81
- ingester .ingest (file , progressListener );
72
+ File dataSourceFile = moveFilesIntoStorage (progressListener );
73
+ ingester .ingest (dataSourceFile , progressListener );
82
74
dataSourceCollection .insert (ingester .dataSource ());
83
75
}
84
76
@@ -90,11 +82,12 @@ public final void action (ProgressListener progressListener) throws Exception {
90
82
* We should also consider whether preprocessing like conversion of GTFS to MapDBs should happen at this upload
91
83
* stage. If so, then this logic needs to change a bit.
92
84
*/
93
- private final void moveFilesIntoStorage (ProgressListener progressListener ) {
85
+ private File moveFilesIntoStorage (ProgressListener progressListener ) {
94
86
// Loop through uploaded files, registering the extensions and writing to storage
95
87
// (with filenames that correspond to the source id)
96
88
progressListener .beginTask ("Moving files into storage..." , 1 );
97
89
final String dataSourceId = ingester .dataSource ()._id .toString ();
90
+ File dataSourceFile = null ;
98
91
for (File file : files ) {
99
92
// Use canonical extension from file type - files may be uploaded with e.g. tif instead of tiff or geotiff.
100
93
String extension = ingester .dataSource ().fileFormat .extension ;
@@ -106,11 +99,14 @@ private final void moveFilesIntoStorage (ProgressListener progressListener) {
106
99
FileStorageKey key = new FileStorageKey (DATASOURCES , dataSourceId , extension );
107
100
fileStorage .moveIntoStorage (key , file );
108
101
if (files .size () == 1 || extension .equalsIgnoreCase (SHP .extension )) {
109
- file = fileStorage .getFile (key );
102
+ dataSourceFile = fileStorage .getFile (key );
110
103
}
111
104
}
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 ;
114
110
}
115
111
116
112
/**
0 commit comments