Skip to content

Commit

Permalink
pass top container and location handlers in with the context in arrea…
Browse files Browse the repository at this point in the history
…rage
  • Loading branch information
jambun committed May 7, 2020
1 parent fd7a047 commit d215621
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions backend/converters/arrearage_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def initialize(input_file)
super
@batch = ASpaceImport::RecordBatch.new
@input_file = input_file
TopContainerHandler.init
LocationHandler.init
end


Expand All @@ -58,6 +56,8 @@ def run
context = {
:collection_handler => CollectionHandler.new,
:parent_handler => ParentHandler.new,
:top_container_handler => TopContainerHandler.new,
:location_handler => LocationHandler.new,
:position => 0,
}

Expand Down Expand Up @@ -142,11 +142,11 @@ def jsonmodel(context)

class LocationHandler

def self.init
def initialize
@locations = {}
end

def self.get_or_create(location_hash)
def get_or_create(location_hash)
loc_key = location_hash

return @locations[loc_key] if @locations.has_key?(loc_key)
Expand All @@ -169,19 +169,19 @@ def self.get_or_create(location_hash)

class TopContainerHandler

def self.init
def initialize
@top_containers = {}
end


def self.key_for(top_container)
def key_for(top_container)
key = "#{top_container[:type]}: #{top_container[:indicator]}"
key += " #{top_container[:barcode]}" if top_container.has_key?(:barcode)
key
end


def self.build(top_container)
def build(top_container)
{
:type => top_container.fetch(:type, 'Box'),
:indicator => top_container.fetch(:indicator, 'Unknown'),
Expand All @@ -190,14 +190,14 @@ def self.build(top_container)
end


def self.uri_or_false(top_container)
def uri_or_false(top_container)
tc = @top_containers.fetch(key_for(build(top_container)), false)
return false unless tc
tc[:uri]
end


def self.get_or_create(top_container)
def get_or_create(top_container)
tc = build(top_container)

unless top_container[:indicator]
Expand Down Expand Up @@ -366,19 +366,19 @@ def load_instances(row)
if row['location_room']
locations << {
'start_date' => Date.today.strftime('%Y-%m-%d'),
'ref' => ::ArrearageConverter::LocationHandler.get_or_create(:room => row['location_room'],
:row => row['location_row'],
:unit => row['location_unit'],
:shelf => row['location_shelf']),
'ref' => @context.fetch(:location_handler).get_or_create(:room => row['location_room'],
:row => row['location_row'],
:unit => row['location_unit'],
:shelf => row['location_shelf']),
'status' => 'current'
}
else

if row['indicator_1']
# no location info, but we have an indicator
# so let's see if we've seen this container before ...
unless (tc_uri = ::ArrearageConverter::TopContainerHandler.uri_or_false(:indicator => row['indicator_1'],
:type => row['type_1']))
unless (tc_uri = @context.fetch(:top_container_handler).uri_or_false(:indicator => row['indicator_1'],
:type => row['type_1']))
# no location info and we haven't seen this indicator before, so blow up ...
raise "Row (#{row['title']}) has no location for container indicator: #{row['indicator_1']}. " +
"Please fix this and rerun. Aborting import ..."
Expand All @@ -392,9 +392,9 @@ def load_instances(row)
end

top_container = tc_uri ||
::ArrearageConverter::TopContainerHandler.get_or_create(:indicator => row['indicator_1'],
:type => row['type_1'],
:container_locations => locations)
@context.fetch(:top_container_handler).get_or_create(:indicator => row['indicator_1'],
:type => row['type_1'],
:container_locations => locations)

sub_container = {
'top_container' => {'ref' => top_container}
Expand Down

0 comments on commit d215621

Please sign in to comment.