Skip to content

Commit

Permalink
update donor converter for new container model
Browse files Browse the repository at this point in the history
  • Loading branch information
jambun committed Dec 19, 2016
1 parent 7192fcf commit 06402be
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions backend/converters/donation_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def initialize(input_file)
@batch = ASpaceImport::RecordBatch.new
@input_file = input_file
@records = []

@top_container_uris = {}
end


Expand Down Expand Up @@ -188,16 +190,43 @@ def add_file(row)
end


def format_box(box_no, box_type)
return if box_no.nil?
def get_or_create_top_container(type, indicator)
if @top_container_uris[type + indicator]
@top_container_uris[type + indicator]
else
uri = "/repositories/12345/top_containers/import_#{SecureRandom.hex}"

{
:instance_type => 'accession',
:container => {
:type_1 => box_type || 'Box',
:indicator_1 => box_no
tc_hash = {
:uri => uri,
:type => type,
:indicator => indicator
}
}

@records << JSONModel::JSONModel(:top_container).from_hash(tc_hash)
@top_container_uris[type + indicator] = uri

uri
end
end


def format_boxes(box_no, box_type)
return [] if box_no.nil?

# supports this sort of business: 1-2
(from_box, to_box) = box_no.split(/\s*\-\s*/, 2)
to_box ||= from_box

(from_box .. to_box).to_a.map do |indicator|
{
:instance_type => 'accession',
:sub_container => {
:top_container => {
:ref => get_or_create_top_container((box_type || 'Box'), indicator)
}
}
}
end
end


Expand All @@ -221,7 +250,7 @@ def format_record(row)
record_hash = {
:uri => "/repositories/12345/archival_objects/import_#{SecureRandom.hex}",
:component_id => row['File no/ control no'],
:instances => [format_box(row['Box No'], row['Box Type'])].compact,
:instances => format_boxes(row['Box No'], row['Box Type']),
:dates => [format_date(row['Date Range'])].compact,
:resource => {
:ref => @resource_uri
Expand Down

0 comments on commit 06402be

Please sign in to comment.