Skip to content

Commit

Permalink
uodate state for ethz dois. datacite/datacite#793
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 30, 2019
1 parent f88f672 commit 6e35753
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/jobs/url_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def perform(doi_id)
response = Doi.get_doi(doi: doi.doi, agency: doi.agency)
url = response.body.dig('data', 'values', 0, 'data', 'value')
if url.present?
if (doi.is_registered_or_findable? || %w(europ crossref medra kisti jalc op).include?(doi.provider_id)) && doi.minted.blank?
if (doi.is_registered_or_findable? || %w(ethz europ crossref medra kisti jalc op).include?(doi.provider_id)) && doi.minted.blank?
doi.update_attributes(url: url, minted: Time.zone.now)
else
doi.update_attributes(url: url)
end

doi.update_attributes(aasm_state: "findable") if %w(europ crossref medra kisti jalc op).include?(doi.provider_id)
doi.update_attributes(aasm_state: "findable") if %w(ethz europ crossref medra kisti jalc op).include?(doi.provider_id)

doi.__elasticsearch__.index_document

Expand Down
10 changes: 5 additions & 5 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -727,19 +727,19 @@ def self.delete_dois_by_prefix(prefix, options={})
end

# register DOIs in the handle system that have not been registered yet
# providers ethz and europ register their DOIs in the handle system themselves and are ignored
# provider europ registers their DOIs in the handle system themselves and are ignored
def self.set_handle
logger = Logger.new(STDOUT)

response = Doi.query("-registered:* +url:* -aasm_state:draft -provider_id:ethz -provider_id:europ", page: { size: 1, cursor: [] })
response = Doi.query("-registered:* +url:* -aasm_state:draft -provider_id:europ -agency:Crossref", page: { size: 1, cursor: [] })
logger.info "#{response.results.total} DOIs found that are not registered in the Handle system."

if response.results.total > 0
# walk through results using cursor
cursor = []

while response.results.results.length > 0 do
response = Doi.query("-registered:* +url:* -aasm_state:draft -provider_id:ethz -provider_id:europ", page: { size: 1000, cursor: cursor })
response = Doi.query("-registered:* +url:* -aasm_state:draft -provider_id:europ -agency:Crossref", page: { size: 1000, cursor: cursor })
break unless response.results.results.length > 0

logger.info "[Handle] Register #{response.results.results.length} DOIs in the handle system starting with _id #{response.results.to_a.first[:_id]}."
Expand Down Expand Up @@ -779,15 +779,15 @@ def self.set_url
def self.set_minted
logger = Logger.new(STDOUT)

response = Doi.query("url:* +provider_id:ethz +aasm_state:draft", page: { size: 1, cursor: [] })
response = Doi.query("provider_id:ethz AND +aasm_state:draft +url:*", page: { size: 1, cursor: [] })
logger.info "#{response.results.total} draft DOIs from provider ETHZ found in the database."

if response.results.total > 0
# walk through results using cursor
cursor = []

while response.results.results.length > 0 do
response = Doi.query("url:* +provider_id:ethz +aasm_state:draft", page: { size: 1000, cursor: cursor })
response = Doi.query("provider_id:ethz AND +aasm_state:draft +url:*", page: { size: 1000, cursor: cursor })
break unless response.results.results.length > 0

logger.info "[MySQL] Set minted for #{response.results.results.length} DOIs starting with _id #{response.results.to_a.first[:_id]}."
Expand Down

0 comments on commit 6e35753

Please sign in to comment.