@@ -192,58 +192,24 @@ class OntologySubmissionsController < ApplicationController
192192 included = Ontology . goo_attrs_to_load . concat ( [ submissions : submission_attributes ] )
193193 ont = Ontology . find ( acronym ) . include ( included ) . first
194194 error 422 , "You must provide an existing `acronym` to download" if ont . nil?
195- ont . bring ( :viewingRestriction ) if ont . bring? ( :viewingRestriction )
196- check_access ( ont )
197- ont_restrict_downloads = LinkedData ::OntologiesAPI . settings . restrict_download
198- error 403 , "License restrictions on download for #{ acronym } " if ont_restrict_downloads . include? acronym
195+ enforce_download_access ( ont )
199196 submission = ont . submission ( params [ 'ontology_submission_id' ] . to_i )
200197 error 404 , "There is no such submission for download" if submission . nil?
201- file_path = submission . uploadFilePath
202- # handle edge case where uploadFilePath is not set
203- error 422 , "Upload File Path is not set for this submission" if file_path . to_s . empty?
204- download_format = params [ "download_format" ] . to_s . downcase
205- allowed_formats = [ "csv" , "rdf" ]
206- if download_format . empty?
207- file_path = submission . uploadFilePath
208- elsif ( [ download_format ] - allowed_formats ) . length > 0
209- error 400 , "Invalid download format: #{ download_format } ."
210- elsif download_format . eql? ( "csv" )
211- if ont . latest_submission . id != submission . id
212- error 400 , "Invalid download format: #{ download_format } ."
213- else
214- latest_submission . bring ( ontology : [ :acronym ] )
215- file_path = submission . csv_path
216- end
217- elsif download_format . eql? ( "rdf" )
218- file_path = submission . rdf_path
219- end
220-
221- if File . readable? file_path
222- send_file file_path , :filename => File . basename ( file_path )
223- else
224- error 500 , "Cannot read submission upload file: #{ file_path } "
225- end
198+ send_submission_download ( ont , submission , params [ "download_format" ] )
226199 end
227200
228201 ##
229202 # Download a submission diff file
230203 get '/:ontology_submission_id/download_diff' do
231204 acronym = params [ "acronym" ]
232205 submission_attributes = [ :submissionId , :submissionStatus , :diffFilePath ]
233- ont = Ontology . find ( acronym ) . include ( :submissions => submission_attributes ) . first
206+ included = Ontology . goo_attrs_to_load . concat ( [ submissions : submission_attributes ] )
207+ ont = Ontology . find ( acronym ) . include ( included ) . first
234208 error 422 , "You must provide an existing `acronym` to download" if ont . nil?
235- ont . bring ( :viewingRestriction )
236- check_access ( ont )
237- ont_restrict_downloads = LinkedData ::OntologiesAPI . settings . restrict_download
238- error 403 , "License restrictions on download for #{ acronym } " if ont_restrict_downloads . include? acronym
209+ enforce_download_access ( ont )
239210 submission = ont . submission ( params [ 'ontology_submission_id' ] . to_i )
240211 error 404 , "There is no such submission for download" if submission . nil?
241- file_path = submission . diffFilePath
242- if File . readable? file_path
243- send_file file_path , :filename => File . basename ( file_path )
244- else
245- error 500 , "Cannot read submission diff file: #{ file_path } "
246- end
212+ send_submission_download ( ont , submission , "diff" )
247213 end
248214
249215 def delete_submissions ( startId , endId )
0 commit comments