@@ -209,33 +209,44 @@ def osf_data
209209 render :json => @document
210210 end
211211
212+ def osf_delete
213+ @document = get_single_doc_via_search ( 1 , { :q => "id:#{ params [ :id ] } " } )
214+ authorize! :show , @document
215+ document = ShareNotify ::PushDocument . new ( "http://library.ucsd.edu/dc/collection/#{ params [ :id ] } " , osf_date ( @document ) )
216+ document . title = osf_title ( @document )
217+ document . delete
218+ share_upload ( document )
219+ redirect_to dams_collection_path ( params [ :id ] ) , notice : "Your record has been deleted from OSF Share."
220+ end
221+
212222 def osf_push
213223 @document = get_single_doc_via_search ( 1 , { :q => "id:#{ params [ :id ] } " } )
214224 authorize! :show , @document
215225 document = ShareNotify ::PushDocument . new ( "http://library.ucsd.edu/dc/collection/#{ params [ :id ] } " , osf_date ( @document ) )
216226 document . title = osf_title ( @document )
217- document . description = osf_description ( @document )
218- document . publisher = osf_publisher
219- document . languages = osf_languages ( @document )
220- document . tags = osf_mads_fields ( @document )
221227 osf_contributors ( @document ) . each do |contributor |
222228 document . add_contributor ( contributor )
223229 end
224-
230+
225231 if document . valid?
226- @headers = { 'Authorization' => "Token #{ share_config . fetch ( 'token' ) } " ,
227- 'Content-Type' => 'application/json'
228- }
229-
230- @route = "#{ share_config . fetch ( 'host' ) } api/v1/share/data"
231- @response = with_timeout { HTTParty . post ( @route , body : document . to_share . to_json , headers : @headers ) }
232+ share_upload ( document )
232233 redirect_to dams_collection_path ( params [ :id ] ) , notice : "Your record has been pushed to OSF Share."
233234 else
234235 redirect_to dams_collection_path ( params [ :id ] ) , alert : "Your record is not valid."
235236 end
236237 end
237238
238239 private
240+ def share_upload ( document )
241+ @headers = {
242+ 'Authorization' => "Bearer #{ share_config . fetch ( 'token' ) } " ,
243+ 'Content-Type' => 'application/vnd.api+json'
244+ }
245+ @route = "#{ share_config . fetch ( 'host' ) } api/v2/normalizeddata/"
246+ @body = ShareNotify ::Graph . new ( document ) . to_share_v2 . to_json
247+ @response = with_timeout { HTTParty . post ( @route , body : @body , headers : @headers ) }
248+ end
249+
239250 def share_config
240251 env = Rails . env || 'test'
241252 @config ||= YAML . load ( ERB . new ( IO . read ( File . join ( Rails . root , 'config' , 'share_notify.yml' ) ) ) . result ) [ env ] . with_indifferent_access
0 commit comments