DEPRECATION NOTICE: Darlingtonia is getting a new name and a new focus. Darlingtonia started as a command line importer tool, but in recent projects we have added UI that allows users to import directly form the Hyrax dashboard. To reflect this and other changes our importer gem will now be called Zizia. Accordingly, we are depreciating Darlingtonia and all future development will be done on Zizia. Moving forward, Zizia will not be backward compatible with Darlingtonia. The code for Darlingtonia will remain available here, but no future development will be occurring.
Object import for Hyrax. See the API documentation for more
information. See the Getting Started guide for a gentle introduction.
Darlingtonia californica, also called the California pitcher plant, cobra lily, or cobra plant, is a species of carnivorous plant, the sole member of the genus Darlingtonia in the family Sarraceniaceae. It is native to Northern California and Oregon growing in bogs and seeps with cold running water. |
In your project's Gemfile
, add: gem 'darlingtonia'
, then run bundle install
.
To do a basic Hyrax import, first ensure that a work type is registered
with your Hyrax
application. Then write a class like this:
require 'darlingtonia'
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: collection_id, # pass a collection id to the record importer and all records will be added to that collection
depositor_id: depositor_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 = Darlingtonia::CsvParser.new(file: file)
record_importer = Darlingtonia::HyraxRecordImporter.new(attributes: attrs)
Darlingtonia::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
You can find an example csv file for import to Hyrax in the fixtures directory. Files for attachment should have the filename in a column
with a heading of files
, and the location of the files should be specified via an
environment variables called IMPORT_PATH
. If IMPORT_PATH
is not set, HyraxRecordImporter
will look in /opt/data
by default.
To input any kind of file other than CSV, you need to provide a Parser
(out of the box, we support simple CSV import with CsvParser
). We will be writing guides about
how to support custom mappers (for metadata outside of Hyrax's core and basic metadata fields).
This software is primarily intended for use in a Hyrax project.
However, its dependency on hyrax
is kept strictly optional so most of its code can be reused to
good effect elsewhere. Note: As of release 2.0, HyraxBasicMetadataMapper
will be the default mapper.
git clone https://github.com/curationexperts/darlingtonia
cd darlingtonia
bundle install
bundle exec rake ci
This gem ships with RSpec shared examples and other support tools intended to ease testing and ensure
interoperability of client code. These can be included by adding require 'darlingtonia/spec'
to a
spec_helper.rb
or rails_helper.rb
file in your application's test suite.