Skip to content

Commit

Permalink
fix doi request requiring the existence of publisher and creator
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Nov 7, 2024
1 parent 07a2bf4 commit 3762e8f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
5 changes: 4 additions & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ def process_doi_requests
if params['actions'].nil? || params['actions'].empty?
response[:errors] = "No operation 'actions' was specified in params for request processing"
else
response = process_identifier_requests('processed', 'processing', params['actions'])
response = process_identifier_requests('processed', 'processing',
params['actions'],
helpers.current_user.name,
helpers.portal_name)
end

if !response[:errors].blank?
Expand Down
35 changes: 18 additions & 17 deletions app/controllers/concerns/doi_request_administration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def doi_requests

doi_requests_data_parsed = JSON.parse(doi_requests_data, symbolize_names: true)

doi_requests_result = doi_requests_data_parsed.map{ |req| new_doi_request_hash(req) }
doi_requests_result = doi_requests_data_parsed.map { |req| new_doi_request_hash(req) }

response[:doi_requests] = doi_requests_result
response[:success] = 'DOI requests list generated'
Expand All @@ -27,14 +27,14 @@ def doi_requests
response
end

def process_identifier_requests(success_keyword, error_keyword, action)
def process_identifier_requests(success_keyword, error_keyword, action, current_user, portal_name)

response = { errors: '', success: '' }

if params['doi_requests'].nil? || params['doi_requests'].empty?
response[:errors] = 'No doi_requests parameter passed. Syntax: ?doi_requests=req1,req2,...,reqN'
else
doi_requests = params['doi_requests'].split(',').map { |o| o.strip }
doi_requests = params['doi_requests'].split(',').map(&:strip)
doi_requests.each do |request_id|
begin
doi_request = LinkedData::Client::Models::IdentifierRequest.find(request_id)
Expand All @@ -44,7 +44,7 @@ def process_identifier_requests(success_keyword, error_keyword, action)
error_response = nil
case action
when 'process'
error_response = process_doi(doi_request)
error_response = process_doi(doi_request, current_user, portal_name)
when 'reject'
error_response = change_request_status(doi_request, 'REJECTED') unless error_response
else
Expand All @@ -64,38 +64,40 @@ def process_identifier_requests(success_keyword, error_keyword, action)
else
response[:errors] << "Request #{request_id} was not found in the system, "
end
rescue Exception => e
rescue StandardError => e
response[:errors] << "Problem #{error_keyword} Request #{request_id} - #{e.class}: #{e.message}, "
end
end
response[:success] = response[:success][0...-2] unless response[:success].empty?
response[:errors] = response[:errors][0...-2] unless response[:errors].empty?
end
response
response
end

private

def process_doi(doi_request)
doi_req_submission = doi_request.submission
def process_doi(doi_request, current_user, portal_name)
doi_req_submission = doi_request.submission
ont_submission_id = doi_req_submission.submissionId
hash_metadata = data_cite_metadata_json(doi_req_submission.ontology, ont_submission_id)
hash_metadata = data_cite_metadata_json(doi_req_submission.ontology, ont_submission_id, current_user, portal_name)
if doi_request.requestType == 'DOI_CREATE'
satisfy_doi_creation_request(doi_request, hash_metadata, doi_req_submission)
elsif doi_request.requestType == 'DOI_UPDATE'
#satisfy_doi_update_request(doi_request, hash_metadata)
# satisfy_doi_update_request(doi_request, hash_metadata)
end
end

def data_cite_metadata_json( ontology, ont_submission_id)
def data_cite_metadata_json(ontology, ont_submission_id, current_user, portal_name)
ontology_acronym = ontology.acronym
sub_metadata_url = SUB_DATA_CITE_METADATA_URL.call(ontology_acronym, ont_submission_id)
hash_metadata = LinkedData::Client::HTTP.get(sub_metadata_url, {}, raw: true)
json = JSON.parse(hash_metadata, symbolize_names: true)

json[:titles].each {|t| t.delete(:titleType) if t[:titleType].blank? }
#json[:title] = ontology_name
json[:url] = json[:url] || (helpers.ontologies_url + '/' +ontology_acronym)
json[:titles].each { |t| t.delete(:titleType) if t[:titleType].blank? }
json[:publisher] ||= portal_name
json[:creators] ||= [{ name: current_user }]

json[:url] = json[:url] || (helpers.ontologies_url + '/' + ontology_acronym)
json
end

Expand All @@ -122,13 +124,12 @@ def datacite_response_errors(error_hash)
return errors unless error_hash && error_hash.length > 0

errors = error_hash[:error]
errors.to_a.map{|x,y| "#{x}: #{y}"}
errors.to_a.map { |x, y| "#{x}: #{y}" }
end

def satisfy_doi_creation_request(doi_request, hash_metadata, submission)
return OpenStruct.new({ errors: ['Ontology submission not found'] }) if submission.nil?


dc_response = DataciteCreatorService.new(hash_metadata).call

# If there is an error, returns it
Expand All @@ -152,7 +153,7 @@ def satisfy_doi_creation_request(doi_request, hash_metadata, submission)
end

def satisfy_doi_update_request(doi_request, hash_metadata)
#Ecoportal::DataciteSrv.update_doi_information_to_datacite(hash_metadata.to_json)
# Ecoportal::DataciteSrv.update_doi_information_to_datacite(hash_metadata.to_json)
end

def change_request_status(doi_request, new_status)
Expand Down
2 changes: 1 addition & 1 deletion app/services/datacite_creator_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def create_new_doi_from_data_cite(json_metadata)
attributes: json_metadata
}
}

url = URI(@url)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
Expand All @@ -42,6 +41,7 @@ def create_new_doi_from_data_cite(json_metadata)
request.body = data_cite_hash.to_json

response = http.request(request)

json_response = response.read_body
# convert response as json if response is a string containing a json
json_response = JSON.parse(json_response) if json_response.is_a?(String) && json_response.start_with?('{')
Expand Down

0 comments on commit 3762e8f

Please sign in to comment.