Skip to content

Commit

Permalink
Add importer configuration for creator and file_path
Browse files Browse the repository at this point in the history
`RecordImporter` needs to know which `User` to treat as the creator for imported
objects, and where on the file system to look for referenced file names. These
configuration options are added to `.env`, `config/importer.yml`, and
`Importer.config`. They are passed to `RecordImporter` by default on creation.

This work could be extended to allow overriding the configuration in the import
rake task by allowing that task to build a custom `RecordImporter`. For now, the
supporeted configuration is through `.env`.

Connected to #170.
  • Loading branch information
Tom Johnson committed Jan 25, 2018
1 parent e760f47 commit 0172498
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ DATACITE_HOST='"https://mds.datacite.org"'
DATACITE_LOGIN=DATACITE.DCE
DATACITE_PASSWORD=YOUR_PASSWORD_HERE
DATACITE_PREFIX=10.24354
IMPORTER_USER='import_user@example.com'
IMPORTER_USER_PASS=password
IMPORTER_FILE_PATH='spec/fixtures/'
OKCOMPUTER_LOGIN=radiohead_dev
OKCOMPUTER_PASSWORD=th0m_y0rke
SIDEKIQ_CONCURRENCY=5
Expand Down
24 changes: 23 additions & 1 deletion app/importers/importer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
# frozen_string_literal: true
class Importer < Darlingtonia::Importer
def initialize(parser:, record_importer: MahoniaRecordImporter.new)
##
# @return [Hash<Symbol, Object>]
def self.config
Rails.application.config_for(:importer)
end

def initialize(parser:, record_importer: default_record_importer)
super
end

def config
self.class.config
end

private

def default_creator
User
.first_or_create!(email: config['username'], password: config['password'])
end

def default_record_importer
MahoniaRecordImporter.new(creator: default_creator,
file_path: config['file_path'])
end
end
4 changes: 2 additions & 2 deletions app/importers/mahonia_record_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class MahoniaRecordImporter < Darlingtonia::RecordImporter
# @param file_path [String]
# @param creator [User]
def initialize(**opts)
self.creator = opts.delete(:creator) { User.first_or_create!(email: 'import_user@example.com', password: 'password') }
self.file_path = opts.delete(:file_path) { 'spec/fixtures/' }
self.creator = opts.delete(:creator) || raise(ArgumentError)
self.file_path = opts.delete(:file_path) || raise(ArgumentError)
super
end

Expand Down
15 changes: 15 additions & 0 deletions config/importer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
development:
username: <%= ENV['IMPORTER_USER'] %>
password: <%= ENV['IMPORTER_USER_PASS'] %>
file_path: <%= ENV['IMPORTER_FILE_PATH'] %>

test:
username: <%= ENV['IMPORTER_USER'] %>
password: <%= ENV['IMPORTER_USER_PASS'] %>
file_path: <%= ENV['IMPORTER_FILE_PATH'] %>

production:
username: <%= ENV['IMPORTER_USER'] %>
password: <%= ENV['IMPORTER_USER_PASS'] %>
file_path: <%= ENV['IMPORTER_FILE_PATH'] %>
17 changes: 17 additions & 0 deletions spec/importers/importer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Importer do
subject(:importer) { described_class.new(parser: parser) }
let(:file) { File.open('spec/fixtures/example.csv') }
Expand Down Expand Up @@ -27,6 +28,22 @@
expect(Etd.where(title: "Unicode Description").count).to eq 1
end

describe '.config' do
it 'has configuration attributes' do
expect(described_class.config).to include('username' => an_instance_of(String),
'password' => an_instance_of(String),
'file_path' => an_instance_of(String))
end
end

describe '#config' do
it 'has configuration attributes' do
expect(importer.config).to include('username' => an_instance_of(String),
'password' => an_instance_of(String),
'file_path' => an_instance_of(String))
end
end

context "With a BePress exported csv", :clean do
description = <<-HERE
A far ultraviolet (UV) spectroscopic ellipsometer system working up to 9 eV has been developed and applied to characterize high-K- dielectric materials. These materials have been gaining greater attention as possible substitutes for Si02 as gate dielectrics in aggressively scaled silicon devices. The optical properties of representative high-K bulk crystalline, epitaxial, and amorphous films, were investigated with far UV spectroscopic ellipsometry and some by visible-near UV optical transmission measurements. Optical dielectric functions and optical band gap energies for these materials are obtained from these studies. The spectroscopic data and results provide information that is needed to select viable alternative dielectric candidate materials with adequate band gaps, and conduction and valence band offset energies for this application, and additionally to provide an optical metrology for gate dielectric films on silicon substrates. For materials with anisotropic structure such as single crystal DySC03and GdSc03 an analysis process was developed to determine the optical constant tensor.
Expand Down

0 comments on commit 0172498

Please sign in to comment.