Skip to content

Commit

Permalink
Added Consignment and Box Type columns to donor spreadsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
jambun committed May 14, 2016
1 parent d2e4792 commit 4cdc954
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions backend/converters/donation_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def run

values_map = Hash[@headers.zip(values)]

if values_map["Consignment"]
@class_uri = get_or_create_class(values_map)
end

if values_map["Series Title"]
@series_uri = get_or_create_series(values_map)
end
Expand Down Expand Up @@ -98,27 +102,27 @@ def get_output_path
def get_or_create_resource(office_use_row, title_row)
office_use_values = row_values(office_use_row)
title_values = row_values(title_row)
identifier_json = JSON(office_use_values[1,2] + [nil, nil])
identifier_json = JSON(office_use_values[2,3] + [nil, nil])

if (resource = Resource[:identifier => identifier_json])
resource.uri
else
uri = "/repositories/12345/resources/import_#{SecureRandom.hex}"
title = title_values[1]
title = title_values[3]

extent = {
:portion => 'whole',
:extent_type => 'metres',
:container_summary => office_use_values[3],
:container_summary => office_use_values[5],
:number => office_use_values[4],
}

date = format_date(office_use_values[5])
date = format_date(office_use_values[6])

@records << JSONModel::JSONModel(:resource).from_hash({
:uri => uri,
:id_0 => office_use_values[1],
:id_1 => office_use_values[2],
:id_0 => office_use_values[2],
:id_1 => office_use_values[3],
:title => title,
:level => 'collection',
:extents => [extent],
Expand All @@ -131,6 +135,23 @@ def get_or_create_resource(office_use_row, title_row)
end


def get_or_create_class(row)
return @class_uri if row['Consignment'].nil?

class_hash = format_record(row).merge({
:title => "Consignment #{row['Consignment']}",
:level => 'class'
})

# consignments don't have these things
[:dates, :instances, :component_id].map{|field| class_hash.delete(field)}

@records << JSONModel::JSONModel(:archival_object).from_hash(class_hash)

class_hash[:uri]
end


def get_or_create_series(row)
return @series_uri if row['Series Title'].nil?

Expand All @@ -145,6 +166,8 @@ def get_or_create_series(row)
[:dates, :instances, :component_id].map{|field| series_hash.delete(field)}
end

series_hash[:parent] = { :ref => @class_uri } if @class_uri

@records << JSONModel::JSONModel(:archival_object).from_hash(series_hash)

series_hash[:uri]
Expand All @@ -157,19 +180,20 @@ def add_file(row)
:level => 'file'
})

file_hash[:parent] = { :ref => @class_uri } if @class_uri
file_hash[:parent] = { :ref => @series_uri } if @series_uri

@records << JSONModel::JSONModel(:archival_object).from_hash(file_hash)
end


def format_box(box_no)
def format_box(box_no, box_type)
return if box_no.nil?

{
:instance_type => 'accession',
:container => {
:type_1 => 'box',
:type_1 => box_type || 'Box',
:indicator_1 => box_no
}
}
Expand All @@ -196,7 +220,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'])].compact,
:instances => [format_box(row['Box No'], row['Box Type'])].compact,
:dates => [format_date(row['Date Range'])].compact,
:resource => {
:ref => @resource_uri
Expand All @@ -217,4 +241,4 @@ def format_record(row)
record_hash
end

end
end
Binary file modified samples/Donor Box List Template.xlsx
Binary file not shown.
Binary file modified samples/donor_scenario_1.xlsx
Binary file not shown.
Binary file modified samples/donor_scenario_2.xlsx
Binary file not shown.
Binary file modified samples/donor_scenario_3.xlsx
Binary file not shown.
Binary file modified samples/donor_scenario_4.xlsx
Binary file not shown.

0 comments on commit 4cdc954

Please sign in to comment.