Repository navigation
Configuring Bulkrax
Bulkrax is configured in the application, mostly in one initializer. This page explains where each setting lives, how field mappings connect import columns to your work types' fields, and every setting Bulkrax 10.0 offers. To install Bulkrax and make it available to users, see Installing and enabling Bulkrax.
On this page
- Where configuration lives
- Parsers
- Field mappings
- Work Identifier
- Source Identifier
- Parent-child relationship field mappings
- Generated Metadata
- Default work type
- Required elements
- Reserved properties
- Controlled properties
- Object factory and models
- Jobs and locking
- Guided Import
- Paths and other settings
- Environment variables
- Removed settings
-
The initializer,
config/initializers/bulkrax.rb, created byrails g bulkrax:install. Settings go insideBulkrax.setup do |config| ... end. -
Hyku stores the field mappings per tenant, in the
bulkrax_field_mappingsaccount setting, which overrides the initializer's mappings for that tenant. Hyku's defaults match its default metadata profile. - Environment variables switch on a few features; see Environment variables.
To see the value Bulkrax is using, open a Rails console and read it from Bulkrax, for example Bulkrax.parsers or Bulkrax.field_mappings['Bulkrax::CsvParser'].
Importers keep a copy of the field mappings from the moment they are created. A change to the mappings reaches an existing importer only when it is saved again through its edit form.
config.parsers lists the import formats offered in the importer form's Parser list. The defaults are:
[
{ name: "OAI - Dublin Core", class_name: "Bulkrax::OaiDcParser", partial: "oai_fields" },
{ name: "OAI - Qualified Dublin Core", class_name: "Bulkrax::OaiQualifiedDcParser", partial: "oai_fields" },
{ name: "CSV - Comma Separated Values", class_name: "Bulkrax::CsvParser", partial: "csv_fields" },
{ name: "Bagit", class_name: "Bulkrax::BagitParser", partial: "bagit_fields" },
{ name: "XML", class_name: "Bulkrax::XmlParser", partial: "xml_fields" }
]Remove an entry to hide that format, change name to relabel it, or point partial at your own form partial. The exporter form offers the parsers that support export (CSV and BagIt).
Bulkrax.setup do |config|
# Hide the XML parser
config.parsers -= [{ name: "XML", class_name: "Bulkrax::XmlParser", partial: "xml_fields" }]
# Add a custom parser (app/parsers/bulkrax/oai_custom_parser.rb must exist)
config.parsers += [{ name: "OAI - Custom", class_name: "Bulkrax::OaiCustomParser", partial: "oai_fields" }]
endTo write a parser, see Customizing Bulkrax.
Field mappings connect the import data (CSV columns, XML elements, OAI fields) to the fields of your work types. They are set per parser in config.field_mappings, as a hash whose keys are the destination fields:
Bulkrax.setup do |config|
config.field_mappings['Bulkrax::CsvParser'] = {
'bulkrax_identifier' => { from: ['source_identifier'], source_identifier: true },
'title' => { from: ['title'] },
'creator' => { from: ['creator', 'author'], split: /\s*[|]\s*/ },
'parents' => { from: ['parents'], related_parents_field_mapping: true },
'children' => { from: ['children'], related_children_field_mapping: true }
}
endThe mappings must match the fields your work types actually have, whether those come from the models or, with flexible metadata, from the metadata profile. Bulkrax does not read the mappings from either. What happens when they do not match, and how to keep them in step, is in Troubleshooting: Fields missing from imports or exports.
How columns are matched:
- A column matches a mapping when its header is the mapping's key or any name in its
fromlist. - Headers are matched exactly, including case:
Titledoes not matchtitle. - A number joined to the name with an underscore is ignored, so
creator_1andcreator_2both map tocreator. This applies anywhere in the header, so a column nameddate_2020maps todate. - A column whose header is a field's own name imports even with no mapping (see Default field mapping). A column mapped to a field the work type does not have is skipped without an error.
- On export, only mapped fields are written. Unmapped fields are left out of the CSV.
| Option | What it does |
|---|---|
from: |
The column or element names to read, as an array. |
split: |
Split a cell into several values. See Splitting a cell into several values. |
join: |
On export, write all values in one cell, separated by |, instead of numbered columns. |
parsed: |
Run the matcher's parse_<field> method on each value. See Customizing Bulkrax. |
if: |
Keep a value only when it matches: [method, pattern], for example ['match?', 'https?://']. |
excluded: true |
Do not import this field. |
generated: true |
Export the field only when Include Generated Metadata? is checked. See Generated Metadata. |
source_identifier: true |
This mapping holds the record's identifier. See Work Identifier. |
search_field: |
With source_identifier: true: the Solr field searched to find existing records, such as bulkrax_identifier_tesim. Defaults to <field>_sim. |
related_parents_field_mapping: true |
This column lists parents. See Parent-child relationship field mappings. |
related_children_field_mapping: true |
This column lists children. |
object:, nested_type:, nested_attributes:, name:
|
Map columns into a field made of several parts. See Mapping from objects. |
skip_object_for_model_names: |
On export, write this field as plain values (not as an object) for the listed models. |
Option names may be written as symbols or strings (split: or 'split').
A cell is not split unless its mapping says so. Without split:, Smith, Jane; Jones, Ruth is one value. Users can always use numbered columns (creator_1, creator_2) instead.
-
split: /\s*[|]\s*/(a regular expression) orsplit: '\|'(a string, read as a regular expression): split on the pattern. Prefer this form, so the separator is explicit. -
split: true: split on the default pattern/\s*[:;|]\s*/, which includes the colon. That breaks values that contain colons, such as URLs and "Title: subtitle".
The file column is the exception: it splits on |, ; and : even without a mapping, so file names must not contain colons.
In Bulkrax 10.0, setting config.multi_value_element_split_on or config.multi_value_element_join_on has no effect: the defaults (/\s*[:;|]\s*/ and |) are always used. Use a pattern on each mapping instead.
A column with no mapping, whose header is a field's own name, gets this mapping:
{ field => { from: [field], split: false, parsed: <true if a parse_<field> method exists>, if: nil, excluded: false } }Fields with a parse method, and so parsed by default: remote_files, language, subject, types, model, resource_type, format_original. For example, subject values are capitalized.
config.default_field_mapping is the lambda that builds this; you are unlikely to need to change it.
If a work type stores fields made of several parts (for example a creator with a first name, last name and position), map each part with object:. The from names are not numbered, even if the CSV headers are.
Sample CSV:
| creator_first_name_1 | creator_last_name_1 | creator_position_1 | creator_first_name_2 |
|---|---|---|---|
| Aaliyah | Haughton | Queen | Ruth |
config.field_mappings['Bulkrax::CsvParser'] = {
'creator_first_name' => { from: ['creator_first_name'], object: 'creator' },
'creator_last_name' => { from: ['creator_last_name'], object: 'creator' },
'position' => { from: ['creator_position'], object: 'creator', nested_type: 'Array' }
}The record then has:
creator: [
{ creator_first_name: 'Aaliyah', creator_last_name: 'Haughton', position: ['Queen'] },
{ creator_first_name: 'Ruth' }
]-
object:names the field the part belongs to. The mapping key may include the object's name (creator_first_name) or not (first_name). -
nested_type: 'Array'makes that part a list; other parts are single strings. -
nested_attributes: truesends the data as<object>_attributes, for forms that accept nested data only that way. See below. -
name:(orrow_key:) sets the key the value is stored under inside the object, when it must differ from the mapping key. See below.
Available in Bulkrax 9.5.0 and later.
Some form objects, typically those wrapping a Valkyrie resource and exposing nested data through Reform's _attributes virtual property, accept nested data only as <object>_attributes. For those, set nested_attributes: true on every field that shares an object: value:
config.field_mappings['Bulkrax::CsvParser'] = {
'path' => { from: ['redirect_path'], object: 'redirects', nested_attributes: true },
'is_display_url' => { from: ['redirect_is_display_url'], object: 'redirects', nested_attributes: true }
}A row with redirect_path_1=/foo, redirect_is_display_url_1=true, redirect_path_2=/bar produces:
parsed_metadata['redirects_attributes'] = {
'0' => { 'path' => '/foo', 'is_display_url' => 'true', '_destroy' => 'false' },
'1' => { 'path' => '/bar', '_destroy' => 'false' }
}The bare redirects key is not set when the option is on. Export reads the resource's own field either way, so one mapping works in both directions.
Available in Bulkrax 9.5.1 and later.
Each mapping key must be unique, because the mappings are a hash. When two objects each need a part with the same name (for example a title inside both participants and relationships), give each mapping a unique key and set the stored name with name::
config.field_mappings['Bulkrax::CsvParser'] = {
'participant_title' => { from: ['participant_title'], object: 'participants', nested_attributes: true, name: 'title' },
'relationship_title' => { from: ['relationship_title'], object: 'relationships', nested_attributes: true, name: 'title' }
}A row with participant_title_1=Dr, relationship_title_1=Companion study produces:
parsed_metadata['participants_attributes'] = { '0' => { 'title' => 'Dr', '_destroy' => 'false' } }
parsed_metadata['relationships_attributes'] = { '0' => { 'title' => 'Companion study', '_destroy' => 'false' } }name: also resolves a clash with a top-level mapping key, for example a compound license part when a plain license mapping exists.
Each imported record stores the identifier from its row (its source identifier) in one of its fields: the work identifier field. On a later import, Bulkrax looks up that field to decide whether a row updates an existing record or creates a new one.
-
The default is the
sourcefield, from Hyrax's basic metadata. This applies when no mapping hassource_identifier: true. It means the identifier is stored in a descriptive field that users also see and edit, and it is seldom used outside test applications. -
Recommended: a dedicated field that exists on every work type, file set and collection, as Hyku does with
bulkrax_identifier:config.field_mappings['Bulkrax::CsvParser'] = { 'bulkrax_identifier' => { from: ['source_identifier'], source_identifier: true, search_field: 'bulkrax_identifier_tesim' } }
The key (
bulkrax_identifier) is the field the identifier is stored in. Add the field to every model and index it, and setsearch_fieldto the Solr field it is indexed under.
Only one mapping per parser may have source_identifier: true.
The source identifier is the column (or element) in the import data that holds each row's identifier. It is source_identifier unless the mapping with source_identifier: true names another column in from. When from lists several names, only the first is read.
# Read identifiers from a column called original_identifier
config.field_mappings['Bulkrax::CsvParser'] = {
'bulkrax_identifier' => { from: ['original_identifier'], source_identifier: true }
}The value must be unique across the repository, must not contain the separator used for splitting (if any), and should stay the same each time a record is imported.
A row with a blank source identifier is skipped. To have Bulkrax create identifiers instead, set a lambda:
config.fill_in_blank_source_identifiers = ->(parser, index) { "#{parser.importerexporter.id}-#{index}" }- Bulkrax calls it with the parser and the row's position.
- Once it is set,
source_identifieris no longer a required column. - The result must be the same every time the same row is imported, or re-imports create duplicates. Do not use random values such as
SecureRandom.uuid.
Two mappings name the columns that hold relationships. Both columns accept source identifiers and repository ids.
config.field_mappings['Bulkrax::CsvParser'] = {
'parents' => { from: ['parents'], related_parents_field_mapping: true },
'children' => { from: ['children'], related_children_field_mapping: true }
}- Without these flags, Bulkrax uses columns named
parentsandchildren. - Every name in
from, and its numbered forms (parents_1,parents_2), is read. - A cell holds one identifier unless the mapping has
split:. Addsplit: /\s*[|]\s*/to accept several identifiers in one cell. -
join:on theparentsmapping also controls howchildrenis written on export.
In this example imported_work_2 becomes a child of imported_work_1:
| source_identifier | title | parents |
|---|---|---|
| imported_work_1 | Work One | |
| imported_work_2 | Work Two | imported_work_1 |
The same relationship can be written from the other side with a children column on imported_work_1.
Fields the system sets rather than users, such as dates of creation and modification, are marked generated: true:
'date_uploaded' => { from: ['date_uploaded'], generated: true }An export includes them only when Include Generated Metadata? is checked on the exporter form. They cannot be imported again.
The work type used for rows with no model value:
config.default_work_type = 'Image'Give the class name as a string; the work type must exist. A row whose model names a work type that does not exist also uses the default, without an error.
The fields every row must have, in addition to the source identifier. Default ['title'].
config.required_elements = ['title', 'creator']Each required element must be either mapped or a column of that name in the CSV; otherwise the import fails with "Missing mapping for at least one required element". Work types can require more fields of their own; those are checked when the record is saved.
Fields that imports never write, because the repository manages them: create_date, modified_date, date_modified, date_uploaded, depositor, arkivo_checksum, has_model, head, label, import_url, on_behalf_of, proxy_depositor, owner, state, tail, original_url, relative_path.
config.reserved_properties += ['person_identifier']Fields whose values are checked against the repository's authority files when a row is imported. Default rights_statement and license.
config.qa_controlled_properties += ['resource_type']A field added here needs a matching Hyrax authority service (Hyrax::ResourceTypesService for resource_type) and a config/authorities file. How values are checked is in Controlled Fields.
Bulkrax creates and finds records through an object factory.
-
config.object_factory:Bulkrax::ValkyrieObjectFactoryfor Valkyrie repositories, including Hyku 6 and later;Bulkrax::ObjectFactoryfor ActiveFedora. The generated initializer setsBulkrax::ObjectFactory, so Valkyrie applications must change it. -
config.curation_concerns: the work types Bulkrax offers, for example in exports. Defaults to Hyrax's list. -
config.file_model_classandconfig.collection_model_class: the file set and collection classes. Default::FileSetandCollection(current Hyku:Hyrax::FileSetandCollectionResource). Themodelcolumn accepts either spelling of these names, such asFileSetorHyrax::FileSet. -
config.factory_class_name_coercer: how amodelvalue is turned into a class.Bulkrax::FactoryClassFinder::ValkyrieMigrationCoercermaps old ActiveFedora names to their Valkyrie counterparts (GenericWorktoGenericWorkResource). -
transformation_removes_blank_hash_values(on the factory class): when true, blank values are removed from the attributes sent to the repository.
How the factories behave differently is in Repository modes. To write your own factory, see Using Bulkrax without Hyrax.
-
config.ingest_queue_name: the queue for import, delete and relationship jobs. Defaults to Hyrax's ingest queue (:defaultin Hyrax 5), or:importwithout Hyrax. Exports run on:export. Workers must listen to these queues and to:default. -
config.use_locking: lock a work while rows add to it. Defaults to true when theREDIS_HOSTenvironment variable is set. -
config.relationship_job_class: the job that links parents and children. Default"Bulkrax::CreateRelationshipsJob".
-
config.guided_import_enabled: shows Guided Import on the importers page. Defaults to theBULKRAX_GUIDED_IMPORTERenvironment variable. Hyku sets it per tenant from the Include guided import feature (Dashboard > Configuration > Features), so in Hyku use that switch instead. -
config.csv_row_validators: the checks Guided Import runs on each row. Add your own withconfig.register_csv_row_validator(MyCheck), whereMyCheckresponds tocall(record, row_index, context)and adds tocontext[:errors]orcontext[:warnings]. Replacing the whole list drops any checks added to Bulkrax later; preferregister_csv_row_validator.
-
config.import_path: where uploaded imports are written before they run. Defaulttmp/imports. -
config.export_path: where exports are written before download. Defaulttmp/exports. -
config.removed_image_path(ActiveFedora only): when Update and Replace Files removes a work's old files, each one is kept as a new version whose content is this image. The default points to a file inside the gem'sspecfolder, which installed gems do not include, so ActiveFedora applications should set it to an image in the application (the install generator copies one toapp/assets/images/bulkrax/removed.png). In Valkyrie repositories the old file sets are deleted and new ones created, and this setting is not used. -
config.server_name: sent with OAI requests. Defaultbulkrax@example.com.
In a multi-tenant Hyku, import and export paths get a subfolder per tenant.
| Variable | Effect |
|---|---|
BULKRAX_GUIDED_IMPORTER |
true shows Guided Import. Hyku uses its per-tenant feature switch instead. |
SHOW_CREATE_AND_VALIDATE |
true shows Create and Validate on the advanced importer form. |
REDIS_HOST |
When set, locking is on by default. |
BULKRAX_API_TOKEN |
The token for the JSON API. |
HYKU_MULTITENANT or SETTINGS__MULTITENANCY__ENABLED
|
Adds a tenant subfolder to import and export paths. |
BULKRAX_NO_BAGIT, BULKRAX_NO_RDF
|
Set automatically when the bagit or rdf gem is missing. |
These appear in older guides and initializers but no longer exist; setting them raises an error:
-
config.collection_field_mapping: removed in Bulkrax 3.0. Use aparentscolumn and the relationship mappings. -
config.child_field_mapping: removed in Bulkrax 3.0. Userelated_children_field_mapping.
Using Bulkrax
Importing
Changing imported records
Exporting
Configuring Bulkrax
- Installing and enabling
- Configuring Bulkrax
- Repository modes
- Common gotchas
- Using Bulkrax without Hyrax
Developing with Bulkrax
Upgrading
Getting help