@@ -161,13 +161,9 @@ private Command getRailsPortApiCommand(String jobId, GrailParams params) throws
161161 return command ;
162162 }
163163
164- private Command getPublicOverpassCommand (String jobId , Users user , String bounds , String output ) {
165- //TODO: is there an availability check for overpass?
166- GrailParams params = new GrailParams ();
167- params .setUser (user );
168- params .setBounds (bounds );
164+ private Command getPublicOverpassCommand (String jobId , GrailParams params ) {
169165 params .setPullUrl (PUBLIC_OVERPASS_URL );
170- params . setOutput ( output );
166+
171167 InternalCommand command = overpassCommandFactory .build (jobId , params , this .getClass ());
172168 return command ;
173169 }
@@ -201,6 +197,7 @@ public Response createDifferentialChangeset(@Context HttpServletRequest request,
201197
202198 Users user = Users .fromRequest (request );
203199 advancedUserCheck (user );
200+ reqParams .setUser (user );
204201
205202 String jobId = "grail_" + UUID .randomUUID ().toString ().replace ("-" , "" );
206203
@@ -214,26 +211,29 @@ public Response createDifferentialChangeset(@Context HttpServletRequest request,
214211 }
215212
216213 List <Command > workflow = new LinkedList <>();
217- String bbox = reqParams .getBounds ();
218214
219215 JSONObject jobInfo = new JSONObject ();
220216 jobInfo .put ("jobid" , jobId );
221217
222218 // Pull reference data from Rails port OSM API
223219 File referenceOSMFile = new File (workDir , REFERENCE + ".osm" );
224- reqParams .setOutput (referenceOSMFile .getAbsolutePath ());
220+ GrailParams getRailsParams = new GrailParams (reqParams );
221+ getRailsParams .setOutput (referenceOSMFile .getAbsolutePath ());
225222
226223 if (referenceOSMFile .exists ()) referenceOSMFile .delete ();
227224 try {
228- workflow .add (getRailsPortApiCommand (jobId , reqParams ));
225+ workflow .add (getRailsPortApiCommand (jobId , getRailsParams ));
229226 } catch (UnavailableException ex ) {
230227 return Response .status (Response .Status .SERVICE_UNAVAILABLE ).entity (ex .getMessage ()).build ();
231228 }
232229
233230 // Pull secondary data from the Public Overpass API
234231 File secondaryOSMFile = new File (workDir , SECONDARY + ".osm" );
232+ GrailParams getOverpassParams = new GrailParams (reqParams );
233+ getOverpassParams .setOutput (secondaryOSMFile .getAbsolutePath ());
234+
235235 if (secondaryOSMFile .exists ()) secondaryOSMFile .delete ();
236- workflow .add (getPublicOverpassCommand (jobId , user , bbox , secondaryOSMFile . getAbsolutePath () ));
236+ workflow .add (getPublicOverpassCommand (jobId , getOverpassParams ));
237237
238238 // Run the differential conflate command.
239239 GrailParams params = new GrailParams ();
@@ -437,17 +437,17 @@ public Response differentialPush(@Context HttpServletRequest request,
437437 if (resourceId != null ) {
438438 // Setup workflow to refresh rails data after the push
439439 long referenceId = DbUtils .getMergedReference (resourceId );
440+ Long parentFolderId = DbUtils .getParentFolder (referenceId );
440441 Map <String , String > mapTags = DbUtils .getMapsTableTags (referenceId );
441442
442443 GrailParams refreshParams = new GrailParams ();
443444 refreshParams .setUser (user );
444445 refreshParams .setWorkDir (workDir );
445446 refreshParams .setOutput (DbUtils .getDisplayNameById (referenceId ));
446447 refreshParams .setBounds (mapTags .get ("bbox" ));
447- refreshParams .setParentId ("grail_" + mapTags .get ("bbox" ).replace ("," , "_" ));
448448
449449 try {
450- List <Command > refreshWorkflow = setupRailsPull (jobId , refreshParams );
450+ List <Command > refreshWorkflow = setupRailsPull (jobId , refreshParams , parentFolderId );
451451 workflow .addAll (refreshWorkflow );
452452 }
453453 catch (UnavailableException exc ) {
@@ -576,6 +576,7 @@ public Response deriveChangeset(@Context HttpServletRequest request,
576576 @ Path ("/pulloverpasstodb" )
577577 @ Produces (MediaType .APPLICATION_JSON )
578578 public Response pullOverpassToDb (@ Context HttpServletRequest request ,
579+ @ QueryParam ("folderId" ) Long folderId ,
579580 GrailParams reqParams ) {
580581
581582 Users user = Users .fromRequest (request );
@@ -584,7 +585,6 @@ public Response pullOverpassToDb(@Context HttpServletRequest request,
584585 String bbox = reqParams .getBounds ();
585586 String layerName = reqParams .getInput1 ();
586587 String jobId = UUID .randomUUID ().toString ().replace ("-" , "" );
587- String folderName = "grail_" + bbox .replace ("," , "_" );
588588
589589 if (DbUtils .mapExists (layerName )) {
590590 throw new BadRequestException ("Record with name : " + layerName + " already exists. Please try a different name." );
@@ -596,9 +596,6 @@ public Response pullOverpassToDb(@Context HttpServletRequest request,
596596
597597 List <Command > workflow = new LinkedList <>();
598598
599- // Create the folder if it doesn't exist
600- Long folderId = DbUtils .createFolder (folderName , 0L , user .getId (), false );
601-
602599 // Write the data to the hoot db
603600 GrailParams params = new GrailParams ();
604601 params .setUser (user );
@@ -736,6 +733,7 @@ public Response overpassStats(@Context HttpServletRequest request,
736733 @ Path ("/pullrailsporttodb" )
737734 @ Produces (MediaType .APPLICATION_JSON )
738735 public Response pullRailsPortToDb (@ Context HttpServletRequest request ,
736+ @ QueryParam ("folderId" ) Long folderId ,
739737 GrailParams reqParams ) {
740738
741739 Users user = Users .fromRequest (request );
@@ -745,7 +743,6 @@ public Response pullRailsPortToDb(@Context HttpServletRequest request,
745743 String layerName = reqParams .getInput1 ();
746744 String jobId = UUID .randomUUID ().toString ().replace ("-" , "" );
747745 File workDir = new File (TEMP_OUTPUT_PATH , "grail_" + jobId );
748- String folderName = "grail_" + bbox .replace ("," , "_" );
749746
750747 if (DbUtils .mapExists (layerName )) {
751748 throw new BadRequestException ("Record with name : " + layerName + " already exists. Please try a different name." );
@@ -760,12 +757,11 @@ public Response pullRailsPortToDb(@Context HttpServletRequest request,
760757 params .setWorkDir (workDir );
761758 params .setOutput (layerName );
762759 params .setBounds (bbox );
763- params .setParentId (folderName );
764760 params .setCustomQuery (reqParams .getCustomQuery ());
765761
766762 List <Command > workflow ;
767763 try {
768- workflow = setupRailsPull (jobId , params );
764+ workflow = setupRailsPull (jobId , params , folderId );
769765 }
770766 catch (UnavailableException exc ) {
771767 return Response .status (Response .Status .SERVICE_UNAVAILABLE ).entity (exc .getMessage ()).build ();
@@ -779,7 +775,7 @@ public Response pullRailsPortToDb(@Context HttpServletRequest request,
779775 return response ;
780776 }
781777
782- private List <Command > setupRailsPull (String jobId , GrailParams params ) throws UnavailableException {
778+ private List <Command > setupRailsPull (String jobId , GrailParams params , Long parentFolderId ) throws UnavailableException {
783779 List <Command > workflow = new LinkedList <>();
784780
785781 Users user = params .getUser ();
@@ -811,11 +807,8 @@ private List<Command> setupRailsPull(String jobId, GrailParams params) throws Un
811807 InternalCommand setMapTags = setMapTagsCommandFactory .build (tags , jobId );
812808 workflow .add (setMapTags );
813809
814- // Create the folder if it doesn't exist
815- Long folderId = DbUtils .createFolder (params .getParentId (), 0L , user .getId (), false );
816-
817810 // Move the data to the folder
818- InternalCommand setFolder = updateParentCommandFactory .build (jobId , folderId , params .getOutput (), user , this .getClass ());
811+ InternalCommand setFolder = updateParentCommandFactory .build (jobId , parentFolderId , params .getOutput (), user , this .getClass ());
819812 workflow .add (setFolder );
820813
821814 return workflow ;
0 commit comments