Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError: undefined method `deduplication_field' for nil:NilClass #106

Open
dutr5288 opened this issue Oct 24, 2020 · 0 comments
Open

Comments

@dutr5288
Copy link

dutr5288 commented Oct 24, 2020

I was trying to follow the example creating a custom importer and mapper class.

require 'zizia'

class MyImporter
  def initialize(csv_file)
    @csv_file = csv_file
    raise "Cannot find expected input file #{csv_file}" unless File.exist?(csv_file)
  end

  def import
    attrs = {
      collection_id: 'id',     # pass a collection id to the record importer and all records will be added to that collection
      depositor_id: 'id',       # pass a Hyrax user_key here and that Hyrax user will own all objects created during this import
      deduplication_field: 'identifier' # pass a field with a persistent identifier (e.g., ARK) and it will check to see if a record with that identifier already
    }                                   # exists, update its metadata if so, and only if it doesn't find a record with that identifier will it make a new object.

    file = File.open(@csv_file)
    parser = Zizia::CsvParser.new(file: file)
    record_importer = Zizia::HyraxRecordImporter.new(attributes: attrs)
    Zizia::Importer.new(parser: parser, record_importer: record_importer).import
    file.close # unless a block is passed to File.open, the file must be explicitly closed
  end
end

my task:

 namespace :basic_import do
    desc 'Ingest sample data'
    task sample: [:environment] do
      csv_file = Rails.root.join('app', 'importers', 'csv.csv')
      ModularImporter.new(csv_file).import
    end
  end

my command to run the import task:

rake basic_import:sample --trace

However i got this error
Screen Shot 2020-10-24 at 3 49 28 AM

I understand what is the error talking about, but could not figure it out why. This CSV file has been imported successfully from UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant