Skip to content

Commit

Permalink
Add support for _mint_reserved_doi flag in CSV imports
Browse files Browse the repository at this point in the history
(cherry picked from commit 564d60a)
  • Loading branch information
elohanlon committed Feb 12, 2024
1 parent 725f6d8 commit 136ead3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/jobs/export_search_results_to_csv_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ExportSearchResultsToCsvJob

SUPPRESSED_ON_EXPORT = ['_uuid', '_data_file_path', '_dc_type', '_state', '_title', '_created', '_modified', '_created_by', '_modified_by', '_project.uri', '_project.short_label']
INTERNAL_FIELD_REGEXES_ALLOWED_ON_IMPORT = [
'_pid', '_doi', '_merge_dynamic_fields', '_publish', '_first_published', '_digital_object_type.string_key', '_import_file.import_type', '_import_file.import_path', '_import_file.original_file_path', '_import_file.service_copy_import_type', '_import_file.service_copy_import_path', '_import_file.access_copy_import_path', '_restrictions.restricted_size_image', '_restrictions.restricted_onsite',
'_pid', '_doi', '_merge_dynamic_fields', '_publish', '_first_published', '_digital_object_type.string_key', '_import_file.import_type', '_import_file.import_path', '_import_file.original_file_path', '_import_file.service_copy_import_type', '_import_file.service_copy_import_path', '_import_file.access_copy_import_path', '_restrictions.restricted_size_image', '_restrictions.restricted_onsite', '_mint_reserved_doi',
/^_publish_target_data\.(string_key|publish_url|api_key|representative_image_pid|short_title|short_description|full_description|restricted|slug|site_url)$/,
/^_parent_digital_objects-\d+\.(identifier|pid)$/, /^_identifiers-\d+$/, /^_project\.(string_key|pid)$/,
/^_publish_targets-\d+\.(string_key|pid)$/, /^_parent_digital_objects-\d+\.(identifier|pid)$/
Expand Down
1 change: 0 additions & 1 deletion app/models/concerns/digital_object/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def save(manual_commit_to_solr = true)
def before_save
# TODO: rewrite with ActiveRecord::Callbacks
# To be overridden by subclasses

mint_and_store_doi(Hyacinth::Datacite::Doi::IDENTIFIER_STATUS[:draft]) if @mint_reserved_doi_before_save || @publish_after_save
end

Expand Down
7 changes: 7 additions & 0 deletions app/models/digital_object/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def initialize
@errors = ActiveModel::Errors.new(self)
@publish_after_save = false
@doi = nil
@mint_reserved_doi_before_save = false
end

def init_from_digital_object_record_and_fedora_object(digital_object_record, fedora_obj)
Expand Down Expand Up @@ -108,6 +109,7 @@ def reset_data_attributes_before_assignment(digital_object_data)
# Updates the DigitalObject with the given digital_object_data
def set_digital_object_data(digital_object_data, merge_dynamic_fields)
publish_after_save_from_data(digital_object_data)
mint_reserved_doi_from_data(digital_object_data)

create_or_validate_pid_from_data(pid, digital_object_data)

Expand Down Expand Up @@ -208,6 +210,11 @@ def publish_after_save_from_data(digital_object_data)
@publish_after_save = digital_object_data['publish'].to_s.match?(/true/i) if digital_object_data.key?('publish')
end

def mint_reserved_doi_from_data(digital_object_data)
# If a user sets the mint_reserved_doi field to "true", set the mint_reserved_doi flag
@mint_reserved_doi_before_save = digital_object_data['mint_reserved_doi'].to_s.match?(/true/i) if digital_object_data.key?('mint_reserved_doi')
end

# Getters

def digital_object_type
Expand Down
15 changes: 15 additions & 0 deletions spec/models/digital_object/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@
end
end

describe "for any valid DigitalObject" do
it "sets @mint_reserved_doi_before_save to true when {'mint_reserved_doi' => true} is present in the digital object data" do
item = DigitalObjectType.get_model_for_string_key(sample_item_digital_object_data['digital_object_type']['string_key']).new()
item.set_digital_object_data(sample_item_digital_object_data.merge({'mint_reserved_doi' => true}), false)
expect(item.mint_reserved_doi_before_save).to eq(true)

# Reset the value
item.mint_reserved_doi_before_save = false

# Verify that it also works with a string (for CSV import scenarios)
item.set_digital_object_data(sample_item_digital_object_data.merge({'mint_reserved_doi' => 'TRUE'}), false)
expect(item.mint_reserved_doi_before_save).to eq(true)
end
end

describe "for DigitalObject::Group" do

it "works for a Group that does not have a parent object" do
Expand Down

0 comments on commit 136ead3

Please sign in to comment.