@@ -19,8 +19,7 @@ def create
1919 @submission = Submission . new ( submission_params )
2020 @submission . user = current_user
2121 if @submission . save
22- process_submission ( @submission )
23- flash . notice = 'Your Submission is now in progress.'
22+ process_submission
2423 redirect_to submissions_path
2524 else
2625 render 'new'
@@ -33,10 +32,34 @@ def package
3332
3433 private
3534
36- def process_submission ( submission )
37- # this will likely want to be an asynch job queue
38- # to create the package and handle the sword submission
39- submission . to_sword_package
35+ def process_submission
36+ @submission . to_sword_package
37+ sword = Sword . new ( @submission )
38+ begin
39+ sword . deposit
40+ read_sword_response ( sword )
41+ rescue RestClient ::Unauthorized
42+ @submission . status = 'failed'
43+ flash . notice = 'There was a problem with your submission.'
44+ end
45+ @submission . save
46+ end
47+
48+ def read_sword_response ( sword )
49+ deposited ( sword ) if sword . response . code == 201
50+ queued if sword . response . code == 202
51+ end
52+
53+ def deposited ( sword )
54+ @submission . status = 'deposited'
55+ @submission . handle = sword . handle
56+ flash . notice =
57+ "Your Submission succeeded. Permanent URL: #{ @submission . handle } "
58+ end
59+
60+ def queued
61+ @submission . status = 'in review queue'
62+ flash . notice = 'Your Submission is now in progress.'
4063 end
4164
4265 def submission_params
0 commit comments