Skip to content

Commit

Permalink
Merge pull request #1900 from datadryad/journal-dpc
Browse files Browse the repository at this point in the history
Correct payment workflow for partner entities
  • Loading branch information
ryscher authored Nov 4, 2024
2 parents 8e3ce30 + 585a080 commit e673670
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/controllers/stash_datacite/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def review

def submission
@resource.current_state = 'processing'
@resource.identifier.record_payment
@resource.identifier.record_payment unless @resource.identifier.publication_date.present?
@resource.check_add_readme_file
@resource.check_add_cedar_json

Expand Down
7 changes: 3 additions & 4 deletions app/models/stash_engine/identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ def user_must_pay?
end

def record_payment
# once we have assigned payment to an entity, keep that entity,
# unless it was a journal that the submission is no longer affiliated with
# (in general, we don't want to tell a user their payment is covered and then later take it away)
# once we have assigned payment to an entity, keep that entity
# unless it was a journal that was removed or a new journal covers the dpc
clear_payment_for_changed_journal
return if payment_type.present? && payment_type != 'unknown'

Expand Down Expand Up @@ -637,7 +636,7 @@ def datacite_available_date

def clear_payment_for_changed_journal
return unless payment_type.present?
return unless payment_type.include?('journal')
return unless payment_type.include?('journal') || journal&.will_pay?
return if payment_id == journal&.single_issn

self.payment_type = nil
Expand Down
42 changes: 20 additions & 22 deletions lib/stash/import/crossref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def bare_doi(doi_string:)
def populate_pub_update!
return nil unless @sm.present? && @resource.present?

populate_publication_issn
populate_publication_name
populate_publication_issn
@resource.reload
end

Expand Down Expand Up @@ -362,35 +362,33 @@ def populate_publication_date
@resource.publication_date = date_parts_to_date(publication_date)
end

def populate_publication_issn
return unless @sm['ISSN'].present? && @sm['ISSN'].first.present?

# We only want to save the ISSN if we receive one that we already know about. Otherwise,
# it is likely an alternative ISSN for a journal where we have a different primary ISSN
# (most journals have separate ISSNs for print, online, linking)
# In that case, we will save the journal name, and look up the correct ISSN from the name.
return unless StashEngine::Journal.find_by_issn(@sm['ISSN'].first).present?

datum = StashEngine::ResourcePublication.find_or_initialize_by(resource_id: @resource.id)

return if @resource.journal&.id == StashEngine::Journal.find_by_issn(@sm['ISSN'].first).id

datum.publication_issn = @sm['ISSN'].first
datum.save
end

def populate_publication_name
return unless publisher.present?
# We do not want to overwrite correct journal names with nonstandardized names for the same journal
# only update the journal name if the dataset is not already set with this journal
# We do not want to overwrite correct journal names with nonstandardized names
# only update the journal name if the dataset is not already set with this journal ISSN
return if @sm['ISSN'].present? && @sm['ISSN'].first.present? && @resource.journal.present? &&
@resource.journal.id == StashEngine::Journal.find_by_issn(@sm['ISSN'].first)&.id

datum = StashEngine::ResourcePublication.find_or_initialize_by(resource_id: @resource.id)
datum.publication_name = publisher
# If the publication name matches an existing journal, populate/update the ISSN
journal = StashEngine::Journal.find_by_title(publisher)
datum.publication_issn = journal.single_issn if journal.present?
# If the publication name matches an existing journal, populate/update the ISSN
# Otherwise, remove existing ISSNs that do not match the imported journal name
datum.publication_issn = journal.present? ? journal.single_issn : nil
datum.save
end

def populate_publication_issn
return unless @sm['ISSN'].present? && @sm['ISSN'].first.present?

# Do not change the ISSN if one for this journal is already set
found = StashEngine::Journal.find_by_issn(@sm['ISSN'].first)
return if found && @resource.journal&.id == found&.id

# First look up the ISSN from the journal name (populate_publication_name).
# If we do not know the ISSN, save it for quarterly checking and addition to our db
datum = StashEngine::ResourcePublication.find_or_initialize_by(resource_id: @resource.id)
datum.publication_issn = @sm['ISSN'].first
datum.save
end

Expand Down

0 comments on commit e673670

Please sign in to comment.